Skip to content
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

Repeated API Errors #664

Open
1 task done
willhy4 opened this issue Apr 27, 2024 · 2 comments
Open
1 task done

Repeated API Errors #664

willhy4 opened this issue Apr 27, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@willhy4
Copy link

willhy4 commented Apr 27, 2024

Search before asking

  • I have searched the HUB issues and found no similar bug report.

HUB Component

Inference

Bug


HTTPError Traceback (most recent call last)
Cell In[13], line 16
12 response = requests.post(url, headers=headers, data=data, files={"image": f})
13 #if response.status_code == 429:
14 # time.sleep(int(response.headers["Retry-After"]))
---> 16 response.raise_for_status()
18 # Get predicted class and confidence from response
19 predicted_class = response.json()['data'][0]['class']

File ~/Python310-boto3/lib/python3.10/site-packages/requests/models.py:1021, in Response.raise_for_status(self)
1016 http_error_msg = (
1017 f"{self.status_code} Server Error: {reason} for url: {self.url}"
1018 )
1020 if http_error_msg:
-> 1021 raise HTTPError(http_error_msg, response=self)

HTTPError: 502 Server Error: Bad Gateway for url: https://api.ultralytics.com/v1/predict/AFX0h0mvCLGtEDjTVvbJ

Environment

  • Computer: MacBook Pro (13-inch) - but I get the same error on a 2022 Dell as well since I am calling from a jupyter hub environment
  • processor 2.5 GHz, i5
  • Memory: 16 GM 1600 MHz DDR3
  • Disk: SSD

Minimal Reproducible Example

I am attempting to run inference on 100 images and I get this same error for every model (17 of them) that I have created.

Here's the code:

Iterate through items and store results in lists

for image_filename in os.listdir(image_folder_path):
if image_filename.endswith(('.jpg', '.jpeg', '.png', '.gif')):
image_path = os.path.join(image_folder_path, image_filename)
label_filename = os.path.splitext(image_filename)[0] + '.txt'
label_path = os.path.join(label_folder_path, label_filename)

    # Read the label file to get the actual class
    actual_class = read_label_file(label_path)

    with open(image_path, "rb") as f:
        response = requests.post(url, headers=headers, data=data, files={"image": f})
        #if response.status_code == 429:
        #    time.sleep(int(response.headers["Retry-After"]))
        
    response.raise_for_status()

    # Get predicted class and confidence from response
    predicted_class = response.json()['data'][0]['class']
    confidence = response.json()['data'][0]['confidence']

    # Store results in lists
    image_list.append(image_filename)
    actual_class_list.append(actual_class)
    predicted_class_list.append(predicted_class)
    confidence_list.append(confidence)
    #time.sleep(5)

Function to read label file and extract class information

def read_label_file(label_file_path):
with open(label_file_path, 'r') as label_file:
# Read the first line of the label file
first_line = label_file.readline().strip()

    # Extract the class value from the first integer
    class_value = int(first_line.split()[0])

return class_value

Additional

The url, headers, and data values were copy/paste from the "Deploy" page for each model.

@willhy4 willhy4 added the bug Something isn't working label Apr 27, 2024
Copy link

👋 Hello @willhy4, thank you for raising an issue about Ultralytics HUB 🚀! Please visit our HUB Docs to learn more:

  • Quickstart. Start training and deploying YOLO models with HUB in seconds.
  • Datasets: Preparing and Uploading. Learn how to prepare and upload your datasets to HUB in YOLO format.
  • Projects: Creating and Managing. Group your models into projects for improved organization.
  • Models: Training and Exporting. Train YOLOv5 and YOLOv8 models on your custom datasets and export them to various formats for deployment.
  • Integrations. Explore different integration options for your trained models, such as TensorFlow, ONNX, OpenVINO, CoreML, and PaddlePaddle.
  • Ultralytics HUB App. Learn about the Ultralytics App for iOS and Android, which allows you to run models directly on your mobile device.
    • iOS. Learn about YOLO CoreML models accelerated on Apple's Neural Engine on iPhones and iPads.
    • Android. Explore TFLite acceleration on mobile devices.
  • Inference API. Understand how to use the Inference API for running your trained models in the cloud to generate predictions.

If this is a 🐛 Bug Report, please provide screenshots and steps to reproduce 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!

@pderrenger
Copy link
Member

Hello! It looks like you're encountering a 502 Bad Gateway error, which typically indicates an issue on the server side, not with your code or environment. Here are a few steps you can take:

  1. Retry the Request: Sometimes, simply retrying the request after a brief pause can resolve the issue.
  2. Check Server Status: There might be temporary downtime or maintenance on the server. It's good to check if there are any known issues or maintenance updates from Ultralytics.
  3. Review API Limits: Ensure you're not hitting any rate limits that might cause the server to drop your requests.

If the issue persists, I recommend reaching out with this detailed report on the GitHub issues page or contacting support directly to investigate this specific server error further. They might need to look into the backend logs to see what's causing the 502 error for your requests. Thanks for your patience! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants