Open chzaryab opened 12 months ago
Hi @chzaryab, I found it running well on the cityscapes dataset. Did you change any code? And then can you provide your config file? can't locate the problem from the error message you provided.
so i am working on my own data data is loaded without any error but it is giving 4d error this is what i am getting when i start the training is their any shape issue in the model batch when going into training
config.json so this is the config please help me with this issue
Thanks for your error report and we appreciate it a lot.
Checklist
Describe the bug i have images data and also have the mask of it and if i train pspnet on that data model start training on it but mask2former is giving me shape error
ValueError Traceback (most recent call last) Cell In[17], line 2 1 # start training ----> 2 runner.train()
File /media/test/New Volume/mask2former_env2/lib/python3.9/site-packages/mmengine/runner/runner.py:1745, in Runner.train(self) 1741 # Maybe compile the model according to options in self.cfg.compile 1742 # This must be called AFTER model has been wrapped. 1743 self._maybe_compile('train_step') -> 1745 model = self.train_loop.run() # type: ignore 1746 self.call_hook('after_run') 1747 return model
File /media/test/New Volume/mask2former_env2/lib/python3.9/site-packages/mmengine/runner/loops.py:278, in IterBasedTrainLoop.run(self) 275 self.runner.model.train() 277 data_batch = next(self.dataloader_iterator) --> 278 self.run_iter(data_batch) 280 self._decide_current_val_interval() 281 if (self.runner.val_loop is not None 282 and self._iter >= self.val_begin 283 and self._iter % self.val_interval == 0):
File /media/test/New Volume/mask2former_env2/lib/python3.9/site-packages/mmengine/runner/loops.py:301, in IterBasedTrainLoop.run_iter(self, data_batch) 296 self.runner.call_hook( 297 'before_train_iter', batch_idx=self._iter, data_batch=data_batch) 298 # Enable gradient accumulation mode and avoid unnecessary gradient 299 # synchronization during gradient accumulation process. 300 # outputs should be a dict of loss. --> 301 outputs = self.runner.model.train_step( 302 data_batch, optim_wrapper=self.runner.optim_wrapper) 304 self.runner.call_hook( 305 'after_train_iter', 306 batch_idx=self._iter, 307 data_batch=data_batch, 308 outputs=outputs) 309 self._iter += 1
File /media/test/New Volume/mask2former_env2/lib/python3.9/site-packages/mmengine/model/base_model/base_model.py:114, in BaseModel.train_step(self, data, optim_wrapper) 112 with optim_wrapper.optim_context(self): 113 data = self.data_preprocessor(data, True) --> 114 losses = self._run_forward(data, mode='loss') # type: ignore 115 parsed_losses, log_vars = self.parse_losses(losses) # type: ignore 116 optim_wrapper.update_params(parsed_losses)
File /media/test/New Volume/mask2former_env2/lib/python3.9/site-packages/mmengine/model/base_model/base_model.py:340, in BaseModel._run_forward(self, data, mode) 330 """Unpacks data for :meth:
forward
331 332 Args: (...) 337 dict or list: Results of training or testing mode. 338 """ 339 if isinstance(data, dict): --> 340 results = self(*data, mode=mode) 341 elif isinstance(data, (list, tuple)): 342 results = self(data, mode=mode)File /media/test/New Volume/mask2former_env2/lib/python3.9/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, *kwargs) 1496 # If we don't have any hooks, we want to skip the rest of the logic in 1497 # this function, and just call forward. 1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks 1499 or _global_backward_pre_hooks or _global_backward_hooks 1500 or _global_forward_hooks or _global_forward_pre_hooks): -> 1501 return forward_call(args, **kwargs) 1502 # Do not call functions when jit is used 1503 full_backward_hooks, non_full_backward_hooks = [], []
File /media/test/New Volume/mmsegmentation1.0/mmsegmentation/mmseg/models/segmentors/base.py:94, in BaseSegmentor.forward(self, inputs, data_samples, mode) 64 """The unified entry for a forward process in both training and test. 65 66 The method should accept three modes: "tensor", "predict" and "loss": (...) 91 - If
mode="loss"
, return a dict of tensor. 92 """ 93 if mode == 'loss': ---> 94 return self.loss(inputs, data_samples) 95 elif mode == 'predict': 96 return self.predict(inputs, data_samples)File /media/test/New Volume/mmsegmentation1.0/mmsegmentation/mmseg/models/segmentors/encoder_decoder.py:174, in EncoderDecoder.loss(self, inputs, data_samples) 161 def loss(self, inputs: Tensor, data_samples: SampleList) -> dict: 162 """Calculate losses from a batch of inputs and data samples. 163 164 Args: (...) 171 dict[str, Tensor]: a dictionary of loss components 172 """ --> 174 x = self.extract_feat(inputs) 176 losses = dict() 178 loss_decode = self._decode_head_forward_train(x, data_samples)
File /media/test/New Volume/mmsegmentation1.0/mmsegmentation/mmseg/models/segmentors/encoder_decoder.py:119, in EncoderDecoder.extract_feat(self, inputs) 117 def extract_feat(self, inputs: Tensor) -> List[Tensor]: 118 """Extract features from images.""" --> 119 x = self.backbone(inputs) 120 if self.with_neck: 121 x = self.neck(x)
File /media/test/New Volume/mask2former_env2/lib/python3.9/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, *kwargs) 1496 # If we don't have any hooks, we want to skip the rest of the logic in 1497 # this function, and just call forward. 1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks 1499 or _global_backward_pre_hooks or _global_backward_hooks 1500 or _global_forward_hooks or _global_forward_pre_hooks): -> 1501 return forward_call(args, **kwargs) 1502 # Do not call functions when jit is used 1503 full_backward_hooks, non_full_backward_hooks = [], []
File /media/test/New Volume/mmsegmentation1.0/mmsegmentation/mmseg/models/backbones/swin.py:740, in SwinTransformer.forward(self, x) 739 def forward(self, x): --> 740 x, hw_shape = self.patch_embed(x) 742 if self.use_abs_pos_embed: 743 x = x + self.absolute_pos_embed
File /media/test/New Volume/mask2former_env2/lib/python3.9/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, *kwargs) 1496 # If we don't have any hooks, we want to skip the rest of the logic in 1497 # this function, and just call forward. 1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks 1499 or _global_backward_pre_hooks or _global_backward_hooks 1500 or _global_forward_hooks or _global_forward_pre_hooks): -> 1501 return forward_call(args, **kwargs) 1502 # Do not call functions when jit is used 1503 full_backward_hooks, non_full_backward_hooks = [], []
File /media/test/New Volume/mmsegmentation1.0/mmsegmentation/mmseg/models/utils/embed.py:203, in PatchEmbed.forward(self, x) 201 x = x.flatten(2).transpose(1, 2) 202 if self.norm is not None: --> 203 x = self.norm(x) 204 return x, out_size
File /media/test/New Volume/mask2former_env2/lib/python3.9/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, *kwargs) 1496 # If we don't have any hooks, we want to skip the rest of the logic in 1497 # this function, and just call forward. 1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks 1499 or _global_backward_pre_hooks or _global_backward_hooks 1500 or _global_forward_hooks or _global_forward_pre_hooks): -> 1501 return forward_call(args, **kwargs) 1502 # Do not call functions when jit is used 1503 full_backward_hooks, non_full_backward_hooks = [], []
File /media/test/New Volume/mask2former_env2/lib/python3.9/site-packages/torch/nn/modules/batchnorm.py:138, in _BatchNorm.forward(self, input) 137 def forward(self, input: Tensor) -> Tensor: --> 138 self._check_input_dim(input) 140 # exponential_average_factor is set to self.momentum 141 # (when it is available) only so that it gets updated 142 # in ONNX graph when this node is exported to ONNX. 143 if self.momentum is None:
File /media/test/New Volume/mask2former_env2/lib/python3.9/site-packages/torch/nn/modules/batchnorm.py:411, in BatchNorm2d._check_input_dim(self, input) 409 print(input.shape) 410 if input.dim() != 4: --> 411 raise ValueError("expected 4D input (got {}D input)".format(input.dim()))
ValueError: expected 4D input (got 3D input)
Reproduction
What command or script did you run?
Did you make any modifications on the code or config? Did you understand what you have modified?
What dataset did you use?
Environment
python mmseg/utils/collect_env.py
to collect necessary environment information and paste it here.$PATH
,$LD_LIBRARY_PATH
,$PYTHONPATH
, etc.)Error traceback
If applicable, paste the error trackback here.
Bug fix
If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!