我需要递归地获得预测
该程序首次预测,但在5.2的下一个循环期间失败。
我尝试使用tf.reset_default_graph()
,但在5.2下再次被杀死。
我在Google上搜索了相同的内容,但找不到
Note: running the code in rpi model b+ with 32gb
这是我的代码,我不确定自己做错了什么。
import RPi.GPIO as GPIO
import tensorflow as tf, sys
GPIO.setmode(GPIO.BOARD)
mypin = 8
GPIO.setup(mypin, GPIO.OUT, initial = 0)
def init():
try:
_hs = ''
_score = 0
image_path = sys.argv[0]
image_data = tf.gfile.FastGFile("/home/pi/tfmodels/smart_sort/test_images/test.jpg", 'rb').read()
label_lines = [line.rstrip() for line in tf.gfile.GFile("/home/pi/tfmodels/smart_sort/retrained_labels.txt")]
with tf.gfile.FastGFile("/home/pi/tfmodels/smart_sort/retrained_graph.pb", 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')
f.close()
with tf.Session() as sess:
print('5.1')
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
print('5.2')
predictions = sess.run(softmax_tensor, {'DecodeJpeg/contents:0': image_data})
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
print('5.4')
for node_id in top_k:
human_string = label_lines[node_id]
score = predictions[0][node_id]
if human_string == 'goodgear':
_hs = human_string
_score = score
print('%s (score = %.5f)' % (human_string, score))
sess.close()
if _hs == 'goodgear' and (_score * 100 > 75):
GPIO.output(mypin,GPIO.HIGH)
print('done:if')
init()
else:
GPIO.output(mypin, GPIO.LOW)
print('done:else')
init()
except KeyboardInterrupt:
GPIO.cleanup()
print("Exiting...")
init()