Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizing_adanet tutorial error #16

Closed
zhouhao-learning opened this issue Nov 2, 2018 · 3 comments
Closed

Customizing_adanet tutorial error #16

zhouhao-learning opened this issue Nov 2, 2018 · 3 comments

Comments

@zhouhao-learning
Copy link

In customizing_adanet notebook, When I ran the Customizing_adanet tutorial error notebook, I got the following error at the end:

TypeError                                 Traceback (most recent call last)
<ipython-input-10-9f72d27cf659> in <module>
     26     eval_spec=tf.estimator.EvalSpec(
     27         input_fn=input_fn("test", training=False, batch_size=BATCH_SIZE),
---> 28         steps=None))
     29 print("Accuracy:", results["accuracy"])
     30 print("Loss:", results["average_loss"])

~/anaconda3/envs/Adanet/lib/python3.5/site-packages/tensorflow/python/estimator/training.py in train_and_evaluate(estimator, train_spec, eval_spec)
    445         '(with task id 0).  Given task id {}'.format(config.task_id))
    446 
--> 447   return executor.run()
    448 
    449 

~/anaconda3/envs/Adanet/lib/python3.5/site-packages/tensorflow/python/estimator/training.py in run(self)
    529         config.task_type != run_config_lib.TaskType.EVALUATOR):
    530       logging.info('Running training and evaluation locally (non-distributed).')
--> 531       return self.run_local()
    532 
    533     # Distributed case.

~/anaconda3/envs/Adanet/lib/python3.5/site-packages/tensorflow/python/estimator/training.py in run_local(self)
    667           input_fn=self._train_spec.input_fn,
    668           max_steps=self._train_spec.max_steps,
--> 669           hooks=train_hooks)
    670 
    671       if not self._continuous_eval_listener.before_eval():

~/anaconda3/envs/Adanet/lib/python3.5/site-packages/adanet/core/estimator.py in train(self, input_fn, hooks, steps, max_steps, saving_listeners)
    440             hooks=hooks,
    441             max_steps=max_steps,
--> 442             saving_listeners=saving_listeners)
    443 
    444         # If training ended because the maximum number of training steps

~/anaconda3/envs/Adanet/lib/python3.5/site-packages/tensorflow/python/estimator/estimator.py in train(self, input_fn, hooks, steps, max_steps, saving_listeners)
    364 
    365       saving_listeners = _check_listeners_type(saving_listeners)
--> 366       loss = self._train_model(input_fn, hooks, saving_listeners)
    367       logging.info('Loss for final step: %s.', loss)
    368       return self

~/anaconda3/envs/Adanet/lib/python3.5/site-packages/tensorflow/python/estimator/estimator.py in _train_model(self, input_fn, hooks, saving_listeners)
   1117       return self._train_model_distributed(input_fn, hooks, saving_listeners)
   1118     else:
-> 1119       return self._train_model_default(input_fn, hooks, saving_listeners)
   1120 
   1121   def _train_model_default(self, input_fn, hooks, saving_listeners):

~/anaconda3/envs/Adanet/lib/python3.5/site-packages/tensorflow/python/estimator/estimator.py in _train_model_default(self, input_fn, hooks, saving_listeners)
   1130       worker_hooks.extend(input_hooks)
   1131       estimator_spec = self._call_model_fn(
-> 1132           features, labels, model_fn_lib.ModeKeys.TRAIN, self.config)
   1133       return self._train_with_estimator_spec(estimator_spec, worker_hooks,
   1134                                              hooks, global_step_tensor,

~/anaconda3/envs/Adanet/lib/python3.5/site-packages/tensorflow/python/estimator/estimator.py in _call_model_fn(self, features, labels, mode, config)
   1105 
   1106     logging.info('Calling model_fn.')
-> 1107     model_fn_results = self._model_fn(features=features, **kwargs)
   1108     logging.info('Done calling model_fn.')
   1109 

~/anaconda3/envs/Adanet/lib/python3.5/site-packages/adanet/core/estimator.py in _model_fn(self, features, labels, mode, params)
   1044           mode=mode,
   1045           previous_ensemble_summary=previous_ensemble_summary,
-> 1046           previous_ensemble_spec=previous_ensemble_spec)
   1047 
   1048     # Variable which allows us to read the current iteration from a checkpoint.

~/anaconda3/envs/Adanet/lib/python3.5/site-packages/adanet/core/iteration.py in build_iteration(self, iteration_number, subnetwork_builders, features, mode, labels, previous_ensemble_summary, previous_ensemble_spec)
    213             mode=mode,
    214             iteration_step=iteration_step_tensor,
--> 215             labels=labels)
    216         candidate = self._candidate_builder.build_candidate(
    217             ensemble_spec=ensemble_spec,

~/anaconda3/envs/Adanet/lib/python3.5/site-packages/adanet/core/ensemble.py in append_new_subnetwork(self, ensemble_spec, subnetwork_builder, iteration_step, summary, features, mode, labels)
    321               iteration_step=iteration_step,
    322               summary=summary,
--> 323               previous_ensemble=ensemble)
    324           trainable_vars_after = tf.trainable_variables()
    325           var_list = list(

<ipython-input-8-13ccd77121f3> in build_subnetwork(self, features, logits_dimension, training, iteration_step, summary, previous_ensemble)
     25                        previous_ensemble=None):
     26     """See `adanet.subnetwork.Builder`."""
---> 27     images = features.values()[0]
     28     kernel_initializer = tf.keras.initializers.he_normal(seed=self._seed)
     29     x = tf.layers.conv2d(

TypeError: 'dict_values' object does not support indexing

This is your latest code, how should I solve this problem?

@dtrippas
Copy link

dtrippas commented Nov 2, 2018

Wrap list() around features.values() to fix this error. Solution taken from stackoverflow

@cweill
Copy link
Contributor

cweill commented Nov 2, 2018

These tutorials were not tested with Python 3: #18. @dtrippas's response is correct.

@cweill cweill closed this as completed in 51660b5 Nov 5, 2018
@smyrbdr
Copy link

smyrbdr commented Nov 10, 2018

Just replaced the corresponding line (images=features.vaules()[0]) in build_subnetwork function with the following line;
images = tf.to_float(features[FEATURES_KEY])
and this solved the issue for me on Python 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants