Hi,
Currently I am using adr/6 model for object detection on images. while using the same image within my application and invoking model using api call with “prediction = self.client.infer(img, model_id=self.model_id)” response show 0 detections. whereas If I use same image in browser it shows 3 detections. I tried debugging but visualising if image input if it’s causing any issue but no problems there. Why are results inconsistent I am unable to debug. Plz help I need to solve this as soon as possible.
current inference code:
# Create debug directory if it doesn’t exist
debug_dir = “Backend/debug_visualizations/roboflow_input”
os.makedirs(debug_dir, exist_ok=True)
# Convert bytes to base64 string
# base64_image_string = self._bytes_to_base64_string(image_bytes)
nparr = np.frombuffer(image_bytes, np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
if img is None:
raise ValueError("Failed to decode image")
# Perform inference
# Save the input image with timestamp for debugging
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
debug_path = os.path.join(debug_dir, f"roboflow_input_{timestamp}.png")
cv2.imwrite(debug_path, img)
logger.info(f"Saved debug input image to: {debug_path}")
prediction = self.client.infer(img, model_id=self.model_id)
boxes_xyxy = []
classes = []
scores = [x]
# Ensure prediction is a dictionary and has 'predictions' key
if not isinstance(prediction, dict):
logger.error(f"Unexpected prediction format: {type(prediction)}. Expected dict.")
prediction = {} # Avoid further errors
predictions_data = prediction.get('predictions', [])
num_detections = len(predictions_data)
logger.info(f"Prediction received: {prediction}")
logger.info(f"Received {num_detections} predictions.")
logger.info(f"Predictions data: {predictions_data}")
and logs output from this code is
INFO - Prediction received: {‘inference_id’: ‘12898b8a-d898-4d21-89f3-5f6e6aa76b2e’, ‘time’: 0.037813304999872344, ‘image’: {‘width’: 800, ‘height’: 1095}, ‘predictions’: }
INFO - Received 0 predictions.
INFO - Predictions data:
INFO - Number of detections: 0
INFO - Yolo/Roboflow Inference: boxes → , classes → , scores → , num_detections → 0
- Object Detection
- Linux OS(ubuntu) and Edge, firefox
- How to Use the adr Object Detection API