ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.02k stars 16.41k forks source link

Issue with Inference post Comet integration #13388

Closed MoonTales closed 3 weeks ago

MoonTales commented 3 weeks ago

Search before asking

Question

I have been in the works of following the Train custom data to train my own data set, which i was successful in doing. I was able to get my data trained, and then I attempted to inference my data.

I was able to get the results from my loaded model (though my bounding boxes where way smaller than they should been, which I recently learned might be due to my data being 64x64 and i just noticed in detect.py I forgot to also set my detect img size to 64x64.

However the issue I am facing is i use to pass my images into my inference in the following way:

    # images is my list of images i want to inference
    for i, img in enumerate(images):
        # Convert to 64x64x3 RGB 
        img = np.reshape(img, (64, 64, 3))
        # Uncommenting this gives a different error
        #img = torch.from_numpy(img).permute(2, 0, 1).float().div(255).unsqueeze(0).to(device)

        # Perform inference on the image
        results = model(img)

        # Extract predicted classes and bounding boxes in XYWH format
        results_xywh = results.xywh[0].cpu().numpy()  # Extracting xywh predictions for the first image in batch

However, I decidedto try the "hyp.no-augmentation.yaml" hyper params, and enable Comet logging. after this moment I have never been able to revert my code back to the state it was before, even though the base of my code did not change at all.

Using the same code I used to be able to get my XYWH after results, I changed the hyper params, enabled COMET, and now the exact same code provides the following error:

TypeError: conv2d() received an invalid combination of arguments - got (str, Parameter, NoneType, tuple, tuple, tuple, int), but expected one of:
 * (Tensor input, Tensor weight, Tensor bias = None, tuple of ints stride = 1, tuple of ints padding = 0, tuple of ints dilation = 1, int groups = 1)
      didn't match because some of the arguments have invalid types: (!str!, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (int, int)!, !int!)
 * (Tensor input, Tensor weight, Tensor bias = None, tuple of ints stride = 1, str padding = "valid", tuple of ints dilation = 1, int groups = 1)
      didn't match because some of the arguments have invalid types: (!str!, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (int, int)!, !int!)

I am really struggling to understand what could have happened to stop my Inference from working, because I dont recall changing my inference function. because if i uncomment the line of code:

img = torch.from_numpy(img).permute(2, 0, 1).float().div(255).unsqueeze(0).to(device)

i then get a result that dosent even have the xywh prediction in it

{AttributeError}AttributeError("'tuple' object has no attribute 'pred'")

TLDR: is there something i somehow accidently changed to fundamentally alter how my inference is working? or can comet actually change my files to stop existing code from working, I didnt have any issues untill i enabled Comet Logging

EDIT: I have tried to essentially rebuild part of my project from scratch in a new file, and I no longer have this issue? I'm trying to avoid restarting and frankenstiening my code together, because I still can not find what is causing this error

Additional

No response

UltralyticsAssistant commented 3 weeks ago

👋 Hello @MoonTales, thank you for bringing this issue to our attention 🚀!

To better assist you, please provide a minimum reproducible example of your code that leads to the issue you're experiencing with inference after integrating Comet. This will help us debug the problem more effectively. It seems like the changes in hyperparameters and Comet logging settings might have had an unforeseen impact on your inference setup.

Ensure your dataset and any modifications to the image preprocessing match the input expectations of your model. Additionally, please check if any integrations or packages like Comet have inadvertently altered your environment or scripts.

Please note that this is an automated response, and an Ultralytics engineer will be with you shortly to assist further. Meanwhile, you might want to review your setup and ensure that everything aligns with the intended configurations. Feel free to provide additional context or logs if you think they might help in diagnosing the issue. Keep us updated! 😊

pderrenger commented 1 week ago

@MoonTales it seems like the issue might be related to changes in your environment or dependencies after enabling Comet logging. Please ensure that your YOLOv5 and PyTorch versions are up-to-date. If the problem persists, try isolating the Comet integration to see if it affects inference. You might also want to check if any changes were made to the model or data preprocessing inadvertently. If rebuilding your project resolves the issue, it might be the quickest solution. For further assistance, you can refer to the Comet Logging Integration Guide.