microsoft / CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit
https://docs.microsoft.com/cognitive-toolkit/
Other
17.49k stars 4.3k forks source link

CNTK fail to build `BatchNormalization` in some case. #3798

Open shiningrain opened 4 years ago

shiningrain commented 4 years ago

System information

Have I written custom code (as opposed to using example directory): OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 &&Linux Ubuntu 18.04 CNTK backend (yes/no): yes CNTK version: 2.7(CPU) Python version: 3.6.9 CUDA/cuDNN version: - GPU model and memory: -

Describe the current behavior When I tried to build Batchnormalization on CNTK, it returned an error in cntk\ops\__init__.py line 3911, related codes are shown in the following picture. For detailed parameters of Batchnormalization, you can refer to the following code snippet ValueError: AssignNode: None of the operands 'Parameter('batch_normalization_1/moving_mean', [], [1]), Output('Plus275_Output_0', [#], [1])' can have dynamic axes. 1-1

The key of this problem is that one of batch_normalization_1 and Plus275_Output_0 has a dynamic axis, which causes the CNTK operation to fail. These two variable was shown in the following pictures. 1-2 1-3

But I didn't find any warning or description about the specific parameters leading to this kind of problem in the documents. I wonder what had happened in the cntk calculation process. In addition, this unexpected problem may confuse CNTK users. Code to reproduce the issue

import numpy as np
import keras.layers as L
from keras.engine import Model, Input

## Using CNTK as Keras backend.
## Input dtype default is float32

layer = 'BatchNormalization'
kwargs = {'axis': 0, 'epsilon': 0.013340624169680626, 'center': True, 'scale': False}
input = (10 * np.random.random((1,32,32,16)))
layer_cls = getattr(L, layer)
layer = layer_cls(**kwargs)
x = Input(batch_shape=input.shape)
y = layer(x)
bk_model =Model(x, y)
print('finish')
delzac commented 4 years ago

What's your custom batchnorm code? Or are you using the batchnorm provided by cntk. I never had any issues with batchnorm.