Open curtinmjc opened 2 hours ago
👋 Hello @curtinmjc, thank you for reaching out about the issues with the Inference API example code on the Ultralytics HUB 🚀!
To assist in resolving your problem, could you please provide a Minimum Reproducible Example of both your Python and cURL-based issues? This will greatly help us diagnose the problems:
Python Example: Ensure the data and headers are correctly formatted and that the file paths and URLs are accessible. Any additional logs or screenshots would be helpful in understanding why the JSON outputs remain constant.
cURL Example: There may be differences causing the "Internal Server Error." Please verify that all fields and headers match the API's expected format. Double-check that the file path is properly formatted in your cURL command (e.g., -F "file=@/path/to/image.jpg"
).
Please check out these helpful resources:
An Ultralytics engineer will review your issue and assist further soon. Thanks for your patience! 😊
Search before asking
HUB Component
Inference
Bug
3 issues listed below: Below information is based on v8n Classify model created 2024.09.27 using a custom dataset uploaded 2024.09.26
import json import requests
Run inference on an image
url = "https://predict.ultralytics.com" headers = {"x-api-key": "d3fc123d26aaf85f89ab6064363146ec52d5a0b619"} data = {"model": "https://hub.ultralytics.com/models/uBRAwxJRTTWrihq4Mxw3", "imgsz": 640, "conf": 0.25, "iou": 0.45} with open("/Users/curtinmjc/AI/model_analysis/created_jpg/IMG_3220copy.jpg", "rb") as f: response = requests.post(url, headers=headers, data=data, files={"file": f})
Check for successful response
response.raise_for_status()
Print inference results
print(json.dumps(response.json(), indent=2))
JSON response to Python example code -- "results" class, confidence, name always same for each different file sent:
{ "images": [ { "results": [ { "class": 8, "confidence": 0.45183, "name": "CM_Cones_Sundaes_Ice_Cream_Social_PP_03" } ], "shape": [ 1080, 810 ], "speed": { "inference": 34.58214, "postprocess": 0.04768, "preprocess": 17.8256 } } ], "metadata": { "functionTimeAlive": 21506.304, "functionTimeCall": 0.09, "imageCount": 1, "model": "https://hub.ultralytics.com/models/uBRAwxJRTTWrihq4Mxw3", "version": { "python": "3.11.10", "torch": "2.4.1+cpu", "torchvision": "0.19.1+cpu", "ultralytics": "8.2.103" } } }
curl -X POST "https://predict.ultralytics.com" \ -H "Content-Type: multipart/form-data" \ -H "x-api-key: d3fc123d26aaf85f89ab6064363146ec52d5a0b619" \ -F "model=https://hub.ultralytics.com/models/uBRAwxJRTTWrihq4Mxw3" \ -F "imgsz=640" \ -F "conf=0.25" \ -F "iou=0.45" \ -F "file=/Users/curtinmjc/AI/model_analysis/created_jpg/IMG_3220copy.jpg"
cURL response
{ "error": "Internal Server Error", "help": "For detailed usage instructions, visit https://docs.ultralytics.com/hub/inference-api. For bug reports or questions, visit https://github.com/ultralytics/hub/issues.", "message": "An unexpected error occurred while processing your request: '\u001b[31m\u001b[1mfile\u001b[0m' is not a valid YOLO argument. Similar arguments are i.e. ['profile=False'].\n\n Arguments received: ['yolo', '--bind', ':8080', '--timeout', '0', 'main:app']. Ultralytics 'yolo' commands use the following syntax:\n\n yolo TASK MODE ARGS\n\n Where TASK (optional) is one of {'detect', 'obb', 'pose', 'classify', 'segment'}\n MODE (required) is one of {'predict', 'track', 'val', 'train', 'benchmark', 'export'}\n ARGS (optional) are any number of custom 'arg=value' pairs like 'imgsz=320' that override defaults.\n See all ARGS at https://docs.ultralytics.com/usage/cfg or with 'yolo cfg'\n\n 1. Train a detection model for 10 epochs with an initial learning_rate of 0.01\n yolo train data=coco8.yaml model=yolov8n.pt epochs=10 lr0=0.01\n\n 2. Predict a YouTube video using a pretrained segmentation model at image size 320:\n yolo predict model=yolov8n-seg.pt source='https://youtu.be/LNwODJXcvt4' imgsz=320\n\n 3. Val a pretrained detection model at batch-size 1 and image size 640:\n yolo val model=yolov8n.pt data=coco8.yaml batch=1 imgsz=640\n\n 4. Export a YOLOv8n classification model to ONNX format at image size 224 by 128 (no TASK required)\n yolo export model=yolov8n-cls.pt format=onnx imgsz=224,128\n\n 5. Explore your datasets using semantic search and SQL with a simple GUI powered by Ultralytics Explorer API\n yolo explorer data=data.yaml model=yolov8n.pt\n \n 6. Streamlit real-time webcam inference GUI\n yolo streamlit-predict\n \n 7. Run special commands:\n yolo help\n yolo checks\n yolo version\n yolo settings\n yolo copy-cfg\n yolo cfg\n\n Docs: https://docs.ultralytics.com\n Community: https://community.ultralytics.com\n GitHub: https://github.com/ultralytics/ultralytics\n " }
curl -X POST "https://predict.ultralytics.com" \ -H "x-api-key: API_KEY" \ -F "model=https://hub.ultralytics.com/models/MODEL_ID" \ -F "file=@/path/to/image.jpg" \ -F "imgsz=640" \ -F "conf=0.25" \ -F "iou=0.45"
Environment
Minimal Reproducible Example
Ran Python code in Visual Studio Code Ran cURL in iTerm2 terminal
Additional
No response