Closed himadrivaidya closed 1 year ago
I got the same issues for a week or so, still trying to find the solution
I got the same issues for a week or so, still trying to find the solution
Have you fixed the problem, I have same problem :confused:
I got the same issues for a week or so, still trying to find the solution
Have you fixed the problem, I have same problem 😕
I realized that my dataset is suitable for detection instead of segmentation. So, I simply changed task from segment to detect, and the model from yolov8x-seg.pt to yolov8x.pt This worked for me, hope it helps
I got the same issues for a week or so, still trying to find the solution
Have you fixed the problem, I have same problem confused
I realized that my dataset is suitable for detection instead of segmentation. So, I simply changed task from segment to detect, and the model from yolov8x-seg.pt to yolov8x.pt This worked for me, hope it helps
with yolov8x.pt, program starts train.py from detect.
I got the same issues for a week or so, still trying to find the solution
Have you fixed the problem, I have same problem confused
I realized that my dataset is suitable for detection instead of segmentation. So, I simply changed task from segment to detect, and the model from yolov8x-seg.pt to yolov8x.pt This worked for me, hope it helps
with yolov8x.pt, program starts train.py from detect.
Have you fixed the problem? It works in detection, but I want to use it in segemntation...and I can't find out the question
@SheeppLi @himadrivaidya For training a segmentation model, please make sure your dataset labels are all segmentation labels.
This error RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 42 but got size 0 for tensor number 1 in the list.
happens which is because you are training segmentation model with detection labels.
related issue: https://github.com/ultralytics/ultralytics/issues/1091
@himadrivaidya closing this issue as there's a similar issue solved. feel free to reopen it if you still have any related issues. :)
Search before asking
Question
Fine-tune yolov8 classifier om custom dataset.
Execute the command: yolo task=segment mode=train data=data/landslide.yaml model=yolov8n-seg.pt epochs=100 imgsz=640
Error: RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 42 but got size 0 for tensor number 1 in the list.
Terminal Output: yolo task=segment mode=train data=data/landslide.yaml model=yolov8n-seg.pt epochs=100 imgsz=640 Ultralytics YOLOv8.0.6 🚀 Python-3.10.6 torch-1.11.0+cu113 CUDA:0 (NVIDIA GeForce RTX 3060 Laptop GPU, 5947MiB) yolo/engine/trainer: task=segment, mode=train, model=yolov8n-seg.pt, data=data/landslide.yaml, epochs=100, patience=50, batch=16, imgsz=640, save=True, cache=False, device=, 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, cfg=None, hydra={'output_subdir': None, 'run': {'dir': '.'}}, v5loader=False, save_dir=/home/himadri/dl_models/ultralytics/runs/segment/train30 Overriding model.yaml nc=80 with nc=1
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 1004275 ultralytics.nn.modules.Segment [1, 32, 64, [64, 128, 256]]
YOLOv8n-seg summary: 261 layers, 3263811 parameters, 3263795 gradients, 12.1 GFLOPs
Transferred 381/417 items from pretrained weights optimizer: SGD(lr=0.01) with parameter groups 66 weight(decay=0.0), 77 weight(decay=0.0005), 76 bias train: Scanning /home/himadri/dl_models/ultralytics/datasets/landslide/train/labels.cache... 654 images, 0 backgrounds, 0 corrupt: 100%|██████████| 654/654 [00:00<?, ?it/s] val: Scanning /home/himadri/dl_models/ultralytics/datasets/landslide/valid/labels.cache... 106 images, 0 backgrounds, 0 corrupt: 100%|██████████| 106/106 [00:00<?, ?it/s] Image sizes 640 train, 640 val Using 8 dataloader workers Logging results to /home/himadri/dl_models/ultralytics/runs/segment/train30 Starting training for 100 epochs...
0%| | 0/41 [00:01<?, ?it/s] Error executing job with overrides: ['task=segment', 'mode=train', 'data=data/landslide.yaml', 'model=yolov8n-seg.pt', 'epochs=100', 'imgsz=640'] Traceback (most recent call last): File "/home/himadri/venv/lib/python3.10/site-packages/ultralytics/yolo/cli.py", line 56, in cli func(cfg) File "/home/himadri/venv/lib/python3.10/site-packages/hydra/main.py", line 79, in decorated_main return task_function(cfg_passthrough) File "/home/himadri/venv/lib/python3.10/site-packages/ultralytics/yolo/v8/segment/train.py", line 153, in train model.train(**cfg) File "/home/himadri/venv/lib/python3.10/site-packages/ultralytics/yolo/engine/model.py", line 193, in train self.trainer.train() File "/home/himadri/venv/lib/python3.10/site-packages/ultralytics/yolo/engine/trainer.py", line 185, in train self._do_train(int(os.getenv("RANK", -1)), world_size) File "/home/himadri/venv/lib/python3.10/site-packages/ultralytics/yolo/engine/trainer.py", line 301, in _do_train self.loss, self.loss_items = self.criterion(preds, batch) File "/home/himadri/venv/lib/python3.10/site-packages/ultralytics/yolo/v8/segment/train.py", line 45, in criterion return self.compute_loss(preds, batch) File "/home/himadri/venv/lib/python3.10/site-packages/ultralytics/yolo/v8/segment/train.py", line 86, in call targets = torch.cat((batch_idx, batch["cls"].view(-1, 1), batch["bboxes"]), 1) RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 42 but got size 0 for tensor number 1 in the list.
Additional
While debugging the issue I find out that the size of the tensor the given statement """targets = torch.cat((batch_idx, batch["cls"].view(-1, 1), batch["bboxes"]), 1)""" is different.
'cls': tensor([], size=(0, 1)), 'bboxes': tensor([], size=(0, 4), dtype=torch.float64), 'batch_idx': tensor([ 0., 0., 0., 1., 1., 1., 1., 2., 2., 2., 2., 3., 4., 5., 6., 6., 6., 6., 7., 8., 8., 8., 9., 9., 10., 10., 10., 10., 11., 11., 11., 11., 12., 12., 13., 13., 14., 14., 15., 15., 15., 15.])
Any help to resolve the above issue????????...