Skip to content

Instantly share code, notes, and snippets.

@obeshor
Created June 25, 2019 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obeshor/ee6bdc4f63494c6244cff55fc470b84c to your computer and use it in GitHub Desktop.
Save obeshor/ee6bdc4f63494c6244cff55fc470b84c to your computer and use it in GitHub Desktop.
Testing
# Import OpenCV
import cv2
# Utility
import itertools
import random
from collections import Counter
from glob import iglob
def load_image(filename):
img = cv2.imread(os.path.join(data_dir, validation_dir, filename))
img = cv2.resize(img, (IMAGE_SIZE[0], IMAGE_SIZE[1]) )
img = img /255
return img
def predict(image):
probabilities = model.predict(np.asarray([img]))[0]
class_idx = np.argmax(probabilities)
return {classes[class_idx]: probabilities[class_idx]}
for idx, filename in enumerate(random.sample(validation_generator.filenames, 5)):
print("SOURCE: class: %s, file: %s" % (os.path.split(filename)[0], filename))
img = load_image(filename)
prediction = predict(img)
print("PREDICTED: class: %s, confidence: %f" % (list(prediction.keys())[0], list(prediction.values())[0]))
plt.imshow(img)
plt.figure(idx)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment