This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import requests | |
with open('sneaker.jpg', "rb") as imageFile: | |
img_b64enc = base64.b64encode(imageFile.read()) | |
data = {'b64_img': img_b64enc} | |
API_URL = 'http://0.0.0.0:5000/apparel_classifier/api/v1/model2_predict' | |
# sending post request and saving response as response object | |
r = requests.post(url=API_URL, data=data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r = requests.get('http://0.0.0.0:5000/apparel_classifier/api/v1/liveness') | |
r.status_code, r.text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load dependencies | |
import warnings | |
warnings.simplefilter(action='ignore', category=FutureWarning) | |
import numpy as np | |
import requests | |
import base64 | |
import json | |
from io import BytesIO | |
from flask import Flask, request, jsonify | |
from flask_cors import CORS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create serving function | |
INPUT_SHAPE_RN = (32, 32, 3) | |
model2 = create_cnn_architecture_model2(input_shape=INPUT_SHAPE_RN) | |
model2.load_weights('./model_weights/cnn_model2_wt.h5') | |
def predict_apparel_model2_regular(img, img_dims=(32,32), label_map=class_names): | |
sample_img_processed = (np.array([resize_image_array(img, | |
img_size_dims=img_dims) | |
for img in np.stack([[img]]*3, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create serving function | |
def predict_apparel_model2_serving(img, img_dims=(32,32), label_map=class_names): | |
sample_img_processed = (np.array([resize_image_array(img, | |
img_size_dims=img_dims) | |
for img in np.stack([[img]]*3, | |
axis=-1)])) / 255. | |
data = json.dumps({"signature_name": "serving_default", | |
"instances": sample_img_processed.tolist()}) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
sample_test_data = test_images | |
sample_test_labels = test_labels | |
IMG_DIMS = (32, 32) | |
sample_test_data_processed = (np.array([resize_image_array(img, | |
img_size_dims=IMG_DIMS) | |
for img in np.stack([sample_test_data]*3, | |
axis=-1)])) / 255. | |
data = json.dumps({"signature_name": "serving_default", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
warmup_data = np.load('serve_warmup_data.npy') | |
warmup_model2_serve(warmup_data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%bash --bg | |
docker run --runtime=nvidia -p 8501:8501 \ | |
--mount type=bind,source=/home/jupyter/tensorflow_serving/tf_saved_models,target=/home/jupyter/tensorflow_serving/tf_saved_models \ | |
--mount type=bind,source=/home/jupyter/tensorflow_serving/models.conf,target=/home/jupyter/tensorflow_serving/models.conf \ | |
-t tensorflow/serving:latest-gpu --model_config_file=/home/jupyter/tensorflow_serving/models.conf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
sample_test_data = test_images | |
sample_test_labels = test_labels | |
IMG_DIMS = (32, 32) | |
sample_test_data_processed = (np.array([resize_image_array(img, | |
img_size_dims=IMG_DIMS) | |
for img in np.stack([sample_test_data]*3, | |
axis=-1)])) / 255. | |
data = json.dumps({"signature_name": "serving_default", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
sample_test_data = test_images | |
sample_test_labels = test_labels | |
sample_test_data_processed = np.expand_dims(sample_test_data / 255., axis=3) | |
data = json.dumps({"signature_name": "serving_default", | |
"instances": sample_test_data_processed.tolist()}) | |
HEADERS = {'content-type': 'application/json'} | |
MODEL1_API_URL = 'http://localhost:8501/v1/models/fashion_model_serving/versions/1:predict' |