ultralytics / hub

Ultralytics HUB tutorials and support
https://hub.ultralytics.com
GNU Affero General Public License v3.0
107 stars 11 forks source link

Repeated API Errors #664

Open willhy4 opened 2 weeks ago

willhy4 commented 2 weeks ago

Search before asking

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

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.

github-actions[bot] commented 2 weeks ago

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

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!