IndexError:当我尝试使用load_weights()加载我自己模型的训练权重时,列表索引超出范围

时间:2019-03-23 06:31:14

标签: python-3.x keras

我创建了一个小的ResNet并在不使用load_weights的情况下成功对其进行了培训和评估。我通过modelCheckPoint保存了权重。

当我不使用load_weights()函数时,代码可以正确运行。 但是当我有该行时,就会发生IndexError。

print("***** conv_model *****")
model=A2OD_N(c=len_closeness,p=len_period,
             T=T,F=F,H=H,W=W,
             pre_F=64,R_N=2,
             CF=64,
             drop=0,
             kernel1=1,
             is_summary=True,
             nb_residual_unit=3)

file_conv='MODEL/pop2flow_'+str(iterate)+'.hdf5'
if train:
    model_checkpoint=ModelCheckpoint(
            filepath=file_conv,
            monitor='val_rmse',
            verbose=1,
            save_best_only=True,
            save_weights_only=True,
            mode='min',
            period=1
        )
    print('=' * 10)
    print("***** training conv_model *****")
    history = model.fit(X_train, Y_train,
                        epochs=epoch,
                        batch_size=batch_size,
                        validation_split=0.1,
                        callbacks=[model_checkpoint],
                        verbose=1)
print('=' * 10)
print('***** evaluate *****')
model.load_weights(file_conv)

*****评估*****

Traceback (most recent call last):
  File "executor.py", line 78, in <module>
    model.load_weights(file_conv)
  File "/home/loooffeeeey/Documents/pop2flow/pop2flow/lib/python3.6/site-packages/keras/engine/network.py", line 1166, in load_weights
    f, self.layers, reshape=reshape)
  File "/home/loooffeeeey/Documents/pop2flow/pop2flow/lib/python3.6/site-packages/keras/engine/saving.py", line 1045, in load_weights_from_hdf5_group
    reshape=reshape)
  File "/home/loooffeeeey/Documents/pop2flow/pop2flow/lib/python3.6/site-packages/keras/engine/saving.py", line 682, in preprocess_weights_for_loading
    weights = convert_nested_model(weights)
  File "/home/loooffeeeey/Documents/pop2flow/pop2flow/lib/python3.6/site-packages/keras/engine/saving.py", line 670, in convert_nested_model
    original_backend=original_backend))
  File "/home/loooffeeeey/Documents/pop2flow/pop2flow/lib/python3.6/site-packages/keras/engine/saving.py", line 682, in preprocess_weights_for_loading
    weights = convert_nested_model(weights)
  File "/home/loooffeeeey/Documents/pop2flow/pop2flow/lib/python3.6/site-packages/keras/engine/saving.py", line 658, in convert_nested_model
    original_backend=original_backend))
  File "/home/loooffeeeey/Documents/pop2flow/pop2flow/lib/python3.6/site-packages/keras/engine/saving.py", line 800, in preprocess_weights_for_loading
    elif layer_weights_shape != weights[0].shape:
IndexError: list index out of range

0 个答案:

没有答案