ultralytics icon indicating copy to clipboard operation
ultralytics copied to clipboard

I used the engine file for validation tests and found an error

Open Sparklexa opened this issue 1 year ago โ€ข 2 comments

Search before asking

  • [X] I have searched the YOLOv8 issues and discussions and found no similar questions.

Question

The following error has occurred๏ผŒI was not able to change the size of the input by entering the code โ€™metrics = model.val(data='data/data.yaml', batch=16, device=0, imgsz=[1152, 1504])โ€™, resulting in an error๏ผš val: Scanning E:\Project\pythonProject\datasets\billiards\valid\labels.cache... 101 images, 1 backgrounds, 0 corrupt: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 101/101 [00:00<?, ?it/s] Traceback (most recent call last): File "E:\Project\pythonProject\yolov8\val.py", line 6, in metrics = model.val(data='data/data.yaml', batch=16, device=0, imgsz=[1152, 1504]) # no arguments needed, dataset and settings remembered File "E:\Project\pythonProject\yolov8\ultralytics\engine\model.py", line 273, in val validator(model=self.model) File "C:\Users\GTL.conda\envs\pytorch\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "E:\Project\pythonProject\yolov8\ultralytics\engine\validator.py", line 153, in call model.warmup(imgsz=(1 if pt else self.args.batch, 3, imgsz, imgsz)) # warmup File "E:\Project\pythonProject\yolov8\ultralytics\nn\autobackend.py", line 480, in warmup self.forward(im) # warmup File "E:\Project\pythonProject\yolov8\ultralytics\nn\autobackend.py", line 369, in forward assert im.shape == s, f"input size {im.shape} {'>' if self.dynamic else 'not equal to'} max model size {s}" AssertionError: input size torch.Size([1, 3, 1504, 1504]) not equal to max model size (1, 3, 1152, 1504)

Additional

`from ultralytics import YOLO

Load a model

if name == 'main': model = YOLO('runs/detect/train5-Fasternet2/weights/best.engine') # load a custom model metrics = model.val(data='data/data.yaml', batch=16, device=0, imgsz=[1152, 1504]) # no arguments needed, dataset and settings remembered metrics.box.map # map50-95 metrics.box.map50 # map50 metrics.box.map75 # map75 metrics.box.maps # a list contains map50-95 of each category`

Sparklexa avatar Mar 30 '24 04:03 Sparklexa

@Sparklexa hey there! ๐Ÿ‘‹ It looks like you're facing an issue with input size mismatch during validation. The error suggests that the model expects an input size of (1, 3, 1152, 1504) but is receiving an input size of torch.Size([1, 3, 1504, 1504]).

This can typically happen if there's a discrepancy in how the model was exported or a misconfiguration in the specified imgsz. Ensure your imgsz matches the model's expected input dimensions. For TensorRT models (.engine files), the input size is fixed at export time and cannot be changed later. You might need to re-export your model with the correct input size if it was not set correctly initially.

Could you double-check the dimensions used during the export process of your .engine file and confirm they align with your validation code? If there was a misunderstanding in the expected input size at export time, re-exporting the model with the correct dimensions should solve the issue.

Here's an example of how you might re-export your model if needed (replace imgsz with your required size):

model.export(format='engine', imgsz=[1152, 1504])

Hope this helps! Let us know if you have more questions. ๐Ÿ˜Š

glenn-jocher avatar Mar 30 '24 07:03 glenn-jocher

๐Ÿ‘‹ Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

  • Docs: https://docs.ultralytics.com
  • HUB: https://hub.ultralytics.com
  • Community: https://community.ultralytics.com

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO ๐Ÿš€ and Vision AI โญ

github-actions[bot] avatar May 01 '24 00:05 github-actions[bot]