Skip to content

Instantly share code, notes, and snippets.

@lukmanr
Created October 17, 2018 19:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukmanr/56b4917b79e564eb8c8006fc6b13ebae to your computer and use it in GitHub Desktop.
Save lukmanr/56b4917b79e564eb8c8006fc6b13ebae to your computer and use it in GitHub Desktop.
TF Model Optimization 5
def inference_tfserving(eval_data, batch=BATCH_SIZE,
repeat=1000, signature='predict'):
url = 'http://localhost:8501/v1/models/mnist_classifier:predict'
instances = [[float(i) for i in list(eval_data[img])] for img in range(batch)]
request_data = {'signature_name': signature,
'instances': instances}
time_start = datetime.utcnow()
for i in range(repeat):
response = requests.post(url, data=json.dumps(request_data))
time_end = datetime.utcnow()
time_elapsed_sec = (time_end - time_start).total_seconds()
print('Total elapsed time: {} seconds'.format(time_elapsed_sec))
print('Time for batch size {} repeated {} times'.format(BATCH_SIZE, repeat))
print('Average latency per batch: {} seconds'.format(time_elapsed_sec/repeat))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment