Ошибка сегментации потока - PullRequest
0 голосов
/ 20 февраля 2019

Мне нужно получить прогнозирование рекурсивно. Программа прогнозирует первый раз, но не удалось в следующем цикле в 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()
...