-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpredict one image.py
More file actions
67 lines (53 loc) · 2.14 KB
/
predict one image.py
File metadata and controls
67 lines (53 loc) · 2.14 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import numpy as np
from keras.preprocessing import image
# 0. 사용할 패키지 불러오기
import numpy as np
from numpy import argmax
#from skimage import transform
import matplotlib.pyplot as plt
from keras.models import load_model
from keras.preprocessing import image
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
import tensorflow as tf
import matplotlib.pyplot as plt
import os
import time
import sqlite3
from sqlite3.dbapi2 import Date
import datetime
class_names = ['correctPosition','father_Legs','leftLean_posture','mother_leftLegs','mother_rightLegs','nobody','rightLean_posture','twist_leftLegs','twist_rightLegs']
model = tf.keras.models.load_model('./model/182-0.5622.hdf5')
file = '//raspberrypi/pi/realTimeImage/realTime_image.png'
while True:
if os.path.isfile(file):
time.sleep(3)
print("들어감....................")
test_image = image.load_img('//raspberrypi/pi/realTimeImage/realTime_image.png', target_size = (224,224))
test_image = image.img_to_array(test_image)
test_image = test_image / 255
test_image = np.expand_dims(test_image, axis=0)
predictions = model.predict(test_image)
print(predictions[0])
idx = np.argmax(predictions[0])
print(class_names[idx])
print(int(idx))
print(type(int(idx)))
os.remove('//raspberrypi/pi/realTimeImage/realTime_image.png')
print("제거 완료")
now = datetime.datetime.now()
conn = sqlite3.connect("C:\\Users\\ESE\\anaconda3\\envs\\buster\\flask-live-charts\\DB2.db")
cur = conn.cursor() # 커서 열기
idx=int(idx)
if idx == 0: v=3
if idx == 1: v=4
if idx == 2: v=6
if idx == 3: v=7
if idx == 4: v=0
if idx == 6: v=1
if idx == 7: v=5
if idx == 8: v=2
if idx == 5: v=8
cur.execute("INSERT INTO pose (posture,datetime) VALUES(?,?)",(v,time.time()*1000))
conn.commit()
conn.close()
# print (decode_predictions (predictions, top = 8) [0])