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 2017/12/01 17:01:39 UTC

[GitHub] R1ncy opened a new issue #8911: can't load weight from hdf5 using mxnet as backend

R1ncy opened a new issue #8911: can't load weight from hdf5 using mxnet as backend
URL: https://github.com/apache/incubator-mxnet/issues/8911
 
 
   ## Description
   Train the u-net keras model using mxnet as backend. Everything works fine during the training and model, weights are saved successfully.
   But when I try to load weights from hdf5, it returns the traceback.
   
   ## Environment info (Required)
   ```
   win10, python3.6, pip version 9.0.1, 
   keras-2.1.1, mxnet-cu80-0.12.1b20171201, keras-mxnet-1.2.2
   ```
   
   ## Error Message:
   ```
   Traceback (most recent call last):
     File "D:/fbl/unet/sc_road.py", line 198, in <module>
       model.load_weights('weights/w_debug.hdf5')
     File "C:\Users\123\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2720, in load_weights
       self.load_weights_from_hdf5_group(f)
     File "C:\Users\123\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2806, in load_weights_from_hdf5_group
       K.batch_set_value(weight_value_tuples)
     File "C:\Users\123\Anaconda3\lib\site-packages\keras\backend\mxnet_backend.py", line 2207, in batch_set_value
       set_value(p, w)
     File "C:\Users\123\Anaconda3\lib\site-packages\keras\backend\mxnet_backend.py", line 2195, in set_value
       x.bind(mx.nd.array(value))
     File "C:\Users\123\Anaconda3\lib\site-packages\mxnet\ndarray\utils.py", line 146, in array
       return _array(source_array, ctx=ctx, dtype=dtype)
     File "C:\Users\123\Anaconda3\lib\site-packages\mxnet\ndarray\ndarray.py", line 2245, in array
       arr[:] = source_array
     File "C:\Users\123\Anaconda3\lib\site-packages\mxnet\ndarray\ndarray.py", line 437, in __setitem__
       self._set_nd_basic_indexing(key, value)
     File "C:\Users\123\Anaconda3\lib\site-packages\mxnet\ndarray\ndarray.py", line 698, in _set_nd_basic_indexing
       self._sync_copyfrom(value)
     File "C:\Users\123\Anaconda3\lib\site-packages\mxnet\ndarray\ndarray.py", line 859, in _sync_copyfrom
       str(self.shape), str(source_array.shape)))
   ValueError: Shape inconsistent: expected () vs got (1,)
   ```
   
   ## Minimum reproducible example
   At the last layer of the model
   ```
   conv10 = Convolution2D(N_CLS, 1, 1, activation='sigmoid')(conv9)
   ```
   where N_CLS=1, so the shape of bias=(1,).
   
   I use this code to save model and weights during traing:
   ```
   model_checkpoint = ModelCheckpoint('weights/sc_road.hdf5', monitor='loss', save_best_only=True,
                                          save_weights_only=False)
   ```
   And also try ```model.save_weights('weights/w_debug.hdf5')``` to save model, ```model.load_weights('weights/w_debug.hdf5')``` or ```model = load_model('weights/w_debug.hdf5')``` to load weights from the hdf5 file, but error is the same.
   
   
   ## What have you tried to solve it?
   
   1. I debuged and found the value of bias at the last layer is -0.15, but the shape in hdf5 is () (which is not correct), so the error occurs.
   2. I found the same issue on stackoverflow but it seems unsolved.
   [https://stackoverflow.com/questions/46698701/keras-fails-to-load-model-weights-when-using-mxnet-backend](url)
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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