from keras_contrib.layers.normalization import InstanceNormalization 报错 ImportError: cannot impor...

在运行3D-UNet 代码的时候,使用 python train_isensee2017.py  之后报错 

Traceback (most recent call last):

  File "/workspace/3D-UNet_plus/brats/unet3d/model/unet.py", line 103, in create_convolution_block

    from keras_contrib.layers.normalization import InstanceNormalization

ImportError: cannot import name 'InstanceNormalization'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "train_isensee2017.py", line 117, in

    main(overwrite=config["overwrite"])

  File "train_isensee2017.py", line 79, in main

    n_base_filters=config["n_base_filters"])

  File "/workspace/3D-UNet_plus/brats/unet3d/model/isensee2017.py", line 47, in isensee2017_model

    in_conv = create_convolution_block(current_layer, n_level_filters)

  File "/workspace/3D-UNet_plus/brats/unet3d/model/unet.py", line 105, in create_convolution_block

    raise ImportError("Install keras_contrib in order to use instance normalization."

ImportError: Install keras_contrib in order to use instance normalization.

Try: pip install git+https://www.github.com/farizrahman4u/keras-contrib.git


解决方法:

1、安装 keras_contrib: pip install git+https://www.github.com/farizrahman4u/keras-contrib.git

2、在报错的文件 /workspace/3D-UNet_plus/brats/unet3d/model/unet.py 中,找到这一行

from keras_contrib.layers.normalization import InstanceNormalization

改为:

from keras_contrib.layers.normalization.instancenormalization import InstanceNormalization

即可完美运行

如果还不能运行,则将Keras的版本与keras-contrib的版本一致。

你可能感兴趣的:(from keras_contrib.layers.normalization import InstanceNormalization 报错 ImportError: cannot impor...)