HOW TO HANDLE THIS ERROR: "Failed to get input map for signature: serving_default" [closed]
Closed as off topic by Mithical†on Aug 4, 2023 at 11:52
This question is not within the scope of Code Golf.
This question was closed; new answers can no longer be added. Users with the reopen privilege may vote to reopen this question if it has been improved or closed incorrectly.
import requests import json import numpy as np import base64 import cv2
Replace this with the actual image path you want to test
image_path = 'H_L_.jpg'
Read and preprocess the image
image = cv2.imread(image_path) image = cv2.resize(image, (256, 256)) image = image.astype(np.float32) / 255.0 image = np.expand_dims(image, axis=0)
Convert the NumPy array to bytes before encoding
encoded_image = base64.b64encode(image.tobytes()).decode('utf-8')
Prepare the JSON request with the signature name
data = { "signature_name": "serving_default", "instances": [{"input_1": encoded_image}] # Adjust the input key based on your model's signature }
Replace these labels with your actual labels
labels = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
Send the inference request to TensorFlow Serving
url = 'http://localhost:8501/v1/models/model:predict' # Replace 'model' with the actual model name and version headers = {"content-type": "application/json"} response = requests.post(url, data=json.dumps(data), headers=headers)
Process the response
if response.status_code == 200: predictions = response.json()['predictions'][0] predicted_class_idx = np.argmax(predictions) predicted_label = labels[predicted_class_idx] print("Predicted Label:", predicted_label) print("Class Probabilities:", predictions) else: print("Error: Unable to get predictions. Status code:", response.status_code) print("Response content:", response.content)
1 comment thread