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

"-1" dimension breaks if no bbox in crop or image #50

Open
londumas opened this issue Mar 18, 2024 · 1 comment
Open

"-1" dimension breaks if no bbox in crop or image #50

londumas opened this issue Mar 18, 2024 · 1 comment

Comments

@londumas
Copy link

In other type of dataset than COCO, having no bbox in a crop is likely. The "-1" dim in a reshape is imposible then.

Change this:

pred_roi_mask = mask_h.reshape(N, -1, 1) * mask_w.reshape(N, 1, -1)

to this:

pred_roi_mask = mask_h.reshape(N, mask_h.shape[-1], 1) * mask_w.reshape(N, 1, mask_w.shape[-1])

Same there:
gt_roi_mask = mask_h.reshape(N, mask_h.shape[-1], 1) * mask_w.reshape(N, 1, mask_w.shape[-1])

and there:
mask_logits = mask_logits.view(bs, np.prod(mask_logits.shape[1:])) / self.temperature # N x K2

The error is what follows:

RuntimeError: cannot reshape tensor of 0 elements into shape [0, -1, 1] because the unspecified dimension size -1 can be any value and is ambiguous
@liniceyo
Copy link

liniceyo commented Nov 6, 2024

Hello, I encountered a similar issue while performing inference on a custom dataset. Do you have any solutions to resolve this? Thank you very much for your response!

File "/home/com/anaconda3/envs/devit/lib/python3.9/site-packages/torch/multiprocessing/spawn.py", line 69, in _wrap
fn(i, *args)
File "/media/A/code/lyl/devit-main/tools/../detectron2/engine/launch.py", line 125, in _distributed_worker
main_func(*args)
File "/media/A/code/lyl/devit-main/tools/train_net.py", line 201, in main
return trainer.train()
File "/media/A/code/lyl/devit-main/tools/../detectron2/engine/defaults.py", line 496, in train
super().train(self.start_iter, self.max_iter)
File "/media/A/code/lyl/devit-main/tools/../detectron2/engine/train_loop.py", line 150, in train
self.after_step()
File "/media/A/code/lyl/devit-main/tools/../detectron2/engine/train_loop.py", line 180, in after_step
h.after_step()
File "/media/A/code/lyl/devit-main/tools/../detectron2/engine/hooks.py", line 386, in after_step
self._do_eval()
File "/media/A/code/lyl/devit-main/tools/../detectron2/engine/hooks.py", line 359, in _do_eval
results = self._func()
File "/media/A/code/lyl/devit-main/tools/../detectron2/engine/defaults.py", line 465, in test_and_save_results
self._last_eval_results = self.test(self.cfg, self.model)
File "/media/A/code/lyl/devit-main/tools/../detectron2/engine/defaults.py", line 618, in test
results_i = inference_on_dataset(model, data_loader, evaluator)
File "/media/A/code/lyl/devit-main/tools/../detectron2/evaluation/evaluator.py", line 159, in inference_on_dataset
outputs = model(inputs)
File "/home/com/anaconda3/envs/devit/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "/home/com/anaconda3/envs/devit/lib/python3.9/site-packages/torch/nn/parallel/distributed.py", line 1040, in forward
output = self._run_ddp_forward(*inputs, **kwargs)
File "/home/com/anaconda3/envs/devit/lib/python3.9/site-packages/torch/nn/parallel/distributed.py", line 1000, in _run_ddp_forward
return module_to_run(*inputs[0], **kwargs[0])
File "/home/com/anaconda3/envs/devit/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "/media/A/code/lyl/devit-main/tools/../detectron2/modeling/meta_arch/devit.py", line 1198, in forward
inter_dist_emb = other_classes.reshape(bs * num_active_classes, -1, self.roialign_size, self.roialign_size)
RuntimeError: cannot reshape tensor of 0 elements into shape [0, -1, 7, 7] because the unspecified dimension size -1 can be any value and is ambiguous

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

2 participants