ELEKTRONN / elektronn3

A PyTorch-based library for working with 3D and 2D convolutional neural networks, with focus on semantic segmentation of volumetric biomedical image data
MIT License
161 stars 27 forks source link

Error with 3D convolution on custom Kernels #49

Closed Elmiar0642 closed 1 year ago

Elmiar0642 commented 1 year ago

I wanted to add my own 3D kernel on every layer. I tried using this,

` def conv3(in_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=True, planar=False, dim=3): """Returns an appropriate spatial convolution layer, depending on args.

`

But I got an error like this,

Testing 3D U-Net with n_blocks = 1, planar_blocks = ()... torch.Size([32, 1, 3, 3, 3]) torch.Size([32, 32, 3, 3, 3])

RuntimeError: Given weight of size [1, 1, 3, 3, 3], expected bias to be 1-dimensional with 1 elements, but got bias of size [32] instead

I kindly request you to Help me fix this!!!

@Optiligence @my-tien @xeray @mdraw @jmrk84

Elmiar0642 commented 1 year ago

With Random kernels and planar setting, I get output as

Testing 3D U-Net with n_blocks = 1, planar_blocks = ()...

torch.Size([32, 1, 3, 3, 3])

torch.Size([32, 32, 3, 3, 3])

Testing 3D U-Net with n_blocks = 1, planar_blocks = (0,)...

torch.Size([32, 1, 1, 3, 3])

torch.Size([32, 32, 1, 3, 3])

...

...

...

All tests sucessful!
mdraw commented 1 year ago

This issue is not really related to elektronn3. If I understand correctly you want to change the initialization of your weights. Note that the get_conv(dim) call here evaluates to torch.nn.Conv3d Please refer to the PyTorch docs and https://discuss.pytorch.org/ if you need help with changing weights of torch.nn.Conv3d modules.