Help with nd Convolution (3d in my case though)
Hi Guys,
I've finally perfected my test bed for cntk and everything is up and running fast now. So I'm looking at my actual problem which is basically training using brain MR images. Just so that we are on the same page, I'll detail the outlook of my MR images. The resolution in my case is 256_190 and there's 200 such slices. So if I'm to put it into an equivalent scenario with channels, it can be considered as a 256_190 image with 200 channels. However, in contrast to the typical image channels, MR images do not point to the same spatial region so using the images as channels doesn't seem accurate. So I'm thinking of using them in a 3d convolution scenario. Just wondering whether CNTK supports this?
Thanks a lot in advance.
Hello, Yes, CNTK supports ND convolution (that includes 2D and 3D), see more details here and in the samples (how to use ND convolution syntax). Note that convolution optimization/performance can be different when running on GPU vs CPU. On GPU, 1D, 2D and 3D convolutions will use cuDNN (fast), all other convos will use reference engine (slow). On CPU, most of common convolution configuration will use GEMM engine (fast), including 2D, 3D and others. The only exception is untied convos (sharing = false) and some other tricky configurations. See the CNTK output for details on which engine is selected for a particular node.
Hi Leo, are you actually talking about a 3D box of pixels, to which you want to apply 3D convolution?
However, in contrast to the typical image channels, MR images do not point to the same spatial region so using the images as channels doesn't seem accurate.
This seems to indicate that it is 200 independent images you want to process in parallel, but without any convolution in the direction of the 200.
Which one is it?
We recently removed an incorrect check in Convolution that prevented >3D convolutions.
Cf. Issue #726
I would like to consider it as a 3D box of pixels if possible Frank
thanks for the reference, that certainly helps! :)
Could you give it a whirl to see if it works? If you work off the latest master branch, you can also use ConvolutionalLayer{}, which makes it a little easier. E.g. a filter over a box 5 wide, 6 high, and 7 deep with 64 output channels would be:
h = ConvolutionalLayer {64, (5:6:7), activation=ReLU, init='heNormal'}
This assumes your data to be stored column-major with dimensions [256 x 190 x 200], where 256 is the fastest changing dimension. In raw 2D images, the fastest-changing dimension is often the width, scanning line by line; or color channel (pixels stored as R,G,B triples), with width then being the second-fastest-changing. The ImageReader uses the transpose transform to fix it up. Please beware of that.
(Please specify init='heNormal'. The default "gaussian" given in the Wiki page will change very soon, so for the next few days, don't rely on the default.)
CC @cha-zhang
Hi leoStark1, did it work using slices as channels? I'm analyzing MR Images too, and I've your doubt: "MR images do not point to the same spatial region so using the images as channels doesn't seem accurate." Thanks Francesco
@fcivardi I've used CNTK on 3D MR images the way Frank suggested. In my case this required writing my own reader, to be able to read 3D images of our internally used image format as a 4D tensor, where the 4th dimension is the number of channels and is usually 1 for the input layer and equal to the number of filters for subsequent layers.