WongKinYiu / yolov9

Implementation of paper - YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information
GNU General Public License v3.0
8.89k stars 1.39k forks source link

RuntimeError: stack expects each tensor to be equal size, but got [1, 256, 32, 32] at entry 0 and [1, 192, 32, 32] at entry 3 #183

Open 7W7W7W opened 6 months ago

7W7W7W commented 6 months ago

Hi,I got the problem:"RuntimeError: stack expects each tensor to be equal size, but got [1, 256, 32, 32] at entry 0 and [1, 192, 32, 32] at entry 3", if it can be resolved,I wii be appreciated.

Youho99 commented 6 months ago

What is your command line ?

7W7W7W commented 6 months ago

What is your command line ?

Hello, it's like this:python train.py --workers 8 --device 0 --batch 4 --data data/VisDrone.yaml --img 640 --cfg models/detect/yolov9-c.yaml --weights '' --name yolov9-c --hyp hyp.scratch-high.yaml --min-items 0 --epochs 200 --close-mosaic 15

Youho99 commented 6 months ago

Use train_dual.py instead of tran.py for yolov9 models Check #1 for more informations

Youho99 commented 6 months ago

Train.py is only for gelan models

7W7W7W commented 6 months ago

Use train_dual.py instead of tran.py for yolov9 models Check #1 for more informations Thank you for your answer. It seems like I still encountered the same mistake:

D:\MiniConda\envs\yolov5\python.exe F:\CNN\deep-learning-for-image-processing-master\pytorch_object_detection\yolov9\train_dual.py 2024-03-11 15:38:30.486259: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudart64_110.dll train_dual: weights=, cfg=models/detect/yolov9-c.yaml, data=data\VisDrone.yaml, hyp=data\hyps\hyp.scratch-high.yaml, epochs=200, batch_size=4, imgsz=640, rect=False, resume=False, nosave=False, noval=False, noautoanchor=False, noplots=False, evolve=None, bucket=, cache=None, image_weights=False, device=0, multi_scale=False, single_cls=False, optimizer=SGD, sync_bn=False, workers=8, project=runs\train, name=exp, exist_ok=False, quad=False, cos_lr=False, flat_cos_lr=False, fixed_lr=False, label_smoothing=0.0, patience=100, freeze=[0], save_period=-1, seed=0, local_rank=-1, min_items=0, close_mosaic=0, entity=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest YOLOv5 v0.1-35-g9660d12 Python-3.8.17 torch-2.0.1+cu118 CUDA:0 (NVIDIA GeForce RTX 3060 Ti, 8192MiB)

hyperparameters: 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, cls_pw=1.0, obj=0.7, obj_pw=1.0, dfl=1.5, iou_t=0.2, anchor_t=5.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.9, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.15, copy_paste=0.3 ClearML: run 'pip install clearml' to automatically track, visualize and remotely train YOLO in ClearML Comet: run 'pip install comet_ml' to automatically track and visualize YOLO runs in Comet TensorBoard: Start with 'tensorboard --logdir runs\train', view at http://localhost:6006/

             from  n    params  module                                  arguments                     

0 -1 1 0 models.common.Silence []
1 -1 1 1392 models.common.Conv [3, 48, 3, 2]
2 -1 1 41664 models.common.Conv [48, 96, 3, 2]
3 -1 1 192256 models.common.RepNCSPELAN4 [96, 192, 128, 64, 1]
4 -1 1 92544 models.common.ADown [192, 192]
5 -1 1 765440 models.common.RepNCSPELAN4 [192, 384, 256, 128, 1]
6 -1 1 369408 models.common.ADown [384, 384]
7 -1 1 2660608 models.common.RepNCSPELAN4 [384, 384, 512, 256, 1]
8 -1 1 369408 models.common.ADown [384, 384]
9 -1 1 2660608 models.common.RepNCSPELAN4 [384, 384, 512, 256, 1]
10 -1 1 492800 models.common.SPPELAN [384, 384, 256]
11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
12 [-1, 7] 1 0 models.common.Concat [1]
13 -1 1 2857216 models.common.RepNCSPELAN4 [768, 384, 512, 256, 1]
14 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
15 [-1, 5] 1 0 models.common.Concat [1]
16 -1 1 814208 models.common.RepNCSPELAN4 [768, 192, 256, 128, 1]
17 -1 1 92544 models.common.ADown [192, 192]
18 [-1, 13] 1 0 models.common.Concat [1]
19 -1 1 2758912 models.common.RepNCSPELAN4 [576, 384, 512, 256, 1]
20 -1 1 369408 models.common.ADown [384, 384]
21 [-1, 10] 1 0 models.common.Concat [1]
22 -1 1 2857216 models.common.RepNCSPELAN4 [768, 384, 512, 256, 1]
23 5 1 98560 models.common.CBLinear [384, [256]]
24 7 1 295680 models.common.CBLinear [384, [256, 512]]
25 9 1 492800 models.common.CBLinear [384, [256, 512, 512]]
26 0 1 1392 models.common.Conv [3, 48, 3, 2]
27 -1 1 41664 models.common.Conv [48, 96, 3, 2]
28 -1 1 192256 models.common.RepNCSPELAN4 [96, 192, 128, 64, 1]
29 -1 1 92544 models.common.ADown [192, 192]
30 [23, 24, 25, -1] 1 0 models.common.CBFuse [[0, 0, 0]]
31 -1 1 765440 models.common.RepNCSPELAN4 [192, 384, 256, 128, 1]
32 -1 1 369408 models.common.ADown [384, 384]
33 [24, 25, -1] 1 0 models.common.CBFuse [[1, 1]]
34 -1 1 2660608 models.common.RepNCSPELAN4 [384, 384, 512, 256, 1]
35 -1 1 369408 models.common.ADown [384, 384]
36 [25, -1] 1 0 models.common.CBFuse [[2]]
37 -1 1 2660608 models.common.RepNCSPELAN4 [384, 384, 512, 256, 1]
38[31, 34, 37, 16, 19, 22] 1 12289244 models.yolo.DualDDetect [10, [384, 384, 384, 192, 384, 384]] Traceback (most recent call last): File "F:\CNN\deep-learning-for-image-processing-master\pytorch_object_detection\yolov9\train_dual.py", line 644, in main(opt) File "F:\CNN\deep-learning-for-image-processing-master\pytorch_object_detection\yolov9\train_dual.py", line 538, in main train(opt.hyp, opt, device, callbacks) File "F:\CNN\deep-learning-for-image-processing-master\pytorch_object_detection\yolov9\train_dual.py", line 118, in train model = Model(cfg, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device) # create File "F:\CNN\deep-learning-for-image-processing-master\pytorch_object_detection\yolov9\models\yolo.py", line 568, in init m.stride = torch.tensor([s / x.shape[-2] for x in forward(torch.zeros(1, ch, s, s))]) # forward File "F:\CNN\deep-learning-for-image-processing-master\pytorch_object_detection\yolov9\models\yolo.py", line 567, in forward = lambda x: self.forward(x)[0] File "F:\CNN\deep-learning-for-image-processing-master\pytorch_object_detection\yolov9\models\yolo.py", line 582, in forward return self._forward_once(x, profile, visualize) # single-scale inference, train File "F:\CNN\deep-learning-for-image-processing-master\pytorch_object_detection\yolov9\models\yolo.py", line 481, in _forward_once x = m(x) # run File "D:\MiniConda\envs\yolov5\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "F:\CNN\deep-learning-for-image-processing-master\pytorch_object_detection\yolov9\models\common.py", line 649, in forward out = torch.sum(torch.stack(res + xs[-1:]), dim=0) RuntimeError: stack expects each tensor to be equal size, but got [1, 256, 32, 32] at entry 0 and [1, 192, 32, 32] at entry 3

1zxkapple commented 6 months ago

I'm also having the same issue.

Youho99 commented 6 months ago

@7W7W7W In your promp, you didn't use weights? Try using the weights given in the ReadMe (--cfg models/detect/yolov9-c.yaml --weights path/to/yolov9-e.pt)

Youho99 commented 6 months ago

@1zxkapple

I'm also having the same issue.

Use train_dual.py instead of tran.py for yolov9 models Check #1 for more informations

If the message above didn't help you, what is your training prompt ?

7W7W7W commented 6 months ago

@7W7W7W In your promp, you didn't use weights? Try using the weights given in the ReadMe (--cfg models/detect/yolov9-c.yaml --weights path/to/yolov9-e.pt) Is weight necessary? I still made the same mistake after using weights (train_dual: weights=yolov9-c.pt, cfg=models/detect/yolov9-c.yaml, data=data\VisDrone.yaml, hyp=data\hyps\hyp.scratch-high.yaml, epochs=200, batch_size=4, imgsz=640, rect=False, resume=False, nosave=False, noval=False, noautoanchor=False, noplots=False, evolve=None, bucket=, cache=None, image_weights=False, device=0, multi_scale=False, single_cls=False, optimizer=SGD, sync_bn=False, workers=8, project=runs\train, name=exp, exist_ok=False, quad=False, cos_lr=False, flat_cos_lr=False, fixed_lr=False, label_smoothing=0.0, patience=100, freeze=[0], save_period=-1, seed=0, local_rank=-1, min_items=0, close_mosaic=0, entity=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest YOLOv5 v0.1-35-g9660d12 Python-3.8.17 torch-2.0.1+cu118 CUDA:0 (NVIDIA GeForce RTX 3060 Ti, 8192MiB))

HTwoOhwater commented 6 months ago

It seems that you have changed the yaml file of the model. I think that you should not modify the size of the model.

7W7W7W commented 6 months ago

It seems that you have changed the yaml file of the model. I think that you should not modify the size of the model.

Yes, that's the problem. I have modified 'depth_multiple and width_multiple' to compare with the YOLOv5S model. Thank you very much for the answer, and may I ask why it cannot be changed?

HTwoOhwater commented 6 months ago

It seems that you have changed the yaml file of the model. I think that you should not modify the size of the model.

Yes, that's the problem. I have modified 'depth_multiple and width_multiple' to compare with the YOLOv5S model. Thank you very much for the answer, and may I ask why it cannot be changed?

You can scan this issue. The author haven't added the function of model size adjustment. https://github.com/WongKinYiu/yolov9/issues/155#issue-2166667817

7W7W7W commented 6 months ago

It seems that you have changed the yaml file of the model. I think that you should not modify the size of the model.

Yes, that's the problem. I have modified 'depth_multiple and width_multiple' to compare with the YOLOv5S model. Thank you very much for the answer, and may I ask why it cannot be changed?

You can scan this issue. The author haven't added the function of model size adjustment. #155 (comment)

Okay, thank you again

HTwoOhwater commented 6 months ago

@WongKinYiu I think that this issue can be closed.