Keras
Piyush242003 commited on
Commit
b9f3d6d
·
verified ·
1 Parent(s): 2530a02

Upload 69 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +3 -35
  2. .vscode/launch.json +15 -0
  3. App/DBI_Model.py +2 -0
  4. App/__pycache__/DBI_Model.cpython-312.pyc +0 -0
  5. App/__pycache__/dog_vision.cpython-312.pyc +0 -0
  6. App/__pycache__/views.cpython-312.pyc +0 -0
  7. App/dog_vision.py +78 -0
  8. App/views.py +64 -0
  9. Aptfile +4 -0
  10. Model/final-keras-model-xception.keras +3 -0
  11. Model/labels.csv +0 -0
  12. Procfile +1 -0
  13. Static/Images/002.PNG +0 -0
  14. Static/Images/Dog1.jpg +0 -0
  15. Static/Images/begle.jpeg +0 -0
  16. Static/Images/content/modules.svg +1 -0
  17. Static/Images/content/training_flow.svg +1 -0
  18. Static/Images/cute-puppies-pomeranian-mixed-breed-pekingese-dog-royalty-free-image-1695914235.avif +0 -0
  19. Static/Images/dog2.jpg +3 -0
  20. Static/Images/download (1).jpeg +0 -0
  21. Static/Images/download (2).jpeg +0 -0
  22. Static/Images/download (3).jpeg +0 -0
  23. Static/Images/download (5).jpeg +0 -0
  24. Static/Images/download (6).jpeg +0 -0
  25. Static/Images/download (7).jpeg +0 -0
  26. Static/Images/icon.png +0 -0
  27. Static/Images/images (1).jpeg +0 -0
  28. Static/Images/images (10).jpeg +0 -0
  29. Static/Images/images (2).jpeg +0 -0
  30. Static/Images/images (3).jpeg +0 -0
  31. Static/Images/images (4).jpeg +0 -0
  32. Static/Images/images (5).jpeg +0 -0
  33. Static/Images/images (6).jpeg +0 -0
  34. Static/Images/images (8).jpeg +0 -0
  35. Static/Images/images (9).jpeg +0 -0
  36. Static/Images/images.jpeg +0 -0
  37. Static/Images/lebra.jpeg +0 -0
  38. Static/Images/lhasa apso.jpeg +0 -0
  39. Static/Images/logo.svg +1 -0
  40. Static/Images/samyed.jpeg +0 -0
  41. Static/Images/scottish dearhound.jpeg +0 -0
  42. Static/Images/tibtian.jpeg +0 -0
  43. Static/Predict/image.jpg +0 -0
  44. Static/Upload/002.PNG +0 -0
  45. Static/Upload/Dog1.jpg +0 -0
  46. Static/Upload/begle.jpeg +0 -0
  47. Static/Upload/dog2.jpg +3 -0
  48. Static/Upload/download (2).jpeg +0 -0
  49. Static/Upload/download (3).jpeg +0 -0
  50. Static/Upload/download (5).jpeg +0 -0
.gitattributes CHANGED
@@ -1,35 +1,3 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.keras filter=lfs diff=lfs merge=lfs -text
2
+ Static/Images/dog2.jpg filter=lfs diff=lfs merge=lfs -text
3
+ Static/Upload/dog2.jpg filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.vscode/launch.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "chrome",
9
+ "request": "launch",
10
+ "name": "Launch Chrome against localhost",
11
+ "url": "http://localhost:8080",
12
+ "webRoot": "${workspaceFolder}"
13
+ }
14
+ ]
15
+ }
App/DBI_Model.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import cv2
2
+ from dog_vision import identificationPipeline
App/__pycache__/DBI_Model.cpython-312.pyc ADDED
Binary file (229 Bytes). View file
 
App/__pycache__/dog_vision.cpython-312.pyc ADDED
Binary file (3.32 kB). View file
 
App/__pycache__/views.cpython-312.pyc ADDED
Binary file (3.26 kB). View file
 
App/dog_vision.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import tensorflow_hub as hub
3
+ import numpy as np
4
+ import os
5
+ import pandas as pd
6
+ import cv2
7
+ import keras
8
+ from matplotlib.pyplot import imread
9
+ from flask import jsonify
10
+
11
+ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
12
+
13
+ # Create a function to load a trained model
14
+ def load_model(model_path):
15
+ '''
16
+ Loads a saved model from a specified path.
17
+ '''
18
+ print(f'Loading saved model from: {model_path}')
19
+ model = tf.keras.models.load_model(model_path,
20
+ custom_objects={'KerasLayer': hub.KerasLayer})
21
+ return model
22
+
23
+ loaded_full_model = load_model(r'C:\Users\piyus\OneDrive\Desktop\FlaskApp\Model\final-keras-model-xception.keras')
24
+
25
+
26
+
27
+ labels_csv = pd.read_csv(r'C:\Users\piyus\OneDrive\Desktop\FlaskApp\Model\labels.csv')
28
+ labels = labels_csv['breed'].to_numpy()
29
+
30
+ # Find the unique label values
31
+ unique_breeds = np.unique(labels)
32
+ IMG_SIZE = 150
33
+
34
+ # Turn probabilities into their respective label (easier to understand)
35
+ def get_pred_label(prediction_probabilities):
36
+ '''
37
+ Turn an array of prediction probabilities into a label.
38
+ '''
39
+ return unique_breeds[np.argmax(prediction_probabilities)]
40
+
41
+
42
+ # Identification Pipeline
43
+ # Identification Pipeline
44
+ def identificationPipeline(img_path):
45
+ '''
46
+ Takes an image path, preprocesses it, and returns the predicted breed.
47
+ '''
48
+ print(f"Received img_path: {img_path}")
49
+
50
+ # Validate Image Path
51
+ if not os.path.exists(img_path):
52
+ raise FileNotFoundError(f"Image not found at: {img_path}")
53
+
54
+ # Read & Preprocess Image
55
+ try:
56
+ image = tf.io.read_file(img_path)
57
+ image = tf.image.decode_jpeg(image, channels=3)
58
+ image = tf.image.convert_image_dtype(image, tf.float32)
59
+ image = tf.image.resize(image, size=[IMG_SIZE, IMG_SIZE])
60
+ image_reshaped = tf.reshape(image, (1, IMG_SIZE, IMG_SIZE, 3)) # Add batch dimension
61
+
62
+ # Predict
63
+ results = loaded_full_model.predict(image_reshaped)
64
+ confidence = np.max(results)
65
+ pred_label = get_pred_label(results)
66
+
67
+ if confidence < 0.1:
68
+ return "Unknown Object (Not a Dog)"
69
+
70
+ print(f"Predicted Label: {pred_label}")
71
+
72
+ return pred_label
73
+
74
+ except Exception as e:
75
+ return f"Error: {str(e)}"
76
+
77
+
78
+
App/views.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask,render_template, request, jsonify, redirect, url_for
2
+ import os
3
+ import cv2
4
+ from App.dog_vision import identificationPipeline
5
+ import numpy as np
6
+
7
+ app = Flask(__name__)
8
+ UPLOAD_FOLDER ='Static/Upload'
9
+ PREDICT_FOLDER = './Static/Predict'
10
+ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
11
+
12
+ @app.route('/', methods=['GET', 'POST'])
13
+ def index():
14
+ if request.method == 'POST':
15
+ file = request.files.get('image_name')
16
+
17
+ # ✅ Check if file is provided
18
+ if not file or file.filename == '':
19
+ return jsonify({"error": "No file was uploaded"}), 400
20
+
21
+ # ✅ Save Image
22
+ path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
23
+ file.save(path)
24
+
25
+ print(f"Received path in views.py: {path}, Type: {type(path)}")
26
+
27
+ # ✅ Get Prediction (Expecting a label string)
28
+ output = identificationPipeline(path)
29
+
30
+ # ✅ Ensure the output is a valid string (Label name)
31
+ if isinstance(output, np.ndarray):
32
+ output = output.tolist() # Convert NumPy array to Python list
33
+ elif hasattr(output, 'numpy'):
34
+ output = output.numpy().tolist() # Convert TensorFlow tensor to list
35
+ elif isinstance(output, dict):
36
+ return jsonify(output) # If it's a dictionary, return as JSON
37
+ elif not isinstance(output, str):
38
+ return jsonify({"error": "Unexpected output format"}), 500
39
+
40
+ print(f"Output from identificationPipeline: {output}") # Debugging line
41
+
42
+ # ✅ Read and save the image properly
43
+ image = cv2.imread(path)
44
+ if image is None:
45
+ return jsonify({"error": "Uploaded file is not a valid image format or is corrupted"}), 400
46
+
47
+ pred_filename = 'image.jpg'
48
+ pred_path = os.path.join(PREDICT_FOLDER, pred_filename)
49
+ cv2.imwrite(pred_path, image)
50
+
51
+ return redirect(url_for('breedIdentification', filename=file.filename, prediction=output))
52
+
53
+ return render_template('index.html')
54
+
55
+
56
+ @app.route("/breedIdentification/")
57
+ def breedIdentification():
58
+ filename = request.args.get('filename')
59
+ prediction = request.args.get('prediction')
60
+
61
+ if not filename or not prediction:
62
+ return redirect(url_for('index')) # Redirect to home if missing data
63
+
64
+ return render_template('breedIdentification.html', filename=filename, prediction=prediction)
Aptfile ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ libsm6
2
+ libxrender1
3
+ libfontconfig1
4
+ libice6
Model/final-keras-model-xception.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37f321464e18cf48b3be5acf710f46595d9c91ee4cecf00bdb0426bea1210249
3
+ size 253469690
Model/labels.csv ADDED
The diff for this file is too large to render. See raw diff
 
Procfile ADDED
@@ -0,0 +1 @@
 
 
1
+ web: gunicorn main:app
Static/Images/002.PNG ADDED
Static/Images/Dog1.jpg ADDED
Static/Images/begle.jpeg ADDED
Static/Images/content/modules.svg ADDED
Static/Images/content/training_flow.svg ADDED
Static/Images/cute-puppies-pomeranian-mixed-breed-pekingese-dog-royalty-free-image-1695914235.avif ADDED
Static/Images/dog2.jpg ADDED

Git LFS Details

  • SHA256: effda71341c1a084d129f2b8c5c7dc4c46e740336e5d6a8590c7520bc2f7a69c
  • Pointer size: 131 Bytes
  • Size of remote file: 133 kB
Static/Images/download (1).jpeg ADDED
Static/Images/download (2).jpeg ADDED
Static/Images/download (3).jpeg ADDED
Static/Images/download (5).jpeg ADDED
Static/Images/download (6).jpeg ADDED
Static/Images/download (7).jpeg ADDED
Static/Images/icon.png ADDED
Static/Images/images (1).jpeg ADDED
Static/Images/images (10).jpeg ADDED
Static/Images/images (2).jpeg ADDED
Static/Images/images (3).jpeg ADDED
Static/Images/images (4).jpeg ADDED
Static/Images/images (5).jpeg ADDED
Static/Images/images (6).jpeg ADDED
Static/Images/images (8).jpeg ADDED
Static/Images/images (9).jpeg ADDED
Static/Images/images.jpeg ADDED
Static/Images/lebra.jpeg ADDED
Static/Images/lhasa apso.jpeg ADDED
Static/Images/logo.svg ADDED
Static/Images/samyed.jpeg ADDED
Static/Images/scottish dearhound.jpeg ADDED
Static/Images/tibtian.jpeg ADDED
Static/Predict/image.jpg ADDED
Static/Upload/002.PNG ADDED
Static/Upload/Dog1.jpg ADDED
Static/Upload/begle.jpeg ADDED
Static/Upload/dog2.jpg ADDED

Git LFS Details

  • SHA256: effda71341c1a084d129f2b8c5c7dc4c46e740336e5d6a8590c7520bc2f7a69c
  • Pointer size: 131 Bytes
  • Size of remote file: 133 kB
Static/Upload/download (2).jpeg ADDED
Static/Upload/download (3).jpeg ADDED
Static/Upload/download (5).jpeg ADDED