Skip to content

Instantly share code, notes, and snippets.

@dipanjanS
Created September 20, 2019 10:29
Show Gist options
  • Select an option

  • Save dipanjanS/167f3c497d27edce87918d9f12a93f13 to your computer and use it in GitHub Desktop.

Select an option

Save dipanjanS/167f3c497d27edce87918d9f12a93f13 to your computer and use it in GitHub Desktop.
# save sample data
np.save('serve_warmup_data.npy', sample_test_data)
# model warmup functions
def warmup_model1_serve(warmup_data):
warmup_data_processed = np.expand_dims(warmup_data / 255., axis=3)
data = json.dumps({"signature_name": "serving_default",
"instances": warmup_data_processed.tolist()})
HEADERS = {'content-type': 'application/json'}
MODEL1_API_URL = 'http://localhost:8501/v1/models/fashion_model_serving/versions/1:predict'
json_response = requests.post(MODEL1_API_URL, data=data, headers=HEADERS)
predictions = json.loads(json_response.text)['predictions']
print('Model 1 warmup complete')
def warmup_model2_serve(warmup_data, img_dims=(32, 32)):
warmup_data_processed = (np.array([resize_image_array(img,
img_size_dims=img_dims)
for img in np.stack([warmup_data]*3,
axis=-1)])) / 255.
data = json.dumps({"signature_name": "serving_default",
"instances": warmup_data_processed.tolist()})
HEADERS = {'content-type': 'application/json'}
MODEL2_API_URL = 'http://localhost:8501/v1/models/fashion_model_serving/versions/2:predict'
json_response = requests.post(MODEL2_API_URL, data=data, headers=HEADERS)
predictions = json.loads(json_response.text)['predictions']
print('Model 2 warmup complete')
# warmup models
warmup_data = np.load('serve_warmup_data.npy')
warmup_model1_serve(warmup_data)
warmup_model2_serve(warmup_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment