thuml / Transfer-Learning-Library

Transfer Learning Library for Domain Adaptation, Task Adaptation, and Domain Generalization
http://transfer.thuml.ai
MIT License
3.39k stars 553 forks source link

作者您好,运行visualize.py时报错 #193

Closed niuyixing closed 1 year ago

niuyixing commented 1 year ago

latest.pth Traceback (most recent call last): File "D:/domain/Transfer-Learning-Library-master/examples/domain_adaptation/object_detection/visualize.py", line 142, in launch( File "d:\domain\detectron2-main\detectron2\engine\launch.py", line 82, in launch main_func(args) File "D:/domain/Transfer-Learning-Library-master/examples/domain_adaptation/object_detection/visualize.py", line 97, in main DetectionCheckpointer(model, save_dir=cfg.OUTPUT_DIR).resume_or_load( File "C:\Users\xingze\AppData\Roaming\Python\Python38\site-packages\fvcore\common\checkpoint.py", line 229, in resume_or_load return self.load(path, checkpointables=[]) File "d:\domain\detectron2-main\detectron2\checkpoint\detection_checkpoint.py", line 52, in load ret = super().load(path, args, **kwargs) File "C:\Users\xingze\AppData\Roaming\Python\Python38\site-packages\fvcore\common\checkpoint.py", line 158, in load incompatible = self._load_model(checkpoint) File "d:\domain\detectron2-main\detectron2\checkpoint\detection_checkpoint.py", line 96, in _load_model self._convert_ndarray_to_tensor(checkpoint["model"]) File "C:\Users\xingze\AppData\Roaming\Python\Python38\site-packages\fvcore\common\checkpoint.py", line 371, in _convert_ndarray_to_tensor raise ValueError( ValueError: Unsupported type found in checkpoint! netG_S2T: <class 'collections.OrderedDict'>

进程已结束,退出代码 1

报错位置:

model could be an OrderedDict with _metadata attribute

    # (as returned by Pytorch's state_dict()). We should preserve these
    # properties.
    for k in list(state_dict.keys()):
        v = state_dict[k]
        if not isinstance(v, np.ndarray) and not isinstance(v, torch.Tensor):
            raise ValueError(
                "Unsupported type found in checkpoint! {}: {}".format(k, type(v))
            )
        if not isinstance(v, torch.Tensor):
            state_dict[k] = torch.from_numpy(v)

还要问下如何将自己的数据、图片根据训练权重全部进行转化,生成所有每张原图像对应的结果图片

thucbx99 commented 1 year ago

根据上面的报错信息来看是使用detectron2读取模型参数时出现的bug,具体原因建议参考detectron2有关这一部分的文档。

使用自己的数据也是类似,detectron2默认提供了两种格式,即coco和pascal voc,其中pascal voc的实现可以参考库里的代码