<jupyter_start><jupyter_text>Sabe PB Filehttps://stackoverflow.com/questions/62079274/difference-between-pb-and-h5<jupyter_code>tf.saved_model.save(export_dir=export_path,obj=model)<jupyter_output><empty_output><jupyter_text>Create a OS Enviroment to TF Serving locate model<jupyter_code>os.environ["model_dir"] = os.path.abspath(model_dir)<jupyter_output><empty_output><jupyter_text>Tensorflow Serving API RESTAdd TensorFlow Serving distribution URI as a package source<jupyter_code>!echo "deb [arch=amd64] http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal" | sudo tee /etc/apt/sources.list.d/tensorflow-serving.list && \
curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | sudo apt-key add -<jupyter_output><empty_output><jupyter_text>Install and update TensorFlow ModelServer<jupyter_code>!apt-get update && apt-get install tensorflow-model-server<jupyter_output><empty_output><jupyter_text>Run Sever<jupyter_code>%%bash --bg 
nohup tensorflow_model_server --rest_api_port 8501 --model_name=cifar10 --model_base_path="${model_dir}" > server.log 2?&1
!tail server.log<jupyter_output><empty_output><jupyter_text>Create Post Request<jupyter_code>random_image = np.random.randint(0, len(x_test))<jupyter_output><empty_output><jupyter_text>Create JSON Object<jupyter_code>data = json.dumps({'signature_name':'serving_default',
                   'intances':x_test[random_image].tolist()
                   })
data<jupyter_output><empty_output><jupyter_text>Send Json to TF Serving<jupyter_code>headers = {'content-type':'application/json'}
json_responde = requests.post(url="http://localhost:8501/v1/models/cifar10:predict",data=data,headers=headers)
json_responde
predictions = json.loads(json_response.text)
plt.imshow(x_test[random_image])
class_names[np.argmax(prediction(0))]
specific_json_responde = requests.post(url="http://localhost:8501/v1/models/cifar10/versions/1:predict",data=data,headers=headers)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1296928327645051, 'fraction_numerical': 0.017552413456850317, 'mean_word_length': 8.243243243243244, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '186708', 'license': 'MIT', 'n_tokens_mistral': 754, 'n_tokens_neox': 710, 'n_words': 81, 'path': 'TensorFlow_Serving.ipynb', 'repo_name': 'gabrieloliveira95/Simple_TensorFlow_Serving', 'size': '2051'}