yolov7
yolov7 copied to clipboard
How to train custom 'yolov7-mask.pt' ?
From the "instance.ipynb" file, i found out that 'yolov7-mask.pt' is different from regular .pt weight file, may I know how to train a custom one for my own school work? Tq
Use train.py in the mask branch. Pro tip: you can still transfer learn from yolov7-mask.pt
I may have lied to you... There is a u7 branch which is for development. It does have training code for segmentation.
I just tried running the train.py in the mask branch and the code does not appear to have sense for some reason:
Traceback (most recent call last):
File "/home/mscherbina/Documents/github_repos/yolov7/train.py", line 363, in train
loss, loss_items = compute_loss_ota(pred, targets.to(device), imgs) # loss scaled by batch_size
File "/home/mscherbina/Documents/github_repos/yolov7/utils/loss.py", line 585, in __call__
bs, as_, gjs, gis, targets, anchors = self.build_targets(p, targets, imgs)
File "/home/mscherbina/Documents/github_repos/yolov7/utils/loss.py", line 641, in build_targets
indices, anch = self.find_3_positive(p, targets)
File "/home/mscherbina/Documents/github_repos/yolov7/utils/loss.py", line 813, in find_3_positive
gain[2:6] = torch.tensor(p[i].shape)[[3, 2, 3, 2]] # xyxy gain
KeyError: 0
p is <class 'dict'> with keys ['mask_iou', 'attn', 'bbox_and_cls', 'bases', 'sem'] Whereas the function expects a tensor
The training code for mask branch has not been released yet because of detectron2 dependecies but you can train your custom dataset for instance segmentation in the u7 branch.
I may have lied to you... There is a u7 branch which is for development. It does have training code for segmentation.
I just tried running the train.py in the mask branch and the code does not appear to have sense for some reason:
Traceback (most recent call last): File "/home/mscherbina/Documents/github_repos/yolov7/train.py", line 363, in train loss, loss_items = compute_loss_ota(pred, targets.to(device), imgs) # loss scaled by batch_size File "/home/mscherbina/Documents/github_repos/yolov7/utils/loss.py", line 585, in __call__ bs, as_, gjs, gis, targets, anchors = self.build_targets(p, targets, imgs) File "/home/mscherbina/Documents/github_repos/yolov7/utils/loss.py", line 641, in build_targets indices, anch = self.find_3_positive(p, targets) File "/home/mscherbina/Documents/github_repos/yolov7/utils/loss.py", line 813, in find_3_positive gain[2:6] = torch.tensor(p[i].shape)[[3, 2, 3, 2]] # xyxy gain KeyError: 0p is <class 'dict'> with keys ['mask_iou', 'attn', 'bbox_and_cls', 'bases', 'sem'] Whereas the function expects a tensor
I see...... maybe it is due to detectron2 dependencies. Btw, thank for your reply.
The training code for mask branch has not been released yet because of detectron2 dependecies but you can train your custom dataset for instance segmentation in the u7 branch.
Yep. But I found out the "mask" one gave slightly better segmentation than the "u7". Thx for your reply.
I also ran into this issue when training on the mask branch:
...
File "/media/cat/oadams/yolov7/train.py", line 363, in train
loss, loss_items = compute_loss_ota(pred, targets.to(device), imgs) # loss scaled by batch_size
File "/media/cat/oadams/yolov7/utils/loss.py", line 585, in __call__
bs, as_, gjs, gis, targets, anchors = self.build_targets(p, targets, imgs)
File "/media/cat/oadams/yolov7/utils/loss.py", line 641, in build_targets
indices, anch = self.find_3_positive(p, targets)
File "/media/cat/oadams/yolov7/utils/loss.py", line 811, in find_3_positive
gain[2:6] = torch.tensor(p[i].shape)[[3, 2, 3, 2]] # xyxy gain
KeyError: 0
Does anyone know how to resolve this or is it still not ready yet?
I've trained on the u7 branch before which seems to require training from scratch (no pretrained weights available there?) but was hoping to try the mask branch since there are the yolov7-mask.pt pre-trained weights.
@oadams have you resolveed it?
up, i have the same problem over here
If this issue was resolved, can anyone give the solution please?
Hi Have you resolved this issue?
Hi. Has anyone solved this issue?