Skip to content

Commit 12111a0

Browse files
committed
Update benchmark to include warmups and more runs
1 parent 9d1c006 commit 12111a0

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

benchmarks/inceptionv3/classify_image_timed.py

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
"""Absolute path to image file.""")
7070
tf.app.flags.DEFINE_integer('num_top_predictions', 5,
7171
"""Display this many predictions.""")
72+
# MODIFICATION BY SAM ABRAHAMS
73+
tf.app.flags.DEFINE_integer('warmup_runs', 10,
74+
"Number of times to run Session before starting test")
75+
tf.app.flags.DEFINE_integer('num_runs', 25,
76+
"Number of sample runs to collect benchmark statistics")
77+
# END OF MODIFICATION
7278

7379
# pylint: disable=line-too-long
7480
DATA_URL = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'
@@ -159,21 +165,14 @@ def run_inference_on_image(image):
159165
Returns:
160166
Nothing
161167
"""
162-
163-
# MODIFICATION BY SAM ABRAHAMS
164-
start_time = time.time()
165-
# END OF MODIFICATION
166-
167168
if not tf.gfile.Exists(image):
168169
tf.logging.fatal('File does not exist %s', image)
169170
image_data = tf.gfile.FastGFile(image, 'rb').read()
170171

171172
# Creates graph from saved GraphDef.
173+
start_time = time.time()
172174
create_graph()
173-
174-
# MODIFICATION BY SAM ABRAHAMS
175-
mid_time = time.time()
176-
# END OF MODIFICATION
175+
graph_time = time.time() - start_time
177176

178177
with tf.Session() as sess:
179178
# Some useful tensors:
@@ -185,27 +184,21 @@ def run_inference_on_image(image):
185184
# encoding of the image.
186185
# Runs the softmax tensor by feeding the image_data as input to the graph.
187186
softmax_tensor = sess.graph.get_tensor_by_name('softmax:0')
188-
predictions = sess.run(softmax_tensor,
189-
{'DecodeJpeg/contents:0': image_data})
190-
predictions = np.squeeze(predictions)
191-
192-
# Creates node ID --> English string lookup.
193-
node_lookup = NodeLookup()
194-
195-
top_k = predictions.argsort()[-FLAGS.num_top_predictions:][::-1]
196-
197-
for node_id in top_k:
198-
human_string = node_lookup.id_to_string(node_id)
199-
score = predictions[node_id]
200-
print('%s (score = %.5f)' % (human_string, score))
201-
202-
# MODIFICATION BY SAM ABRAHAMS
203-
end_time = time.time()
204-
graph_time = mid_time - start_time
205-
eval_time = end_time - mid_time
206-
print('Build graph time: %f' % graph_time)
207-
print('Eval time: %f' % eval_time)
208-
# END OF MODIFICATION
187+
# MODIFICATION BY SAM ABRAHAMS
188+
for i in range(FLAGS.warmup_runs):
189+
predictions = sess.run(softmax_tensor,
190+
{'DecodeJpeg/contents:0': image_data})
191+
runs = []
192+
for i in range(FLAGS.num_runs):
193+
start_time = time.time()
194+
predictions = sess.run(softmax_tensor,
195+
{'DecodeJpeg/contents:0': image_data})
196+
runs.append(time.time() - start_time)
197+
for i, run in enumerate(runs):
198+
print('Run %03d:\t%0.4f seconds' % (i, run))
199+
print('Average run: %0.4f' % float(sum(runs) / len(runs)))
200+
print('Build graph time: %0.4f' % graph_time)
201+
# END OF MODIFICATION
209202

210203
def maybe_download_and_extract():
211204
"""Download and extract model tar file."""

0 commit comments

Comments
 (0)