-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcnn_predict.py
43 lines (33 loc) · 1003 Bytes
/
cnn_predict.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
import tensorflow as tf
import cv2
import numpy as np
from tensorflow.keras.models import load_model
model=load_model('CNN_model.h5')
from tkinter import filedialog
from tensorflow.keras.preprocessing import image
def browse_file():
global select_dir
browse = filedialog.askopenfile()
try:
select_dir = (browse.name)
return (select_dir)
except:
return
def file_location():
return select_dir
run=True
if run is True:
while True:
X_pred = []
browse_file()
#one_root_img=(os.path.join(train_dir,train_dir_class[0],train_one_data[1]))
img_location=file_location()
img=cv2.imread(img_location,cv2.IMREAD_GRAYSCALE)
new_array=cv2.resize(img,(130,130))
x=new_array.reshape(-1,130,130,1)
classes=model.predict(x)
print(classes[0])
if classes[0][0] ==1:
print("1root")
else:
print("2 or more root")