Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import cv2
- import random
- import tensorflow as tf
- import numpy as np
- images = []
- for path, subdirs, files in os.walk("C:\\Users\\Krakkus\\Desktop\\flower_images"):
- for name in files:
- fn = os.path.join(path, name)
- images.append(fn)
- fn = random.choice(images)
- print(fn)
- org_img = cv2.imread(fn)
- tf_image = cv2.resize(org_img, (224, 224))
- tf_image = cv2.cvtColor(tf_image, cv2.COLOR_BGR2RGB)
- tf_image = np.expand_dims(tf_image, axis=0)
- model = tf.keras.models.load_model('my_model_224.keras')
- prediction = model.predict([tf_image])
- print(prediction[0])
- predicted_class = np.argmax(prediction[0])
- print(predicted_class)
- cv2.imshow('Image classification', org_img)
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement