簡體   English   中英

我該如何解決這個錯誤? 我正在嘗試運行模型,但不斷收到此關鍵錯誤

[英]how do i go about fixing this error? i am trying to run model but keep getting this key error

這是我的代碼,一切似乎都很好,直到我運行它,就在它運行之前,我收到一個錯誤

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'

我該怎么做?

更改名稱

'val_accuracy' 到 'val_acc'

在文件filepath = "RNN_Final-{epoch:02d}-{val_accuracy:.3f}.hdf5" ,它應該可以工作。

另外,請換行

"models\{}.model".format(filepath, monitor='val_acc', verbose=10, save_best_only=True, mode='max')

"models\{}.model".format(filepath), monitor='val_acc', verbose=10, save_best_only=True, mode='max'). 

在這里,您只需要使用 .format() 函數中的第一個參數。 問題來自這樣一個事實,即您向 .format() 函數發送了大量參數而不是單個參數。

如果這些仍然不起作用,您應該在文件路徑和檢查點中使用 'val_accuracy'。 如果這也不起作用,請從您的文件路徑名稱中刪除 'val_acc:3f'。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM