keras: Slow BatchNormalization layers (CPU tested)

Hi,

I added BatchNormalization layers to my model and it suddenly took much more time to train.

It takes 561 seconds for one epoch with them: Epoch 1/1 4096/4096 [==============================] - 561s - loss: 0.0946 - acc: 0.9006

This is if I comment out the BatchNorm layers (186 seconds): Epoch 1/1 4096/4096 [==============================] - 186s - loss: 4.5043 - acc: 0.5933

I wrote on the user group and someone informed me that adding Dropout slows it down further, but even without Dropout this is much slower (above 500 seconds too).

Is it a CPU-related issue? Or is such a slowdown expected? Below is my model.

    model = Sequential()
    model.add(Convolution2D(32, 11, 11, subsample=(4,4),input_shape=(3,227,227)))
    model.add(PReLU())
    model.add(BatchNormalization())

    model.add(Convolution2D(64, 5, 5, subsample=(2,2)))
    model.add(PReLU())
    model.add(BatchNormalization())

    model.add(Convolution2D(64, 3, 3))
    model.add(PReLU())
    #model.add(BatchNormalization())
    model.add(MaxPooling2D((2,2), strides=(2,2)))

    model.add(Flatten())
    model.add(BatchNormalization())
    model.add(Dense(400))
    model.add(PReLU())
    model.add(BatchNormalization())
    model.add(Dropout(0.25))

    model.add(Dense(400))
    model.add(PReLU())
    model.add(BatchNormalization())
    model.add(Dropout(0.25))

    model.add(Dense(3, activation='softmax'))
    optimizer = keras.optimizers.RMSprop(lr=0.0005, rho=0.9, epsilon=1e-6)

    model.compile(loss='categorical_crossentropy',optimizer=optimizer)

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 5
  • Comments: 16 (10 by maintainers)

Most upvoted comments

I just observed almost a 10x slowdown when using batch normalization using GPUs. I am using the Theano backend, CUDA 8 RC and CuDNN. I am training a VGG-style CNN, on CIFAR-10, that is around 20 layers deep.

In Theano, we juste merged a wrapper of cuDNN batch norm that must be used manually:

http://deeplearning.net/software/theano_versions/dev/library/sandbox/cuda/dnn.html#batch-normalization

It speed up the compilation and execution time.

So if you or someone else modify keras to use it, it would be great.

On Thu, Jul 14, 2016 at 12:57 PM, iaroslav-ai notifications@github.com wrote:

+1 I observe same thing

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fchollet/keras/issues/1309#issuecomment-232726054, or mute the thread https://github.com/notifications/unsubscribe/AALC-3IwuQ6xSPdXSJRiNkyk6zBBgWoCks5qVmqBgaJpZM4G4bYz .