无法load_model或load_weights,但可以保存它们

时间:2019-07-19 02:11:23

标签: python keras

使用自动编码器并仅通过modelcheckpoint减轻重量

也尝试过load_model遇到相同的错误

check=ModelCheckpoint('data/bestmodel/autoencoder.h5',monitor='val_acc',save_best_only=True,save_weights_only=True,mode='max',verbose=1)

autoencoder.fit(train_images,train_labels,verbose=1,batch_size=2,epochs=1,validation_data=[test_images,test_labels] ,  callbacks=[check],shuffle=True)

autoencoder.load_weights('autoencoder.h5')

这是错误日志:

Traceback (most recent call last):
  File "encodeco.py", line 171, in <module>
    autoencoder.load_weights('autoencoder.h5')
  File "/home/niraj/.local/lib/python3.7/site-packages/keras/engine/network.py", line 1166, in load_weights
    f, self.layers, reshape=reshape)
  File "/home/niraj/.local/lib/python3.7/site-packages/keras/engine/saving.py", line 1045, in load_weights_from_hdf5_group
    reshape=reshape)
  File "/home/niraj/.local/lib/python3.7/site-packages/keras/engine/saving.py", line 682, in preprocess_weights_for_loading
    weights = convert_nested_model(weights)
  File "/home/niraj/.local/lib/python3.7/site-packages/keras/engine/saving.py", line 670, in convert_nested_model
    original_backend=original_backend))
  File "/home/niraj/.local/lib/python3.7/site-packages/keras/engine/saving.py", line 682, in preprocess_weights_for_loading
    weights = convert_nested_model(weights)
  File "/home/niraj/.local/lib/python3.7/site-packages/keras/engine/saving.py", line 658, in convert_nested_model
    original_backend=original_backend))
  File "/home/niraj/.local/lib/python3.7/site-packages/keras/engine/saving.py", line 801, in preprocess_weights_for_loading
    weights[0] = np.transpose(weights[0], (3, 2, 0, 1))
  File "/home/maki-d/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 639, in transpose
    return _wrapfunc(a, 'transpose', axes)
  File "/home/maki-d/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 56, in _wrapfunc
    return getattr(obj, method)(*args, **kwds)
ValueError: axes don't match array

0 个答案:

没有答案