<jupyter_start><jupyter_text>The model, once it's loaded in memory, will have to be an `infer` object, so it can make a prediction output with an input data.<jupyter_code>infer = working_model.signatures['serving_default']<jupyter_output><empty_output><jupyter_text>The model output signature tells us the data structure of the output.<jupyter_code>print(infer.structured_outputs)<jupyter_output>{'custom_class': TensorSpec(shape=(None, 5), dtype=tf.float32, name='custom_class')}<jupyter_text>The output is an array of five floating point values. The output node name is `custom_class`. Next, we will use the following image as our input image to the model for scoring:<jupyter_code>jpg1 = 'raw_images/2440874162_27a7030402_n.jpg' # it is a tulip
img1_np = nv.imread(jpg1, resize=(224,224),normalize=True) #Width and height required. RGB dimension preserved. Numpy.
#img2_np = nv.imread(jpg2, resize=(224,224),normalize=True)
img1_np = nv.expand_dims(img1_np,axis=0)<jupyter_output><empty_output><jupyter_text>A prediction is made for flower image `img1_np`.<jupyter_code>prediction = infer(tf.constant(img1_np))
prediction['custom_class'].numpy()<jupyter_output><empty_output><jupyter_text>Now we will reuse the label map from Chapter 7's exercises:<jupyter_code>val_label_map = {4: 'tulips', 3: 'dandelion', 1: 'sunflowers', 2: 'daisy', 0: 'roses'}
val_label_map
def lookup(np_entry, dictionary):
    class_key = np.argmax(np_entry)
    return dictionary.get(class_key)
lookup(prediction['custom_class'].numpy(), val_label_map)<jupyter_output><empty_output><jupyter_text>Build JSON Payload<jupyter_code>data = json.dumps({ 
    "instances": img1_np.tolist()
})
headers = {"content-type": "application/json"}
# data # uncomment to see what a JSON payload looks like.
response = requests.post('http://localhost:8501/v1/models/flowerclassifier:predict', data=data, headers=headers)
response.json()<jupyter_output><empty_output><jupyter_text>Use `lookup` to decode response from the model:<jupyter_code>lookup(response.json()['predictions'], val_label_map)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12278177458033573, 'fraction_numerical': 0.02685851318944844, 'mean_word_length': 8.27111111111111, 'pattern_counts': {'":': 2, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '194553', 'license': 'MIT', 'n_tokens_mistral': 756, 'n_tokens_neox': 709, 'n_words': 163, 'path': 'Chapter09/Tensorflow_Serving.ipynb', 'repo_name': 'PacktPublishing/Learn-Tensorflow-Enterprise', 'size': '2085'}