tensorflow - Slow prediction in Google InceptionV-3 using Transfer learning -
i using google's inceptionv-3 model , tensorflow gender recognition using transfer learning ( here's link of tutorial) on data-set having 135 face images of female , 335 face images of male. after training shows 95% accuracy , tested on few images it's working fine it's taking around 3 seconds classification result.
i trying in real time (live video feed)
below code modified bit, loaded model first took 1 seconds, make in infinite loop pass image , prediction result.
import os, sys import tensorflow tf os.environ['tf_cpp_min_log_level'] = '2' import time # unpersists graph file tf.gfile.fastgfile("retrained_graph.pb", 'rb') f: graph_def = tf.graphdef() graph_def.parsefromstring(f.read()) tf.import_graph_def(graph_def, name='') # change see fit image_path = sys.argv[1] # read in image_data image_data = tf.gfile.fastgfile(image_path, 'rb').read() # loads label file, strips off carriage return label_lines = [line.rstrip() line in tf.gfile.gfile("retrained_labels.txt")] while true: start_time = time.time() tf.session() sess: # feed image_data input graph , first prediction softmax_tensor = sess.graph.get_tensor_by_name('final_result:0') predictions = sess.run(softmax_tensor, {'decodejpeg/contents:0': image_data}) print("--- %s seconds ---" % (time.time() - start_time)) # sort show labels of first prediction in order of confidence """top_k = predictions[0].argsort()[-len(predictions[0]):][::-1] node_id in top_k: human_string = label_lines[node_id] score = predictions[0][node_id]"""
here's output:
--- 2.21238899231 seconds --- --- 2.1374540329 seconds --- --- 2.08863019943 seconds --- --- 2.08074688911 seconds --- --- 2.07966399193 seconds ---
is there way can reduce time here, sorry code formatting. not sure if have asked right question, new ml.
thanks help!
sys config: amd-a4, 2.5ghz, 8gb ram
first of should not recreate session scratch in loop. create 1 session object, , during loop call sess.run(...) on , on again. also, should call "get_tensor_by_name" once (outside loop). apart nothing can done code-wise. put execution on gpu make things faster though.
Comments
Post a Comment