Skip to content

Instantly share code, notes, and snippets.

@wronk
Created February 13, 2019 19:38
Show Gist options
  • Save wronk/2774fdc3da77b442bf78e0358156a51e to your computer and use it in GitHub Desktop.
Save wronk/2774fdc3da77b442bf78e0358156a51e to your computer and use it in GitHub Desktop.
TF Serving blog post: sending payloads for inference
import json
import base64
import requests
# Modify the name of your model (`hv_grid` here) to match what you used in Section 2
server_endpoint = 'http://localhost:8501/v1/models/hv_grid:predict'
img_fpaths = ['path/to/my_image_1.png', 'path/to/my_image_2.png']
# Load and Base64 encode images
data_samples = []
for img_fpath in img_fpaths:
with open(img_fpath, 'rb') as image_file:
b64_image = base64.b64encode(image_file.read())
data_samples.append({'image_bytes': {'b64': b64_image.decode('utf-8')}})
# Create payload request
payload = json.dumps({"instances": data_samples})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment