You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/01/09 13:15:40 UTC

[GitHub] [incubator-mxnet] Justobe opened a new issue #17260: ValueError: Layer #1 (named "batch_normalization_1" in the current model) was found to correspond to layer batch_normalization_1 in the save file. However the new layer batch_normalization_1 expects 4 weights, but the saved weights have 3 elements.

Justobe opened a new issue #17260: ValueError: Layer #1 (named "batch_normalization_1" in the current model) was found to correspond to layer batch_normalization_1 in the save file. However the new layer batch_normalization_1 expects 4 weights, but the saved weights have 3 elements.
URL: https://github.com/apache/incubator-mxnet/issues/17260
 
 
   ## Description
   I find that MXNET behaves differently from tensorflow  when I try to load the inceptionV3 model using the following code. The scipt runs correctly with tensorflow, but I get one exception with MXNET. I don't know why this happens only on MXNET.
   
   ### Error Message
   ```
   Using MXNet backend
   /root/anaconda3/lib/python3.6/site-packages/keras/backend/mxnet_backend.py:94: UserWarning: MXNet Backend performs best with `channels_first` format. Using `channels_last` will significantly reduce performance due to the Transpose operations. For performance improvement, please use this API`keras.utils.to_channels_first(x_input)`to transform `channels_last` data to `channels_first` format and also please change the `image_data_format` in `keras.json` to `channels_first`.Note: `x_input` is a Numpy tensor or a list of Numpy tensorRefer to: https://github.com/awslabs/keras-apache-mxnet/tree/master/docs/mxnet_backend/performance_guide.md
     train_symbol = func(*args, **kwargs)
   /root/anaconda3/lib/python3.6/site-packages/keras/backend/mxnet_backend.py:97: UserWarning: MXNet Backend performs best with `channels_first` format. Using `channels_last` will significantly reduce performance due to the Transpose operations. For performance improvement, please use this API`keras.utils.to_channels_first(x_input)`to transform `channels_last` data to `channels_first` format and also please change the `image_data_format` in `keras.json` to `channels_first`.Note: `x_input` is a Numpy tensor or a list of Numpy tensorRefer to: https://github.com/awslabs/keras-apache-mxnet/tree/master/docs/mxnet_backend/performance_guide.md
     test_symbol = func(*args, **kwargs)
   /root/anaconda3/lib/python3.6/site-packages/keras/backend/mxnet_backend.py:94: UserWarning: MXNet Backend uses `channels_first` format. Axis for BatchNorm should ideally be `1`.Provided - `3`. Performance can be significantly lower!
     train_symbol = func(*args, **kwargs)
   /root/anaconda3/lib/python3.6/site-packages/keras/backend/mxnet_backend.py:97: UserWarning: MXNet Backend uses `channels_first` format. Axis for BatchNorm should ideally be `1`.Provided - `3`. Performance can be significantly lower!
     test_symbol = func(*args, **kwargs)
   Traceback (most recent call last):
     File "test_inception.py", line 19, in <module>
       base_model = keras.applications.inception_v3.InceptionV3(weights='imagenet', include_top=True, input_shape=(299,299,3))
     File "/root/anaconda3/lib/python3.6/site-packages/keras/applications/__init__.py", line 28, in wrapper
       return base_fun(*args, **kwargs)
     File "/root/anaconda3/lib/python3.6/site-packages/keras/applications/inception_v3.py", line 11, in InceptionV3
       return inception_v3.InceptionV3(*args, **kwargs)
     File "/root/anaconda3/lib/python3.6/site-packages/keras_applications/inception_v3.py", line 391, in InceptionV3
       model.load_weights(weights_path)
     File "/root/anaconda3/lib/python3.6/site-packages/keras/engine/network.py", line 1166, in load_weights
       f, self.layers, reshape=reshape)
     File "/root/anaconda3/lib/python3.6/site-packages/keras/engine/saving.py", line 1133, in load_weights_from_hdf5_group
       ' elements.')
   ValueError: Layer #1 (named "batch_normalization_1" in the current model) was found to correspond to layer batch_normalization_1 in the save file. However the new layer batch_normalization_1 expects 4 weights, but the saved weights have 3 elements.
   ```
   
   ## To Reproduce
   code.py
   ```
   import os
   import sys
   import argparse
   
   """Parser of command args"""
   parse = argparse.ArgumentParser()
   parse.add_argument("--backend", type=str, help="name of backends")
   flags, unparsed = parse.parse_known_args(sys.argv[1:])
   
   bk = flags.backend
   os.environ['KERAS_BACKEND'] = bk
   os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2'
   os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
   os.environ["CUDA_VISIBLE_DEVICES"] = ""
   import keras
   
   base_model = keras.applications.inception_v3.InceptionV3(weights='imagenet', include_top=True, input_shape=(299,299,3))
   base_model.summary()
   print("Done")
   ```
   The script can be run like this:
   > python3 code.py --backend mxnet
   
   ## Environment
   - numpy  1.16.1
   - tensorflow 1.14.0
   - mxnet-cu101_1.6.0b20191122
   - keras-mxnet  2.2.4.2
   
   Thanks in advance!
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services