-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (33 loc) · 1.08 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import numpy as np
from PIL import Image
model = load_model("/Users/r_prateek/Bird-Species-Classifier/birds.h5")
train_path = "/Users/r_prateek/Bird-Species-Classifier/birdspeciesdata/train"
datagen = ImageDataGenerator(
rescale = 1./255,
)
train_data = datagen.flow_from_directory(
train_path,
target_size = ((224,224)),
)
ci = train_data.class_indices
classes = {v: k for k, v in ci.items()}
path = input('Please enter path of image of bird to classify: \n')
inp = Image.open(path)
img = inp.resize((224,224))
img = np.array(img)/255.0
img = np.reshape(img, [1,224,224,3])
predictions = model.predict(img)
top_values, top_indices = tf.nn.top_k(predictions, k=3)
values = np.array(top_values)
indices = np.array(top_indices)
print('Input Image: \n\n\n')
inp.show()
print('Probabilities: \n')
for i in range(3):
print(classes[indices[0][i]] + " : ", end = "")
print(values[0][i] * 100)
print()