Created
June 25, 2019 22:43
-
-
Save obeshor/ee6bdc4f63494c6244cff55fc470b84c to your computer and use it in GitHub Desktop.
Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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