Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensorflow version issue solved #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"terminal.explorerKind": "both",
"python.analysis.extraPaths": [
"C:/users/aayus/appdata/roaming/python/python311/site-packages"
]
}
Binary file added __pycache__/data.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/pred.cpython-311.pyc
Binary file not shown.
43 changes: 23 additions & 20 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from PIL import Image
import numpy as np
import tensorflow as tf
import pred
import matplotlib.pyplot as plt
from data import class_names
import keras
from tensorflow import keras

all_classes = class_names

Expand Down Expand Up @@ -36,39 +37,41 @@ def predict():
# Load and preprocess the image for prediction
img = Image.open(image_path)
# Preprocess the image (resize, normalize, etc.) as needed for your model
img = load_and_prep_image(image_path)
img = pred.load_and_prep_image(image_path)

# Make a prediction
prediction = pred_and_plot(mon_model, img, all_classes)

prediction = pred.pred_and_plot(mon_model, img, all_classes)
img_array = img.numpy()
plt.imshow(img_array)
plt.show()
return jsonify({'prediction': prediction})


def load_and_prep_image(filename, img_shape=300):
img = tf.io.read_file(filename)
# def load_and_prep_image(filename, img_shape=300):
# img = tf.io.read_file(filename)

img = tf.image.decode_image(img, channels = 3)
# img = tf.image.decode_image(img, channels = 3)

img = tf.image.resize(img, size=[img_shape, img_shape])
# img = tf.image.resize(img, size=[img_shape, img_shape])

img = img/255.
# img = img/255.

return img
# return img

def pred_and_plot(model, img, class_names):
# def pred_and_plot(model, img, class_names):

pred = model.predict(tf.expand_dims(img,axis = 0))
# pred = model.predict(tf.expand_dims(img,axis = 0))

if len(pred[0]) > 1:
pred_class = class_names[pred.argmax()]
else:
pred_class = class_names[int(tf.round(pred)[0][0])]
# if len(pred[0]) > 1:
# pred_class = class_names[pred.argmax()]
# else:
# pred_class = class_names[int(tf.round(pred)[0][0])]

plt.imshow(img)
plt.title(f"Prediction: {pred_class}")
plt.axis(False);
# plt.imshow(img)
# plt.title(f"Prediction: {pred_class}")
# plt.axis(False);

return pred_class
# return pred_class

if __name__ == '__main__':
app.run(debug=True)
Expand Down
4 changes: 2 additions & 2 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@


device = 'cuda' if tf.test.is_gpu_available() else 'cpu'

#C:/Users/aayus/Downloads/DSC-ML-Task-main/DSC-ML-Task-main/

# Path to Kaggle Input
path = "C:/Users/Tumul Ranjan/OneDrive/Documents/monument-prediction/Indian-monuments/images"
path = "Indian-monuments/images"
# Walk through the directory and list number of files
for dirpath, dirnames, filenames in os.walk(path):
print(f"There are {len(dirnames)} directories and {len(filenames)} images in '{dirpath}'.")
Expand Down
9 changes: 5 additions & 4 deletions pred.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import matplotlib.pyplot as plt

def load_and_prep_image(filename, img_shape=300):
img = tf.io.read_file(img)
img = tf.io.read_file(filename)

img = tf.image.decode_image(img, channels = 3)

Expand All @@ -13,9 +13,9 @@ def load_and_prep_image(filename, img_shape=300):

return img

def pred_and_plot(model, filename, class_names):
def pred_and_plot(model, img, class_names):

img = load_and_prep_image(filename)
# img = load_and_prep_image(filename)

pred = model.predict(tf.expand_dims(img,axis = 0))

Expand All @@ -26,4 +26,5 @@ def pred_and_plot(model, filename, class_names):

plt.imshow(img)
plt.title(f"Prediction: {pred_class}")
plt.axis(False);
plt.axis('off')
return pred_class
11 changes: 9 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
protobuf==3.19.0
tensorflow==2.8.0
protobuf
tensorflow==2.14.0
flask
pillow
numpy
matplotlib
keras
pandas
opencv-python
Binary file added uploads/58.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added uploads/62.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added uploads/63.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.