Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

22%
+0 −5
Challenges HOW TO HANDLE THIS ERROR: "Failed to get input map for signature: serving_default" [closed]

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 ...

0 answers  ·  posted 1y ago by mjkatre18‭  ·  closed 1y ago by Mithical‭

#2: Question closed by user avatar Mithical‭ · 2023-08-04T11:52:54Z (over 1 year ago)
#1: Initial revision by user avatar mjkatre18‭ · 2023-08-04T04:48:42Z (over 1 year ago)
HOW TO HANDLE THIS ERROR: "Failed to get input map for signature: serving_default"
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)