AmigoLab / nmpevqvae

Neuromorphologicaly Preserving Volumetric Data Encoding Using VQ-VAE
https://arxiv.org/abs/2002.05692
MIT License
4 stars 0 forks source link

Tensor size error when running network.py #13

Closed tommybotch closed 1 year ago

tommybotch commented 1 year ago

Hello! Thank you for sharing your code. I am attempting to run the code with some of my own data, where the images are size (1,91,109,91).

I experience the following error when attempting to train:

Current run is terminating due to exception: Sizes of tensors must match except in dimension 1. Expected size 6 but got size 8 for tensor number 1 in the list.
Engine run is terminating due to exception: Sizes of tensors must match except in dimension 1. Expected size 6 but got size 8 for tensor number 1 in the list.
Traceback (most recent call last):
  File "/Users/thomasbotch/mri_vqvae/code/mri_vqvae/experiment.py", line 238, in <module>
    e = engine.run(data=data_loader, max_epochs=args.epochs if args.mode == utils.TRAINING else 1)
  File "/Users/thomasbotch/conda/envs/mri_vqvae/lib/python3.6/site-packages/ignite/engine/engine.py", line 704, in run
    return self._internal_run()
  File "/Users/thomasbotch/conda/envs/mri_vqvae/lib/python3.6/site-packages/ignite/engine/engine.py", line 783, in _internal_run
    self._handle_exception(e)
  File "/Users/thomasbotch/conda/envs/mri_vqvae/lib/python3.6/site-packages/ignite/engine/engine.py", line 466, in _handle_exception
    raise e
  File "/Users/thomasbotch/conda/envs/mri_vqvae/lib/python3.6/site-packages/ignite/engine/engine.py", line 753, in _internal_run
    time_taken = self._run_once_on_dataset()
  File "/Users/thomasbotch/conda/envs/mri_vqvae/lib/python3.6/site-packages/ignite/engine/engine.py", line 854, in _run_once_on_dataset
    self._handle_exception(e)
  File "/Users/thomasbotch/conda/envs/mri_vqvae/lib/python3.6/site-packages/ignite/engine/engine.py", line 466, in _handle_exception
    raise e
  File "/Users/thomasbotch/conda/envs/mri_vqvae/lib/python3.6/site-packages/ignite/engine/engine.py", line 840, in _run_once_on_dataset
    self.state.output = self._process_function(self, self.state.batch)
  File "/Users/thomasbotch/mri_vqvae/experiment.py", line 33, in process_function
    output = model(input)
  File "/Users/thomasbotch/conda/envs/mri_vqvae/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/Users/thomasbotch/mri_vqvae/network.py", line 20, in forward
    q6, q4, q2, qar = self.quantization(e6, e4, e2)
  File "/Users/thomasbotch/conda/envs/mri_vqvae/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/Users/thomasbotch/mri_vqvae/network.py", line 210, in forward
    q4l, q4, q4p, q4eo, q4ei = self.q4(self.q4b(torch.cat((e4, q6u), 1)))
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 6 but got size 8 for tensor number 1 in the list.

Could you please suggest how to fix this error? Thank you!

tommybotch commented 1 year ago

Sorry, this was due to the size of my input.

danieltudosiu commented 1 year ago

Hi @tlasmanbotch

Thank you for your interest in our work.

If you want to see a more up-to-date piece of work from our lab please check our VQ-VAE + Transformer pipeline codebase that was published at MICCAI 2022.

More details can be found in our publication:

Tudosiu, P.D., Pinaya, W.H.L., Graham, M.S., Borges, P., Fernandez, V., Yang, D., Appleyard, J., Novati, G., Mehra, D., Vella, M. and Nachev, P., 2022. Morphology-Preserving Autoregressive 3D Generative Modelling of the Brain. In International Workshop on Simulation and Synthesis in Medical Imaging (pp. 66-78). Springer, Cham.