tensorflow mnist.py代码出错

问题描述 投票:0回答:1

我现在用python 2.7.5学习tensorflow 1.5.0。我在models / official / mnist中尝试了mnist.py代码我收到以下错误消息。怎么了 ?

bash-4.2$ cd models/official/mnist
bash-4.2$ python mnist.py
INFO:tensorflow:Using default config.
INFO:tensorflow:Using config: {'_save_checkpoints_secs': 600, '_session_config': None, '_keep_checkpoint_max': 5, '_task_type': 'worker', '_is_chief': True, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x4993e90>, '_save_checkpoints_steps': None, '_keep_checkpoint_every_n_hours': 10000, '_service': None, '_num_ps_replicas': 0, '_tf_random_seed': None, '_master': '', '_num_worker_replicas': 1, '_task_id': 0, '_log_step_count_steps': 100, '_model_dir': '/tmp/mnist_model', '_save_summary_steps': 100}
Traceback (most recent call last):
  File "mnist.py", line 270, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 124, in run
    _sys.exit(main(argv))
  File "mnist.py", line 202, in main
    mnist_classifier.train(input_fn=train_input_fn, hooks=[logging_hook])
  File "/usr/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 314, in train
    loss = self._train_model(input_fn, hooks, saving_listeners)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 743, in _train_model
    features, labels, model_fn_lib.ModeKeys.TRAIN, self.config)
  File "/usr/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 725, in _call_model_fn
    model_fn_results = self._model_fn(features=features, **kwargs)
  File "mnist.py", line 89, in model_fn
    model = Model(params['data_format'])
  File "mnist.py", line 48, in __init__
    super(Model, self).__init__()
TypeError: __init__() takes at least 3 arguments (1 given)
python tensorflow mnist
1个回答
0
投票

正如堆栈跟踪所说 - 问题在于此调用:

super(Model, self).__init__()

Model类至少需要2个参数+ self作为默认值 - 它给出了上面提到的3个参数。请查看here - 有自定义分类器示例。问题是你传递的params是由**kwargs拍摄的,并描述了构造函数所采用的参数 - 你需要2个或更多值。至少就是说,没有看到你的代码,我可以告诉你。

© www.soinside.com 2019 - 2024. All rights reserved.