Python 如何着手修复此错误?我正在尝试运行模型,但不断出现此关键错误
这是我的代码,在我运行它之前,一切似乎都很好,在它运行之前,我得到了一个错误Python 如何着手修复此错误?我正在尝试运行模型,但不断出现此关键错误,python,tensorflow,keras,Python,Tensorflow,Keras,这是我的代码,在我运行它之前,一切似乎都很好,在它运行之前,我得到了一个错误 tensorboard=tensorboard(log_dir=f'logs\{NAME}) filepath=“RNN_Final-{epoch:02d}-{val_精度:.3f}.hdf5” checkpoint=ModelCheckpoint(“models\{}.model.”格式(filepath,monitor='val\u acc',verbose=10,save\u best\u only=True,m
tensorboard=tensorboard(log_dir=f'logs\{NAME})
filepath=“RNN_Final-{epoch:02d}-{val_精度:.3f}.hdf5”
checkpoint=ModelCheckpoint(“models\{}.model.”格式(filepath,monitor='val\u acc',verbose=10,save\u best\u only=True,mode='max'))
列车y=np.asarray(列车y)
验证y=np.asarray(验证y)
历史=model.fit(
列车x,列车y,
批次大小=批次大小,
时代,
验证数据=(验证x,验证y),
回调=[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'
runfile('C:/Users/Enock/.spyder-py3/cryptoRnn.py',wdir='C:/Users/Enock/.spyder-py3')
列车数据:69188验证:3062
不要买:34594,买:34594
验证不购买:1531,购买:1531
培训69188个样本,验证3062个样本
纪元1/20
警告:tensorflow:无法转换实体,将按原样执行。请向签名组报告。在归档bug时,将详细度设置为10(在Linux上,`export AUTOGRAPH\u verbosity=10`),并附加完整的输出。原因:
警告:实体无法转换,将按原样执行。请向签名组报告。在归档bug时,将详细度设置为10(在Linux上,`export AUTOGRAPH\u verbosity=10`),并附加完整的输出。原因:
64/69188[……]-预计到达时间:16:11:22回溯(最近一次呼叫最后一次):
文件“”,第1行,在
运行文件('C:/Users/Enock/.spyder-py3/cryptoRnn.py',wdir='C:/Users/Enock/.spyder-py3')
文件“C:\Users\Enock\Anaconda3\lib\site packages\spyder\u kernels\customize\spyderrcustomize.py”,第827行,在runfile中
execfile(文件名、命名空间)
文件“C:\Users\Enock\Anaconda3\lib\site packages\spyder\u kernels\customize\spyderrcustomize.py”,第110行,在execfile中
exec(编译(f.read(),文件名,'exec'),命名空间)
文件“C:/Users/Enock/.spyder-py3/cryptoRnn.py”,第184行,在
回调=[tensorboard,checkpoint])
文件“C:\Users\Enock\Anaconda3\lib\site packages\tensorflow\u core\python\keras\engine\training.py”,第728行,fit
使用多处理=使用多处理)
文件“C:\Users\Enock\Anaconda3\lib\site packages\tensorflow\u core\python\keras\engine\training\u v2.py”,第372行
前缀class='val')
文件“C:\Users\Enock\Anaconda3\lib\contextlib.py”,第130行,在退出时__
self.gen.throw(类型、值、回溯)
文件“C:\Users\Enock\Anaconda3\lib\site packages\tensorflow\u core\python\keras\engine\training\u v2.py”,第685行,on\u epoch
self.callbacks.on\u epoch\u end(epoch,epoch\u日志)
文件“C:\Users\Enock\Anaconda3\lib\site packages\tensorflow\u core\python\keras\callbacks.py”,第298行,在末尾
回调。在\u epoch\u结束时(epoch,日志)
文件“C:\Users\Enock\Anaconda3\lib\site packages\tensorflow\u core\python\keras\callbacks.py”,第965行,在末尾
自我保存模型(历元=历元,日志=日志)
文件“C:\Users\Enock\Anaconda3\lib\site packages\tensorflow\u core\python\keras\callbacks.py”,第984行,在保存模型中
filepath=self.\u获取\u文件\u路径(历元、日志)
文件“C:\Users\Enock\Anaconda3\lib\site packages\tensorflow\u core\python\keras\callbacks.py”,第1020行,在\u get\u File\u路径中
返回self.filepath.format(epoch=epoch+1,**日志)
KeyError:“val_精度”
我该怎么做呢?更改 “val_精度”至“val_acc” 在
filepath=“RNN\u Final-{epoch:02d}-{val\u精度:.3f}.hdf5”
中,它应该可以工作
另外,请换电话
"models\{}.model".format(filepath, monitor='val_acc', verbose=10, save_best_only=True, mode='max')
到
在这里,您只需要使用.format()函数中的第一个参数。问题在于,您向.format()函数发送了大量参数,而不是单个参数
如果这些仍然不起作用,您应该在filepath和checkpoint中使用“val_accurity”。如果这也不起作用,请从文件路径名中删除“val\u acc:3f”。我这样做了,但仍然给了我相同的错误:文件“C:\Users\Enock\Anaconda3\lib\site packages\tensorflow\u core\python\keras\callbacks.py”,第1020行,在“get\u File\u path返回self.filepath.format(epoch=epoch+1,**日志)KeyError:'val_acc'仍然不明白为什么我会出错这里是代码::::filepath=“RNN_Final-{epoch:02d}-{val_acc:.3f}.hdf5”checkpoint=modelscheckpoint(“models\{}.model”)。format(filepath,monitor='val_acc',verbose=1,save\u best\u only=True,mode='max')我发现了这个问题。“models\{}.model.”格式(文件路径,monitor='val\u acc',verbose=10,save\u best\u only=True,mode='max')。在这里,您只需要使用.format()函数中的第一个参数。我这样做了,但错误就在那里:文件“C:\Users\Enock\Anaconda3\lib\site packages\tensorflow\u core\python\keras\callbacks.py”,第1020行,在"get\u File\u path"返回self.filepath.format(epoch=epoch+1,**logs)键错误:“val\u acc”代码:filepath=“RNN\u Final-{epoch:02d}-{val_acc:.3f}.hdf5“checkpoint=ModelCheckpoint(“models\{}.model.”格式(filepath),monitor='val_acc',verbose=1,save_best_only=True,mode='max')
"models\{}.model".format(filepath), monitor='val_acc', verbose=10, save_best_only=True, mode='max').