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

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 30 but got size 29 for tensor number 1 in the list. #243

Closed
1 of 2 tasks
VYRION-Ai opened this issue Jan 11, 2023 · 38 comments
Labels
bug Something isn't working

Comments

@VYRION-Ai
Copy link

VYRION-Ai commented Jan 11, 2023

Search before asking

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

YOLOv8 Component

No response

Bug

When trying to do traning in local pc
yolo task=detect mode=train model=yolov8n.pt data=data.yaml epochs=3 imgsz=460 batch=1 cache=True

I:\python>yolo task=detect mode=train model=yolov8n.pt data=data.yaml epochs=3 imgsz=460 batch=1 cache=True
yolo\engine\trainer: task=detect, mode=train, model=yolov8n.pt, data=data.yaml, epochs=3, patience=50, batch=1, imgsz=460, save=True, cache=True, device=None, workers=8, project=None, name=None, exist_ok=False, pretrained=False, optimizer=SGD, verbose=False, seed=0, deterministic=True, single_cls=False, image_weights=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, show=False, save_txt=False, save_conf=False, save_crop=False, hide_labels=False, hide_conf=False, vid_stride=1, line_thickness=3, visualize=False, augment=False, agnostic_nms=False, retina_masks=False, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=17, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, fl_gamma=0.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0, hydra={'output_subdir': None, 'run': {'dir': '.'}}, v5loader=False, save_dir=runs\detect\train4
Ultralytics YOLOv8.0.3  Python-3.8.7 torch-1.10.0+cu113 CUDA:0 (NVIDIA GeForce GTX 1050 Ti, 4096MiB)
Overriding model.yaml nc=80 with nc=28

                   from  n    params  module                                       arguments
  0                  -1  1       464  ultralytics.nn.modules.Conv                  [3, 16, 3, 2]
  1                  -1  1      4672  ultralytics.nn.modules.Conv                  [16, 32, 3, 2]
  2                  -1  1      7360  ultralytics.nn.modules.C2f                   [32, 32, 1, True]
  3                  -1  1     18560  ultralytics.nn.modules.Conv                  [32, 64, 3, 2]
  4                  -1  2     49664  ultralytics.nn.modules.C2f                   [64, 64, 2, True]
  5                  -1  1     73984  ultralytics.nn.modules.Conv                  [64, 128, 3, 2]
  6                  -1  2    197632  ultralytics.nn.modules.C2f                   [128, 128, 2, True]
  7                  -1  1    295424  ultralytics.nn.modules.Conv                  [128, 256, 3, 2]
  8                  -1  1    460288  ultralytics.nn.modules.C2f                   [256, 256, 1, True]
  9                  -1  1    164608  ultralytics.nn.modules.SPPF                  [256, 256, 5]
 10                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 11             [-1, 6]  1         0  ultralytics.nn.modules.Concat                [1]
 12                  -1  1    148224  ultralytics.nn.modules.C2f                   [384, 128, 1]
 13                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']
 14             [-1, 4]  1         0  ultralytics.nn.modules.Concat                [1]
 15                  -1  1     37248  ultralytics.nn.modules.C2f                   [192, 64, 1]
 16                  -1  1     36992  ultralytics.nn.modules.Conv                  [64, 64, 3, 2]
 17            [-1, 12]  1         0  ultralytics.nn.modules.Concat                [1]
 18                  -1  1    123648  ultralytics.nn.modules.C2f                   [192, 128, 1]
 19                  -1  1    147712  ultralytics.nn.modules.Conv                  [128, 128, 3, 2]
 20             [-1, 9]  1         0  ultralytics.nn.modules.Concat                [1]
 21                  -1  1    493056  ultralytics.nn.modules.C2f                   [384, 256, 1]
 22        [15, 18, 21]  1    756772  ultralytics.nn.modules.Detect                [28, [64, 128, 256]]
Model summary: 225 layers, 3016308 parameters, 3016292 gradients, 8.2 GFLOPs

Transferred 319/355 items from pretrained weights
optimizer: SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias
train: Scanning I:\python\road damage\full database\labels\train.cache... 2491 images, 0 backgrounds, 0 corrupt: 100%|██████████| 2491/2491 [00:00<?, ?it/s]
train: Caching images (0.9GB True): 100%|██████████| 2491/2491 [00:46<00:00, 53.26it/s]
albumentations: Blur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01), CLAHE(p=0.01, clip_limit=(1, 4.0), tile_grid_size=(8, 8))
val: Scanning I:\python\road damage\full database\labels\valid.cache... 830 images, 0 backgrounds, 0 corrupt: 100%|██████████| 830/830 [00:00<?, ?it/s]
val: Caching images (0.3GB True): 100%|██████████| 830/830 [00:20<00:00, 39.86it/s]
Image sizes 460 train, 460 val
Using 0 dataloader workers
Logging results to runs\detect\train4
Starting training for 3 epochs...

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
  0%|          | 0/2491 [00:02<?, ?it/s]
Error executing job with overrides: ['task=detect', 'mode=train', 'model=yolov8n.pt', 'data=data.yaml', 'epochs=3', 'imgsz=460', 'batch=1', 'cache=True']
Traceback (most recent call last):
  File "i:\python\road damage\full database\ultralytics\ultralytics\yolo\cli.py", line 52, in cli
    func(cfg)
  File "C:\Users\Mroid\AppData\Local\Programs\Python\Python38\lib\site-packages\hydra\main.py", line 79, in decorated_main
    return task_function(cfg_passthrough)
  File "i:\python\road damage\full database\ultralytics\ultralytics\yolo\v8\detect\train.py", line 206, in train
    model.train(**cfg)
  File "i:\python\road damage\full database\ultralytics\ultralytics\yolo\engine\model.py", line 193, in train
    self.trainer.train()
  File "i:\python\road damage\full database\ultralytics\ultralytics\yolo\engine\trainer.py", line 177, in train
    self._do_train(int(os.getenv("RANK", -1)), world_size)
  File "i:\python\road damage\full database\ultralytics\ultralytics\yolo\engine\trainer.py", line 292, in _do_train
    preds = self.model(batch["img"])
  File "C:\Users\Mroid\AppData\Roaming\Python\Python38\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "i:\python\road damage\full database\ultralytics\ultralytics\nn\tasks.py", line 175, in forward
    return self._forward_once(x, profile, visualize)  # single-scale inference, train
  File "i:\python\road damage\full database\ultralytics\ultralytics\nn\tasks.py", line 56, in _forward_once
    x = m(x)  # run
  File "C:\Users\Mroid\AppData\Roaming\Python\Python38\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "i:\python\road damage\full database\ultralytics\ultralytics\nn\modules.py", line 365, in forward
    return torch.cat(x, self.d)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 30 but got size 29 for tensor number 1 in the list.

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

Environment

No response

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@VYRION-Ai VYRION-Ai added the bug Something isn't working label Jan 11, 2023
@VYRION-Ai
Copy link
Author

when change the img size to 640 the code run correctly ? why?

@Laughing-q
Copy link
Member

@totoadel you have to make sure the img size can be divided by 32. That's the rule. :)

@VYRION-Ai
Copy link
Author

i use 460 , i should use 480, thank you
that happened because in yolov5 it was correct automatically , sorry .

@Robotatron
Copy link

@totoadel you have to make sure the img size can be divided by 32. That's the rule. :)

It works with YOLOv5, it will automatically change the image size to be divisible by 32. I guess v8 doesnt do that?

@Caliphamin
Copy link

@Laughing-q my image sizes are 1024x1024 but not working. i am facing this error

Sizes of tensors must match except in dimension 1. Expected size 57 but got size 0 for tensor number 1 in the list.
Sentry is attempting to send 1 pending error messages

i am using this command to run yolo instance segmentation
!yolo task=segment mode=train model=yolov8m-seg.pt data={dataset.location}/data.yaml epochs=100 imgsz=1024 batch=8
when i change image sizes or batch size the expected size in error changes to another number

@Laughing-q
Copy link
Member

Laughing-q commented Mar 21, 2023

@Caliphamin Training with your command but with coco128-seg.yaml works correctly to me.

yolo task=segment mode=train model=yolov8m-seg.pt data=coco128-seg.yaml epochs=100 imgsz=1024 batch=4

image

BTW I'm using the latest version of package.

@Caliphamin
Copy link

@Laughing-q
I’ve changed my data format to yolov8

@Caliphamin
Copy link

Caliphamin commented Mar 21, 2023

@Laughing-q
Can i send my data for you?
I’ve uploaded on roboflow

@Laughing-q
Copy link
Member

@Caliphamin sure, laughingq@163.com.

@Laughing-q
Copy link
Member

@Caliphamin I just checked your dataset, and found you were using a detection labels but trying to train a segmentation model which is incorrect. You should always train a segmentation model with segmentation labels.

BTW I just saw the following error when I was trying to reproduce your issue but it seems that you didn't encounter this error msg.
image
So I suppose that you might also need to upgrade the package pip install --upgrade ultralytics.

@Caliphamin
Copy link

@Laughing-q ooooh, you mean my data is wrong. actually i did not get this message. i just thought my image sizes or batch sizes are wrong
thanks for helping me.
i am going to change my data and try it again.

@Laughing-q
Copy link
Member

@Caliphamin Also It's better to use the latest version of package. :)

@Caliphamin
Copy link

I will do that too:)

@AnonymousPhython
Copy link

AnonymousPhython commented Mar 28, 2023

@Laughing-q I am getting the same erroe can you check my dataset too..
Here is the link to the dataset: https://app.roboflow.com/btech-project/heavy-vehicle-detection-and-classification

@Caliphamin
Copy link

@AnonymousPhython my problem solved by changing dataset label from object detection to instance segmentation
What is your dataset format?(i mean yolo, coco and etc)

@AnonymousPhython
Copy link

@AnonymousPhython my problem solved by changing dataset label from object detection to instance segmentation What is your dataset format?(i mean yolo, coco and etc)

hi, it is YOLOv8 i am using yolov8n-seg.
you can take a look into my dataset at https://app.roboflow.com/btech-project/heavy-vehicle-detection-and-classification

@Caliphamin
Copy link

Pls send the code that you use to train
And also what do you want to do
I mean you working on instance segment or what

@AnonymousPhython
Copy link

thanks.. it is working now..

@Caliphamin
Copy link

@AnonymousPhython What?how?😁

@glenn-jocher
Copy link
Member

I apologize for any confusion. I am an AI language model and sometimes my responses might not make sense or be relevant to the conversation. Is there anything I can assist you with?

@Kr-Sheshank
Copy link

Screenshot from 2023-05-17 11-59-37

I got the same error, size of a tensor is not matched, even when I m using 416 and 640 image sizes.
Please help

@VYRION-Ai
Copy link
Author

@Kr-Sheshank it seems you are ruining training on local pc , if true, change batch=1

@Kr-Sheshank
Copy link

No i m running in google colab,
Screenshot from 2023-05-17 13-13-21

@Kr-Sheshank it seems you are ruining training on local pc , if true, change batch=1

@Kr-Sheshank
Copy link

@Caliphamin Training with your command but with coco128-seg.yaml works correctly to me.

yolo task=segment mode=train model=yolov8m-seg.pt data=coco128-seg.yaml epochs=100 imgsz=1024 batch=4

image

BTW I'm using the latest version of package.

I tried this it is working, training for coco data set is working but not for my dataset which I'm using from exporting from roboflow

@VYRION-Ai
Copy link
Author

@Kr-Sheshank write down your .yaml file here

@Kr-Sheshank
Copy link

@Kr-Sheshank write down your .yaml file here

names:

@Kr-Sheshank
Copy link

I think problem is with my dataset,I used another v8 segment data set from roboflow than training got start

@glenn-jocher
Copy link
Member

@VYRION-Ai based on the error message you posted, it looks like the issue may be with your dataset. If you used another YOLOv8 segment dataset from Roboflow and the training started successfully, then it could be that your original dataset may have had issues with it. You may want to double check your original dataset to ensure that it's properly formatted and contains the necessary files and annotations in the correct format for YOLOv8 to work with.

@CoffeeinTeaC
Copy link

@AnonymousPhython What?how?😁

@AnonymousPhython my problem solved by changing dataset label from object detection to instance segmentation What is your dataset format?(i mean yolo, coco and etc)

I encounter same problem.I guess something wrong in the process during json file convert to txt file.But I am not sure.Can you help me .

@liyan1997
Copy link

I encountered the same problem, but when I set the parameter “save_hybrid” to False, this issue is resolved.

@TheSole0
Copy link

TheSole0 commented May 30, 2023

@glenn-jocher

I got the same above problems in Yolov8
My command is yolo detect train data=kitti.yaml model=yolov8s_test.yaml epochs=50 imgsz=640
this is my yaml file

`
backbone:
[from, repeats, module, args]

  • [-1, 1, Conv, [64, 3, 2]] # 0-P1/2
  • [-1, 1, Conv, [128, 3, 2]] # 1-P2/4
  • [-1, 3, C2f, [128, True]] # 2
  • [-1, 1, Conv, [256, 3, 2]] # 3-P3/8
  • [-1, 6, C2f, [256, True]] # 4
  • [-1, 1, Conv, [512, 3, 2]] # 5-P4/16
  • [-1, 6, C2f, [512, True]] # 6
  • [-1, 1, Conv, [768, 3, 2]] # 7-P5/32
  • [-1, 6, C2f, [768, True]] # 8
  • [-1, 1, Conv, [1024, 3, 2]] # 9-P6/64
  • [-1, 3, C2f, [1024, True]] # 10
  • [-1, 1, SPPF, [1024, 5]] # 11

head:

  • [-1, 1, nn.Upsample, [None, 2, 'nearest']] # 12

  • [[-1, 8], 1, Concat, [1]] # cat backbone P5 # 13

  • [-1, 3, C2f, [768]] # 14

  • [-1, 1, nn.Upsample, [None, 2, 'nearest']] # 15

  • [[-1, 6], 1, Concat, [1]] # cat backbone P4 # 16

  • [-1, 3, C2f, [512]] # (P4/16-medium) # 17

  • [-1, 1, Conv, [512, 3, 2]] # 18

  • [[-1, 14], 1, Concat, [1]] # cat head P3 # 19

  • [-1, 3, C2f, [768]] # (P5/32-large) # 20

  • [[17, 20], 1, Detect, [nc]] # Detect(P4, P5, P6) # 24
    `
    Actually, I want to use only medium and large heads that's why I did to scale up in backbone but it couldn't
    Why is this not working? Anybody can help me?

Image sizes 640 train, 640 val Using 8 dataloader workers Logging results to runs\detect\train11 Starting training for 50 epochs... Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size 1/50 3.25G 4.309 3.989 3.242 11 640: 100%|██████████| 335/335 [00:58<00:00 Class Images Instances Box(P R mAP50 mAP50-95): 0%| | 0/43 [00: Traceback (most recent call last): File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\dlwlsgh\.conda\envs\yolov8\Scripts\yolo.exe\__main__.py", line 7, in <module> File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\ultralytics\yolo\cfg\__init__.py", line 317, in entrypoint getattr(model, mode)(**overrides) # default args from model File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\ultralytics\yolo\engine\model.py", line 325, in train self.trainer.train() File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\ultralytics\yolo\engine\trainer.py", line 186, in train self._do_train(RANK, world_size) File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\ultralytics\yolo\engine\trainer.py", line 357, in _do_train self.metrics, self.fitness = self.validate() File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\ultralytics\yolo\engine\trainer.py", line 453, in validate metrics = self.validator(self) File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\torch\autograd\grad_mode.py", line 26, in decorate_context return func(*args, **kwargs) File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\ultralytics\yolo\engine\validator.py", line 159, in __call__ preds = model(batch['img']) File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\ultralytics\nn\tasks.py", line 199, in forward return self._forward_once(x, profile, visualize) # single-scale inference, train File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\ultralytics\nn\tasks.py", line 58, in _forward_once x = m(x) # run File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "C:\Users\dlwlsgh\.conda\envs\yolov8\lib\site-packages\ultralytics\nn\modules.py", line 352, in forward return torch.cat(x, self.d) RuntimeError: Sizes of tensors must match except in dimension 2. Got 7 and 8 (The offending index is 0)

image

image

I already try to change stride 32 to 64 in "v5loader.py", "build.py" and "trainer.py"
Plz help me

@aleehamza25
Copy link

I encountered the same problem, but when I set the parameter “save_hybrid” to False, this issue is resolved.

I was exhausted after wasting my whole day due to this parameter. You just saved my life

@pderrenger
Copy link
Member

@aleehamza25 i'm glad to hear that setting the parameter "save_hybrid" to False resolved the issue for you! Sometimes small changes can have a big impact. If you have any more questions or need further assistance, feel free to ask!

@MandilJThapa
Copy link

!yolo task=segment mode=train model=yolov8s-seg.pt data=dataset.yaml epochs=10 imgsz=320 batch= 4 save=true
Screenshot (132)
This problem arise when i am training custom data on yolov8 segmentation model

@glenn-jocher
Copy link
Member

@MandilJThapa it looks like there might be an issue with the way the dataset or the model is configured. Could you please check if your dataset.yaml is correctly set up for segmentation tasks, and that the paths to images and labels are correct? Also, ensure that your model yolov8s-seg.pt is compatible with the segmentation task you're aiming at. If the problem persists, it could be helpful to share the dataset.yaml content and any error logs for more context.🙂

@AZong76
Copy link

AZong76 commented Jun 5, 2024

After improving the YOLOv8 model structure, I encountered a similar issue when performing val on the Visdrone dataset:

Ultralytics YOLOv8.0.180 🚀 Python-3.8.19 torch-1.12.0+cu116 CUDA:1 (NVIDIA GeForce RTX 3090, 24259MiB)
YOLOv8x_DW_swin_FOCUS-3 summary: 556 layers, 199741797 parameters, 0 gradients
val: Scanning /home/lyu4/datasets/dh_wp/dh/visdrone-det/visdrone2024/VisDrone2019-DET-test-dev/labels.cache...
val: Caching images (2.5GB True): 100%|██████████| 1610/1610 [00:03<00:00, 474.51it/s]
Class Images Instances Box(P R mAP50 mAP50-95): 0%| | 0/1
Traceback (most recent call last):
File "val.py", line 7, in
validation_results = model.val(data="/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/datasets/VisDrone-test.yaml", imgsz=960, iou = 0.6, batch=1, device="1",save_hybrid=True)
File "/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/engine/model.py", line 272, in val
validator(model=self.model)
File "/home/lyu4/anaconda3/envs/v8improve/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/engine/validator.py", line 168, in call
preds = model(batch['img'], augment=augment)
File "/home/lyu4/anaconda3/envs/v8improve/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/nn/autobackend.py", line 333, in forward
y = self.model(im, augment=augment, visualize=visualize) if augment or visualize else self.model(im)
File "/home/lyu4/anaconda3/envs/v8improve/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/nn/tasks.py", line 49, in forward
return self.predict(x, *args, **kwargs)
File "/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/nn/tasks.py", line 66, in predict
return self._predict_once(x, profile, visualize)
File "/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/nn/tasks.py", line 86, in _predict_once
x = m(x) # run
File "/home/lyu4/anaconda3/envs/v8improve/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/nn/modules/conv.py", line 294, in forward
return torch.cat(x, self.d)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 32 but got size 31 for tensor number 1 in the list.

@AZong76
Copy link

AZong76 commented Jun 5, 2024

在改进了YOLOv8模型结构之后,我在Visdrone数据集上进行val时也遇到了类似的问题:

Ultralytics YOLOv8.0.180 🚀 Python-3.8.19 torch-1.12.0+cu116 CUDA:1(NVIDIA GeForce RTX 3090,24259MiB)
YOLOv8x_DW_swin_FOCUS-3 摘要:556 层,199741797 个参数,0 个梯度
val:扫描 /home/lyu4/datasets/dh_wp/dh/visdrone-det/visdrone2024/VisDrone2019-DET-test-dev/labels.cache...
val:缓存图像(2.5GB True):100%|██████████| 1610/1610 [00:03<00:00, 474.51it/s]
类别图像实例框(PR mAP50 mAP50-95): 0%| | 0/1
回溯(最近一次调用最后一次):
文件“val.py”,第 7 行,在
validation_results = model.val(data="/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/datasets/VisDrone-test.yaml",imgsz=960,iou = 0.6,batch=1,device="1",save_hybrid=True)
文件“/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/engine/model.py”,第 272 行,在 val
validator(model=self.model)
文件“/home/lyu4/anaconda3/envs/v8improve/lib/python3.8/site-packages/torch/autograd/grad_mode.py”,第 27 行,在 decorate_context
return func(*args, kwargs)
文件“/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/engine/validator.py”,第 168 行,在
调用**中
preds = model(batch['img'], augment=augment)
文件“/home/lyu4/anaconda3/envs/v8improve/lib/python3.8/site-packages/torch/nn/modules/module.py”,第 1130 行,在 _call_impl 中
返回 forward_call(*input,**kwargs)
文件“/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/nn/autobackend.py”,第 333 行,在正向
y = self.model(im,augment=augment,visualize=visualize)如果 augment 或 visualize else self.model(im)
文件“/home/lyu4/anaconda3/envs/v8improve/lib/python3.8/site-packages/torch/nn/modules/module.py”,第 1130 行,在 _call_impl 中
返回 forward_call(*input, **kwargs)
文件“/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/nn/tasks.py”,第 49 行,在 forward 中
返回 self.predict(x, *args, **kwargs)
文件“/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/nn/tasks.py”,第 66 行,在 predict 中
返回 self._predict_once(x, profile, visualize)
文件“/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/nn/tasks.py”, 第 86 行, 在 _predict_once
x = m(x) # 运行
文件“/home/lyu4/anaconda3/envs/v8improve/lib/python3.8/site-packages/torch/nn/modules/module.py”, 第 1130 行, 在 _call_impl 中
返回 forward_call(*input, **kwargs)
文件“/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/ultralytics/nn/modules/conv.py”, 第 294 行, 在 forward 中
返回 torch.cat(x, self.d)
RuntimeError:除维度 1 外,张量的大小必须匹配。列表中张量 1 的预期大小为 32,但实际得到的大小为 31。

This is my command:
`from ultralytics import YOLO

model = YOLO("/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/runs/detect/yolov8x_DW_swin_FOCUS-3--调参/weights/best.pt")

validation_results = model.val(data="/home/lyu4/datasets/dh_wp/dh/visdrone-det/v8-improve/datasets/VisDrone-test.yaml", imgsz=960, iou = 0.6, batch=1)`

@glenn-jocher
Copy link
Member

@AZong76 it seems like you're encountering a tensor size mismatch error during the concatenation process in your model's forward pass. This typically happens when the dimensions of the tensors being concatenated do not align as expected except for the specified dimension (in your case, dimension 1).

Here are a few steps you can take to troubleshoot and potentially resolve this issue:

  1. Check Layer Outputs: Ensure that all layers of your model are outputting the expected tensor shapes. You can add print statements temporarily in your model's forward function to log the shapes of tensors before they are concatenated.

  2. Review Model Architecture: Double-check your model configuration in yolov8s-seg.pt to ensure that all layers are correctly specified and that the output dimensions of each layer correctly match where they are concatenated.

  3. Batch Size: Sometimes issues arise when batch size is set to 1, due to how some layers behave differently with single-item batches. Although less likely the issue here, it's something to consider if other troubleshooting steps fail.

  4. Configuration File: Verify that your VisDrone-test.yaml is correctly set up and matches the expected format and paths for the Visdrone dataset.

  5. Update and Test: Ensure your environment is using the latest version of Ultralytics YOLOv8 and dependencies. Sometimes, bugs fixed in newer versions could resolve your issue.

If these steps do not resolve the problem, consider providing more details such as the specific layers involved in the error, and possibly a snippet of your model's architecture around the problematic layers. This information could help further diagnose the issue.

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