简体   繁体   English

为什么validation_freq不能与Keras模型配合使用?

[英]Why doesn't validation_freq work with Keras model fit?

According to the Keras docs , fit takes a validation_freq param: 根据Keras文档 ,fit需要一个validation_freq参数:

validation_freq: Only relevant if validation data is provided. validation_freq:仅在提供验证数据时相关。 Integer or list/tuple/set. 整数或列表/元组/集。 If an integer, specifies how many training epochs to run before a new validation run is performed, eg validation_freq=2 runs validation every 2 epochs. 如果是整数,则指定在执行新验证运行之前要运行多少个训练时期,例如validation_freq = 2每2个时期运行验证。 If a list, tuple, or set, specifies the epochs on which to run validation, eg validation_freq=[1, 2, 10] runs validation at the end of the 1st, 2nd, and 10th epochs. 如果list,tuple或set指定了运行验证的时期,例如validation_freq = [1,2,10]在第1,第2和第10个时期结束时运行验证。

result = model.fit( X_train, Y_train, epochs=2000, verbose=1, validation_data=(X_test,Y_test), validation_freq=10) # , validation_split=0.2

This raises: 这引起了:

File "/Users/george/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 942, in fit
raise TypeError('Unrecognized keyword arguments: ' + str(kwargs))
TypeError: Unrecognized keyword arguments: {'validation_freq': 10}

Using Keras2.1.6-tf. 使用Keras2.1.6-tf。 Has this param been added since? 从那以后添加了这个参数吗?

If so, how to update Keras for Anaconda? 如果是这样,如何更新Keras for Anaconda? I tried: 我试过了:

> conda update keras
Collecting package metadata: done
Solving environment: done

# All requested packages already installed.

The commit that added validation_freq was added after the latest release 2.2.4. 在最新版本2.2.4之后添加了添加validation_freq的提交。 See https://github.com/keras-team/keras/commit/a6c8042121371b5873773ca767f28cdf5689d5e4 , which was committed 28 days ago, after the latest release which was released last October. 请参阅https://github.com/keras-team/keras/commit/a6c8042121371b5873773ca767f28cdf5689d5e4 ,这是在去年10月发布的最新版本之后28天前提交的。

I fixed this by installing from keras' git repo: 我通过从keras的git repo安装修复了这个问题:

pip uninstall keras
pip install git+git://github.com/keras-team/keras.git

Although you're using conda , pip should still work to install packages. 虽然您使用的是conda ,但pip仍然可以安装包。 You may have to fiddle around with pip installing to the right python, ie pip3 install or on windows python -m pip install . 你可能不得不摆弄pip安装到正确的python,即pip3 install或Windows python -m pip install Worst comes to worst use conda to install from the source on github. 最糟糕的是使用conda从github上的源代码安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM