I implemented a 3D CNN
in Keras with TensorFlow before which worked really fine. Now to speed up the training on multiple GPU's, I wanted to try MXNet
with Keras
. I expected that I didn't have to change a lot of the code apart from the "channels_last
" to "channels_first" issue, but the program crashes at a Conv3D operation.
The keras.json file is, so it should be set up to run fine:
{
"backend": "mxnet",
"image_data_format": "channels_first",
"epsilon": 1e-07,
"floatx": "float32"
}
This is a small part which shows the error:
from keras.models import *
from keras.layers import *
from keras.optimizers import *
def SimpleInceptionBlock(input, num_kernels, kernel_init='he_normal', padding='same', bn_axis=1):
tower1 = Conv3D(num_kernels, 1, padding=padding, kernel_initializer=kernel_init)(input)
tower1 = BatchNormalization()(tower1)
tower1 = ELU()(tower1)
tower2 = MaxPooling3D(pool_size=(2, 2, 2), strides=(1, 1, 1), padding=padding)(input)
tower2 = Conv3D(num_kernels, 1, padding=padding, kernel_initializer=kernel_init)(tower2)
tower2 = BatchNormalization()(tower2)
tower2 = ELU()(tower2)
output = concatenate([tower1, tower2], axis=bn_axis)
return output
def TestNet(input_size=(1,64,64,64), num_class=7):
bn_axis = 1
img_input = Input(shape=input_size)
filter1 = SimpleInceptionBlock(img_input, 16)
# this runs fine, filter1.shape = (None, 32, 64, 64, 64)
filter2 = SimpleInceptionBlock(filter1, 16)
output = Conv3D(num_class, (1, 1, 1), activation='softmax', kernel_initializer = kernel_init, padding='same', kernel_regularizer=l2(1e-4))(filter2)
model = Model(input=img_input, output=output)
return model
model = TestNet()
The first call of "SimpleInceptionBlock
" runs fine, with filter1.shape = (None, 32, 64, 64)
as expected, but the second call yields the error message:
Error in operator concat0: [15:40:58] C:\Jenkins\workspace\mxnet-tag\mxnet\src\operator\nn\concat.cc:66: Check failed: shape_assign(&(*in_shape)[i], dshape) Incompatible input shape: expected [0,0,64,64,64], got [0,16,64,65,65]