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

imgsz bug when using openvino #12841

Closed
1 of 2 tasks
KeitoKohinata opened this issue May 19, 2024 · 8 comments
Closed
1 of 2 tasks

imgsz bug when using openvino #12841

KeitoKohinata opened this issue May 19, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@KeitoKohinata
Copy link

Search before asking

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

YOLOv8 Component

Predict

Bug

I get an error when I run the following program.

After training on a non-640 imgsz, export to the openvino model.
When predict() is run on the model, the following error is output for imgsz.

"the input tensor size is not equal to the model input tyep: got [1,3,640,640] expecting [1,3,320,320]"

I assume that this is because the imgsz information is not read from yaml when the openvino model is loaded.

Is this error caused by my program being inadequate? Or is it a bug?
(If it is a bug, I think it needs to be resolved by adding a process to YOLO._load() that reads the yaml and sets the imgsz appropriately, etc.)

Translated with DeepL.com (free version)

Environment

No response

Minimal Reproducible Example

train and export

model.train(
data="dataset.yaml",
epochs=20,
imgsz=320,
project="myproject",
)
model.export(format="openvino", imgsz=imgsz)

predict

model = YOLO("best_openvino_model", task="detect")
result = model.predict(numpy_image) # error

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@KeitoKohinata KeitoKohinata added the bug Something isn't working label May 19, 2024
Copy link

👋 Hello @KeitoKohinata, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

Hello,

Thanks for reporting this issue. It seems like the model export did not correctly translate the image size (imgsz) used during the training (320 in your case) to the exported OpenVINO model.

The error you're encountering suggests that the image size expected by the OpenVINO model is still set to the default (640x640) rather than what you used during training (320x320). To ensure the exported model uses the right imgsz, please specify it again during the export phase as shown below:

model.export(format="openvino", imgsz=320)

This should help align the expected input size of your model with the actual data passing through during prediction. Be sure to consistently use the same image size you trained with when exporting and running predictions.

If the problem persists after trying this fix, it may indeed be a bug. I'd recommend watching the issue tracker for updates related to this problem or any patch that might address it.

Good luck!

@KeitoKohinata
Copy link
Author

Thank you for your reply.
The example I showed was not good.
The example is running as imgsz=320. Thus, it is equivalent to running model.export(format="openvino", imgsz=320).

@glenn-jocher
Copy link
Member

glenn-jocher commented May 19, 2024

Hello,

Thank you for the clarification. If you've already exported the model with imgsz=320 and are still facing issues, it might be beneficial to double-check the loading and prediction steps. Ensure that the image size during prediction matches the size used during training and exporting.

Here's a quick check you can perform when loading the model for prediction:

model = YOLO("best_openvino_model", task="detect")
result = model.predict(numpy_image, imgsz=320)

This explicitly sets the image size when loading the model, which might help resolve any discrepancies. If the issue persists, it could be a bug, and I recommend opening an issue on the repository for further investigation.

Hope this helps! 😊

@KeitoKohinata
Copy link
Author

Thank you for your reply.

YOLO() does not have imgsz as an argument. Therefore, your suggested code will result in an error.

Are you using another "YOLO" that is not "from ultralytics import YOLO" ?

Also, even if you solved the problem by explicitly specifying the argument that way, it would be a bit tedious to specify it, since the openvino model should keep the information about the imgsz.

@glenn-jocher
Copy link
Member

@KeitoKohinata ah yes, you're right! The imgsz argument belongs in the predict method:

model = YOLO("best_openvino_model", task="detect")
result = model.predict(numpy_image, imgsz=320)

@KeitoKohinata
Copy link
Author

Thank you for your reply.
Sorry for the mistake ................
I ran "model.predict(numpy_image, imgsz=320)" and it worked fine.

@glenn-jocher
Copy link
Member

@KeitoKohinata great to hear that it worked! If you have any more questions or run into other issues, feel free to reach out. Happy coding! 😊

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