YOLO-World icon indicating copy to clipboard operation
YOLO-World copied to clipboard

SyntaxError: cannot assign to None && missing batch_img_metas

Open YuLionel opened this issue 9 months ago • 14 comments

When I fine tuned, this error occurred: File "/xx/YOLO-World-master/yolo_world/models/detectors/init.py", line 2, in from .yolo_world import YOLOWorldDetector, SimpleYOLOWorldDetector File "/xx/YOLO-World-master/yolo_world/models/detectors/yolo_world.py", line 61 self.text_feats, None = self.backbone.forward_text(texts) ^ SyntaxError: cannot assign to None [2025-03-05 07:36:16,194] torch.distributed.elastic.multiprocessing.api: [ERROR] failed (exitcode: 1) local_rank: 0 (pid: 2265245) of binary: /data/users/xx/.conda/envs/yolo-world/bin/python

Change 'None' to '_' and then it appears:

File "/home/xx/workspace/YOLO-World-master/yolo_world/models/dense_heads/yolo_world_head.py", line 366, in loss losses = self.loss_by_feat(*loss_inputs) TypeError: loss_by_feat() missing 1 required positional argument: 'batch_img_metas'

How to solve it? Is it because there is a problem with the latest project code?

YuLionel avatar Mar 06 '25 08:03 YuLionel

I'm having the same problem.

llllllfy avatar Mar 07 '25 14:03 llllllfy

I'm having the same problem.

doilion avatar Mar 10 '25 08:03 doilion

Did you resolve the second issue?

qilvzhuihuojian avatar Mar 10 '25 08:03 qilvzhuihuojian

@qilvzhuihuojian If you manage to solve it, please let me know if possible.

doilion avatar Mar 10 '25 10:03 doilion

@doilion second question: yolo_world/models/dense_heads/yolo_world_head.py line:357 ` def loss(self, img_feats: Tuple[Tensor], txt_feats: Tensor, txt_masks: Tensor, batch_data_samples: Union[list, dict]) -> dict: """Perform forward propagation and loss calculation of the detection head on the features of the upstream network."""

    outs = self(img_feats, txt_feats, txt_masks)
    # Fast version
    loss_inputs = outs + (txt_masks,batch_data_samples['bboxes_labels'],
                          batch_data_samples['img_metas'])
    losses = self.loss_by_feat(*loss_inputs)

    return losses`

qilvzhuihuojian avatar Mar 10 '25 11:03 qilvzhuihuojian

@qilvzhuihuojian @llllllfy @YuLionel I asked Claude 3.7, and it also suggested that the issue might be related to this part, but I’m not entirely sure if it’s really the root cause. I reverted to a few earlier versions using git checkout 4826695, and the problem was resolved.

doilion avatar Mar 10 '25 11:03 doilion

@qilvzhuihuojian It works for me. Thank you for your sharing.

GuanRunwei avatar Mar 10 '25 11:03 GuanRunwei

@doilion @qilvzhuihuojian Thank you. Combine your sharing, it works for me.

Use python tools/train.py

  1. git checkout 4826695
  2. change yolo_world/models/dense_heads/yolo_world_head.py line:357
def loss(self, img_feats: Tuple[Tensor], txt_feats: Tensor,
            txt_masks: Tensor, batch_data_samples: Union[list, dict]) -> dict:
        """Perform forward propagation and loss calculation of the detection
        head on the features of the upstream network."""

        outs = self(img_feats, txt_feats, txt_masks)
        # Fast version
        loss_inputs = outs + (txt_masks,batch_data_samples['bboxes_labels'],
                            batch_data_samples['img_metas'])
        losses = self.loss_by_feat(*loss_inputs)
        return losses

However, it doesn't work when use tools/dist_train.sh

  File "YOLO-World/yolo_world/models/detectors/yolo_world.py", line 32, in loss
    losses = self.bbox_head.loss(img_feats, txt_feats, batch_data_samples)                
TypeError: loss() missing 1 required positional argument: 'batch_data_samples'  

M3Dade avatar Apr 08 '25 08:04 M3Dade

File "YOLO-World/yolo_world/models/detectors/yolo_world.py", line 32, in loss losses = self.bbox_head.loss(img_feats, txt_feats, batch_data_samples)
TypeError: loss() missing 1 required positional argument: 'batch_data_samples'

May I ask if this problem has been solved? I also encountered the same problem. @M3Dade

glory21 avatar May 08 '25 14:05 glory21

yolo_world/models/dense_heads/yolo_world_head.py line:357 def loss(self, img_feats: Tuple[Tensor], txt_feats: Tensor, txt_masks: Tensor, batch_data_samples: Union[list, dict]) -> dict: """Perform forward propagation and loss calculation of the detection head on the features of the upstream network.""" self.head_module.training = True ##add outs = self(img_feats, txt_feats, txt_masks) yolo_world/models/dense_heads/yolo_world_head.py line:401 def predict(self, img_feats: Tuple[Tensor], txt_feats: Tensor, txt_masks: Tensor, batch_data_samples: SampleList, rescale: bool = False) -> InstanceList: """Perform forward propagation of the detection head and predict detection results on the features of the upstream network. """ self.head_module.training = False ##add batch_img_metas = [ data_samples.metainfo for data_samples in batch_data_samples ]

gjygjy-a11 avatar Jul 02 '25 02:07 gjygjy-a11

Thanks a lot,it work. git checkout 4826695

connorye avatar Jul 25 '25 07:07 connorye

when use tools/dist_train.sh File "YOLO-World/yolo_world/models/detectors/yolo_world.py", line 166, in loss losses = self.bbox_head.loss(img_feats, txt_feats, batch_data_samples)
TypeError: loss() missing 1 required positional argument: 'batch_data_samples' @M3Dade @connorye @GuanRunwei How to modify the code specifically,

Thank you very much

sqh85 avatar Jul 31 '25 11:07 sqh85

@sqh85
https://github.com/AILab-CVC/YOLO-World/commit/4826695a84ce370dad7fe4cb555a6c7162f3751d dowanload and use the provided version

connorye avatar Jul 31 '25 12:07 connorye

dowanload and use the provided version 4826695, when use tools/dist_train.sh。 data['category_id'] = self.cat_ids[label] IndexError:list index out of range ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode:1) local_rank:0 (pid:23980) of binary: /home....../python @M3Dade @connorye @GuanRunwei Thank you very much

sqh85 avatar Aug 04 '25 03:08 sqh85