Reputation: 1
I'm using tensorflow to train a CNN. I wanted to use the custom Estimator with the code:
estimator = tf.estimator.Estimator(model_fn=cnn_model_fn, model_dir=r'C:\record')
And this is my model function:
def cnn_model_fn(Images, labels, mode)
When the code running to estimator, the error occurs: ValueError: model_fn () must include features argument. There is some other stuff that I am not sure if there is some help:
>
INFO:tensorflow:Using default config.
WARNING:tensorflow:Using temporary folder as model directory: C:Users\AppData\Local\Temp\tmpux9r74un
INFO:tensorflow:Using config: {'_log_step_count_steps': 100, '_model_dir': 'C:Users\\AppData\\Local\\Temp\\tmpux9r74un', '_keep_checkpoint_max': 5, '_save_summary_steps': 100, '_tf_random_seed': None, '_num_worker_replicas': 1, '_keep_checkpoint_every_n_hours': 10000, '_is_chief': True, '_save_checkpoints_secs': 600, '_train_distribute': None, '_evaluation_master': '', '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x0000019AC007C1D0>, '_global_id_in_cluster': 0, '_master': '', '_task_id': 0, '_save_checkpoints_steps': None, '_task_type': 'worker', '_session_config': None, '_num_ps_replicas': 0}
Traceback (most recent call last):
File "C:\Users\headpose2.py", line 273, in <module>
tf.app.run()
File "C:\Users\Downloads\anaconda\envs\python35\lib\site-packages\tensorflow\python\platform\app.py", line 126, in run
_sys.exit(main(argv))
File "C:/Users/headpose2.py", line 248, in main
estimator = tf.estimator.Estimator(model_fn=cnn_model_fn)
File "C:\Users\Downloads\anaconda\envs\python35\lib\site-packages\tensorflow\python\estimator\estimator.py", line 223, in __init__
_verify_model_fn_args(model_fn, params)
File "C:\Users\Downloads\anaconda\envs\python35\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1216, in _verify_model_fn_args
raise ValueError('model_fn (%s) must include features argument.' % model_fn)
ValueError: model_fn (<function cnn_model_fn at 0x0000019AB5C0B048>) must include features argument.
Could anyone help with this issue?
Upvotes: 0
Views: 1360
Reputation: 246
The model_fn
function of an Estimator object must have the following signature: model_fn(features, labels, mode, params)
where the names of the arguments are fixed. Therefore You can not replace features
by Images
as you did.
When using an Estimator, you also have to define an input_fn
whose role is to prepare the data and feed them to the Estimator's model_fn
. Both functions are connected under the hood by the Estimator class and I would say that the naming constraint was imposed so as to simplify this binding (and maybe others too).
Upvotes: 2