我该如何解决该错误?我正在尝试运行模型,但始终收到此关键错误

时间:2019-12-28 20:04:16

标签: python tensorflow keras

这是我的代码,直到我仔细阅读为止,并且在运行之前我遇到了错误

tensorboard = TensorBoard(log_dir=f'logs\{NAME}')

filepath = "RNN_Final-{epoch:02d}-{val_accuracy:.3f}.hdf5"
checkpoint = ModelCheckpoint("models\{}.model".format(filepath, monitor='val_acc', verbose=10, save_best_only=True, mode='max'))

train_y= np.asarray(train_y) 
validation_y= np.asarray(validation_y)

history = model.fit(
    train_x, train_y,
    batch_size=BATCH_SIZE,
    epochs=EPOCHS,

    validation_data=(validation_x, validation_y),

    callbacks=[tensorboard, checkpoint])

这是错误:

runfile('C:/Users/Enock/.spyder-py3/cryptoRnn.py', wdir='C:/Users/Enock/.spyder-py3')
train data: 69188 validation: 3062
Dont buys: 34594, buys: 34594
VALIDATION Dont buys: 1531, buys: 1531
Train on 69188 samples, validate on 3062 samples
Epoch 1/20
    WARNING:tensorflow:Entity <function Function._initialize_uninitialized_variables.<locals>.initialize_variables at 0x000001ED8967C1F8> could not be transformed and will be executed as-is. Please report this to the AutoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: 
WARNING: Entity <function Function._initialize_uninitialized_variables.<locals>.initialize_variables at 0x000001ED8967C1F8> could not be transformed and will be executed as-is. Please report this to the AutoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: 
   64/69188 [..............................] - ETA: 16:11:22Traceback (most recent call last):

  File "<ipython-input-25-37d8bfb90722>", line 1, in <module>
    runfile('C:/Users/Enock/.spyder-py3/cryptoRnn.py', wdir='C:/Users/Enock/.spyder-py3')

  File "C:\Users\Enock\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\Enock\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Enock/.spyder-py3/cryptoRnn.py", line 184, in <module>
    callbacks=[tensorboard, checkpoint])

  File "C:\Users\Enock\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 728, in fit
    use_multiprocessing=use_multiprocessing)

  File "C:\Users\Enock\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 372, in fit
    prefix='val_')

  File "C:\Users\Enock\Anaconda3\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)

  File "C:\Users\Enock\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 685, in on_epoch
    self.callbacks.on_epoch_end(epoch, epoch_logs)

  File "C:\Users\Enock\Anaconda3\lib\site-packages\tensorflow_core\python\keras\callbacks.py", line 298, in on_epoch_end
    callback.on_epoch_end(epoch, logs)

  File "C:\Users\Enock\Anaconda3\lib\site-packages\tensorflow_core\python\keras\callbacks.py", line 965, in on_epoch_end
    self._save_model(epoch=epoch, logs=logs)

  File "C:\Users\Enock\Anaconda3\lib\site-packages\tensorflow_core\python\keras\callbacks.py", line 984, in _save_model
    filepath = self._get_file_path(epoch, logs)

  File "C:\Users\Enock\Anaconda3\lib\site-packages\tensorflow_core\python\keras\callbacks.py", line 1020, in _get_file_path
    return self.filepath.format(epoch=epoch + 1, **logs)

KeyError: 'val_accuracy'

我该怎么办?

1 个答案:

答案 0 :(得分:0)

更改的名称

  

“ val_accuracy”到“ val_acc”

filepath = "RNN_Final-{epoch:02d}-{val_accuracy:.3f}.hdf5"中,它应该可以工作。