NVIDIA-AI-IOT / tf_trt_models

TensorFlow models accelerated with NVIDIA TensorRT
BSD 3-Clause "New" or "Revised" License
686 stars 241 forks source link

inference time is too long 3s/img at example/classification/classification.ipynb #73

Open biyuehuang opened 4 years ago

biyuehuang commented 4 years ago

Hi, I use example/classification/classification.ipynb by inceptionV3 model on Jetson AGX Xavier. I modify it to print inference time by "import datetime" as following:

......
tf.import_graph_def(trt_graph, name='')
tf_input = tf_sess.graph.get_tensor_by_name(input_names[0] + ':0')
tf_output = tf_sess.graph.get_tensor_by_name(output_names[0] + ':0')

import datetime
start = datetime.datetime.now()

image = Image.open(IMAGE_PATH)
width = int(tf_input.shape.as_list()[1])
height = int(tf_input.shape.as_list()[2])
image = np.array(image.resize((width, height)))

output = tf_sess.run(tf_output, feed_dict={
    tf_input: image[None, ...]
})
scores = output[0]
end=datetime.datetime.now()
print("Took time = ",(end-start))

with open(LABELS_PATH, 'r') as f:
    labels = f.readlines()
top5_idx = scores.argsort()[::-1][0:5]
for i in top5_idx:
    print('(%3f) %s' % (scores[i], labels[i]))
tf_sess.close()

Took time = 0:00:03.205719 Why it took 3 s/img? on Jetson AGX Xavier? it's too far way from benchmark TF-TRT 20ms.