-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using the Inference API #291
Comments
👋 Hello @CemHaligur, thank you for raising an issue about Ultralytics HUB 🚀! Please visit our HUB Docs to learn more, and see our ⭐️ HUB Guidelines to quickly get started uploading datasets and training YOLO models. If this is a 🐛 Bug Report, please provide screenshots and steps to recreate your problem to help us get started working on a fix. If this is a ❓ Question, please provide as much information as possible, including dataset, model, environment details etc. so that we might provide the most helpful response. We try to respond to all issues as promptly as possible. Thank you for your patience! |
Hi @CemHaligur, the response suggests that your request is invalid. Can you give us an example of a request you are sending? You can also try printing the json of the response to see if there is any more information:
|
This is an example of the code : url = "https://api.ultralytics.com/v1/predict/XXXX" headers = {
} files = {
} data = {
} response = requests.post(url, headers=headers, files=files, data=data) And i try to print the json file i have this : {'data': {}, but i have the right path to my file |
@CemHaligur There is an issue with how you are passing the files, I can see the same issue on our example code on HUB. We will get this updated. For now you can follow the docs. The change needed is here:
|
Hi. API returns the 400 - Bad Request response status code : Here is my code: `import requests url = "https://api.ultralytics.com/v1/predict/XXXXXXXXXXXXXXXXX" print(response.json())` |
Same issue with this doc : import requests API URL, use actual MODEL_IDurl = f"https://api.ultralytics.com/v1/predict/XXXXXXXXXX" Headers, use actual API_KEYheaders = {"x-api-key": "XXXXX"} Inference arguments (optional)data = {"size": 640, "confidence": 0.20, "iou": 0.45} Load image and send requestwith open("./data/Raw/V-00476_2023_02_03_09-50-04.jpeg", "rb") as image_file: print(response.json()) -> {'data': {}, 'message': 'Unknown', 'success': False} |
@CemHaligur and @CemHaligur, there seems to be an issue when using specific versions of requests package, which prevents multipart/form-data from being set up correctly. Please make sure you are using requests version 2.22.0 or newer by running If you still face the same error after upgrading the requests package, please try sending the image as bytes instead of a file, as in the following example:
Please let us know if this helps! |
Hi. {'data': {}, 'message': 'An image file or URL must be submitted.', 'success': False} |
@CemHaligur We found an issue that was causing the @ape75 Do not set the content type header but allow requests to set it so that a boundary can be set. import requests
url = "https://api.ultralytics.com/v1/predict/XXXXXXXXX"
headers = {
"x-api-key": "XXXXXXXXXXXXXXXXXXXXX",
}
data = {
"size": 640,
"confidence": 0.25,
"iou": 0.45
}
files={
"image": open("image2.jpg", "rb")
}
response = requests.post(url, headers=headers, files=files, data=data)
print(response.json()) |
Now it is working fine. 👍 |
@ape75 you're welcome! We're glad to hear that the issue has been resolved. If you have any other questions or concerns, please don't hesitate to reach out to us. We're always here to help. Thank you for using Ultralytics HUB! |
Search before asking
HUB Component
No response
Bug
Hey,
I was trying to use the API to inference images in my notebook, but when i try to print my 'response' variable i have this : <Response [400]>.
I guess the API don't work, how can i handle this ?
Kind regards !
Environment
No response
Minimal Reproducible Example
No response
Additional
No response
The text was updated successfully, but these errors were encountered: