Comments (5)
After your chain of transforms,
Is the data has same dimension?
Seeing from your code your first image is [44, 55, 83], is the second image the same size as this?
Like in the original spleen example, we use
RandCropByPosNegLabeld(
keys=["image", "label"],
label_key="label",
spatial_size=(96, 96, 96),
pos=1,
neg=1,
num_samples=4,
image_key="image",
image_threshold=0,
),
This ensures that the data passed in will be in batches of [96, 96, 96] cubes.
from tutorials.
Thank you! That was the problem. Adding DivisiblePadd
with k=32
solves it.
from tutorials.
The images have the same dimensions after the transforms. Updated notebook is here. Adding
inputs, labels = (
batch_data["image"].to(device),
batch_data["label"].to(device),
)
print(f"batch_data image: {batch_data['image'].shape}")
print(f"batch_data label: {batch_data['label'].shape}")
produces the output:
----------
epoch 1/10
batch_data image: torch.Size([20, 1, 44, 55, 83])
batch_data label: torch.Size([20, 1, 44, 55, 83])
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-12-e43444a90bc8> in <module>
22
23 optimizer.zero_grad()
---> 24 outputs = model(inputs)
25 loss = loss_function(outputs, labels)
26 loss.backward()
c:\dev\monai\pyenv\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)
c:\dev\monai\pyenv\lib\site-packages\monai\networks\nets\unet.py in forward(self, x)
190
191 def forward(self, x: torch.Tensor) -> torch.Tensor:
--> 192 x = self.model(x)
193 return x
194
c:\dev\monai\pyenv\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)
c:\dev\monai\pyenv\lib\site-packages\torch\nn\modules\container.py in forward(self, input)
98 def forward(self, input):
99 for module in self:
--> 100 input = module(input)
101 return input
102
c:\dev\monai\pyenv\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)
c:\dev\monai\pyenv\lib\site-packages\monai\networks\layers\simplelayers.py in forward(self, x)
37
38 def forward(self, x: torch.Tensor) -> torch.Tensor:
---> 39 return torch.cat([x, self.submodule(x)], self.cat_dim)
40
41
c:\dev\monai\pyenv\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)
c:\dev\monai\pyenv\lib\site-packages\torch\nn\modules\container.py in forward(self, input)
98 def forward(self, input):
99 for module in self:
--> 100 input = module(input)
101 return input
102
c:\dev\monai\pyenv\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)
c:\dev\monai\pyenv\lib\site-packages\monai\networks\layers\simplelayers.py in forward(self, x)
37
38 def forward(self, x: torch.Tensor) -> torch.Tensor:
---> 39 return torch.cat([x, self.submodule(x)], self.cat_dim)
40
41
c:\dev\monai\pyenv\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)
c:\dev\monai\pyenv\lib\site-packages\torch\nn\modules\container.py in forward(self, input)
98 def forward(self, input):
99 for module in self:
--> 100 input = module(input)
101 return input
102
c:\dev\monai\pyenv\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
530 result = self._slow_forward(*input, **kwargs)
531 else:
--> 532 result = self.forward(*input, **kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)
c:\dev\monai\pyenv\lib\site-packages\monai\networks\layers\simplelayers.py in forward(self, x)
37
38 def forward(self, x: torch.Tensor) -> torch.Tensor:
---> 39 return torch.cat([x, self.submodule(x)], self.cat_dim)
40
41
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 7 and 8 in dimension 3 at C:\w\1\s\windows\pytorch\aten\src\TH/generic/THTensor.cpp:612
from tutorials.
Hi
The problem is the data shape changed after down-sample then up-sample.
You can take a look at the answer here: https://stackoverflow.com/questions/60063797/not-understanding-the-data-flow-in-unet-like-architetures-and-having-problems-wi
and here: http://makeyourownneuralnetwork.blogspot.com/2020/02/calculating-output-size-of-convolutions.html
So you will need to do some calculations and get a valid shape
Then either pad or rescale to that shape should solve this problem
from tutorials.
Thank you! That was the problem. Adding
DivisiblePadd
withk=32
solves it.
I meet same error, can you show detail in code?
from tutorials.
Related Issues (20)
- The monai-generative in requirements-dev.txt points to a deleted branch.
- Maisi debug HOT 1
- can't run on large datasets HOT 2
- Issue in maisi_train_vae_tutorial HOT 2
- Index embedding of MAISI HOT 2
- Port Existing Generative Tutorials HOT 10
- realism_diversity_metrics
- Refactor MAISI Network with New Generative AI Components HOT 1
- Using auto3dseg for Multichannel Inputs HOT 3
- change maisi notebook display function
- Auto3dseg swinunetr Pretrained weight download link not working
- image_to_image_translation
- distributed_training HOT 1
- ModuleNotFoundError: No module named 'monai.transforms.morphological_ops' HOT 1
- AverageMeter and Metric Reduction Clarification HOT 1
- Question about MAISI data preprocessing HOT 5
- Tutorial gradCAM 3D seems to have inverted heatmap HOT 1
- Invaild data link for IXI Dataset HOT 2
- Add tutorial for VISTA2D+CellProfiler
- `runner.sh` Parses Some Files Incorrectly HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tutorials.