keyu-tian / SparK

[ICLR'23 Spotlight🔥] The first successful BERT/MAE-style pretraining on any convolutional network; Pytorch impl. of "Designing BERT for Convolutional Networks: Sparse and Hierarchical Masked Modeling"
https://arxiv.org/abs/2301.03580
MIT License
1.41k stars 82 forks source link

infer问题 #62

Closed Shlre closed 9 months ago

Shlre commented 9 months ago

你好,请问 import torch from mmpretrain import inference_model from mmpretrain import get_model image ='path' checkpoint = 'epoch_800.pth' config = 'spark_sparse-resnet50_8xb64-amp-coslr-800e_in1k.py' model = get_model('spark_sparse-resnet50_8xb64-amp-coslr-800e_in1k.py',pretrained=checkpoint) input = torch.randn(1,3,224,224) output = model(input) 报错 File "/home/xxx/mmpretrain/mmpretrain/models/utils/sparse_modules.py", line 34, in sp_conv_forward x *= SparseHelper._get_active_map_or_index( File "/home/xxx/mmpretrain/mmpretrain/models/utils/sparse_modules.py", line 22, in _get_active_map_or_index downsample_raito = H // SparseHelper._cur_active.shape[-1] AttributeError: 'NoneType' object has no attribute 'shape' Process finished with exit code 1 怎么解决么,万分感谢

Shlre commented 9 months ago

我使用mmpretrain进行预训练,在训练时在spark.py文件中loss函数中遇到报错,在122行activate_mask_feature_map = self.mask(input.shape , inputs.device),读取input.shape时会报错没有shape,debug发现inputs是一个list,因此我在其上添加inputs = torch.cat(inputs,dim=0)后可以正常进行训练,或许这个是问题所在

keyu-tian commented 9 months ago

@Shlre 非常感谢,我觉得这可能是mmpretrain的一个bug,您可以前往 https://github.com/open-mmlab/mmpretrain 为他们提一个 issue 或 pull request,谢谢

Shlre commented 9 months ago

好的,谢谢您的回复