2016-08-18 2 views
2

나는 공식 TensorFlow 웹 사이트에서 제공하는 예제를 실행하려고 시도하고 실행은 여기에서 찾을 :TensorFlow 다음 DNN 아이리스 예

from __future__ import absolute_import 
from __future__ import division 
from __future__ import print_function 

import tensorflow as tf 
import numpy as np 

# Data sets 
IRIS_TRAINING = "iris_training.csv" 
IRIS_TEST = "iris_test.csv" 

# Load datasets. 
training_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TRAINING, 
                 target_dtype=np.int) 
test_set = tf.contrib.learn.datasets.base.load_csv(filename=IRIS_TEST, 
                target_dtype=np.int) 

# Build 3 layer DNN with 10, 20, 10 units respectively. 
classifier = tf.contrib.learn.DNNClassifier(hidden_units=[10, 20, 10], 
              n_classes=3, 
              model_dir="/tmp/iris_model") 

# Fit model. 
classifier.fit(x=training_set.data, 
       y=training_set.target, 
       steps=2000) 

# Evaluate accuracy. 
accuracy_score = classifier.evaluate(x=test_set.data, 
            y=test_set.target)["accuracy"] 
print('Accuracy: {0:f}'.format(accuracy_score)) 

# Classify two new flower samples. 
new_samples = np.array(
    [[6.4, 3.2, 4.5, 1.5], [5.8, 3.1, 5.0, 1.7]], dtype=float) 
y = classifier.predict(new_samples) 
print('Predictions: {}'.format(str(y))) 
: https://www.tensorflow.org/versions/r0.10/tutorials/tflearn/index.html 완성도를 들어

, 내가 실행하고 문제의 코드는 다음과 같다 그러나 나는 "hidden_units"를 변경하면 변수를

WARNING:tensorflow:Change warning: `feature_columns` will be required after 2016-08-01. 
Instructions for updating: 
Pass `tf.contrib.learn.infer_real_valued_columns_from_input(x)` or `tf.contrib.learn.infer_real_valued_columns_from_input_fn(input_fn)` as `feature_columns`, where `x` or `input_fn` is your argument to `fit`, `evaluate`, or `predict`. 
WARNING:tensorflow:Setting feature info to TensorSignature(dtype=tf.float32, shape=TensorShape([Dimension(None), Dimension(4)]), is_sparse=False) 
WARNING:tensorflow:Setting targets info to TensorSignature(dtype=tf.int64, shape=TensorShape([Dimension(None)]), is_sparse=False) 
E tensorflow/core/client/tensor_c_api.cc:485] Tensor name "hiddenlayer_2/weights/Adagrad" not found in checkpoint files /tmp/iris_model/model.ckpt-16000-?????-of-00001 
     [[Node: save/restore_slice_18 = RestoreSlice[dt=DT_FLOAT, preferred_shard=0, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/restore_slice_18/tensor_name, save/restore_slice_18/shape_and_slice)]] 
Traceback (most recent call last): 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 730, in _do_call 
    return fn(*args) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 712, in _run_fn 
    status, run_metadata) 
    File "/usr/lib/python3.5/contextlib.py", line 66, in __exit__ 
    next(self.gen) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors.py", line 450, in raise_exception_on_not_ok_status 
    pywrap_tensorflow.TF_GetCode(status)) 
tensorflow.python.framework.errors.NotFoundError: Tensor name "hiddenlayer_2/weights/Adagrad" not found in checkpoint files /tmp/iris_model/model.ckpt-16000-?????-of-00001 
     [[Node: save/restore_slice_18 = RestoreSlice[dt=DT_FLOAT, preferred_shard=0, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/restore_slice_18/tensor_name, save/restore_slice_18/shape_and_slice)]] 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "test.py", line 26, in <module> 
    steps=2000) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 240, in fit 
    max_steps=max_steps) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 578, in _train_model 
    max_steps=max_steps) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/graph_actions.py", line 276, in _supervised_train 
    scaffold=scaffold) as super_sess: 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/supervised_session.py", line 212, in __init__ 
    self._sess = recoverable_session.RecoverableSession(self._create_session) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/recoverable_session.py", line 46, in __init__ 
    WrappedSession.__init__(self, sess_factory()) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/supervised_session.py", line 232, in _create_session 
    init_fn=self._scaffold.init_fn) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/session_manager.py", line 164, in prepare_session 
    max_wait_secs=max_wait_secs, config=config) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/session_manager.py", line 224, in recover_session 
    saver.restore(sess, ckpt.model_checkpoint_path) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1129, in restore 
    {self.saver_def.filename_tensor_name: save_path}) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 382, in run 
    run_metadata_ptr) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 655, in _run 
    feed_dict_string, options, run_metadata) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 723, in _do_run 
    target_list, options, run_metadata) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 743, in _do_call 
    raise type(e)(node_def, op, message) 
tensorflow.python.framework.errors.NotFoundError: Tensor name "hiddenlayer_2/weights/Adagrad" not found in checkpoint files /tmp/iris_model/model.ckpt-16000-?????-of-00001 
     [[Node: save/restore_slice_18 = RestoreSlice[dt=DT_FLOAT, preferred_shard=0, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/restore_slice_18/tensor_name, save/restore_slice_18/shape_and_slice)]] 
Caused by op 'save/restore_slice_18', defined at: 
    File "test.py", line 26, in <module> 
    steps=2000) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 240, in fit 
    max_steps=max_steps) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py", line 578, in _train_model 
    max_steps=max_steps) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/graph_actions.py", line 252, in _supervised_train 
    keep_checkpoint_max=keep_checkpoint_max) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/supervised_session.py", line 152, in __init__ 
    lambda: training_saver.Saver(sharded=True, 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/supervised_session.py", line 164, in _get_or_default 
    op = default_constructor() 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/contrib/learn/python/learn/supervised_session.py", line 153, in <lambda> 
    max_to_keep=keep_checkpoint_max)) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 861, in __init__ 
    restore_sequentially=restore_sequentially) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 515, in build 
    filename_tensor, per_device, restore_sequentially, reshape) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 312, in _AddShardedRestoreOps 
    name="restore_shard")) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 272, in _AddRestoreOps 
    values = self.restore_op(filename_tensor, vs, preferred_shard) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 187, in restore_op 
    preferred_shard=preferred_shard) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/io_ops.py", line 203, in _restore_slice 
    preferred_shard, name=name) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_io_ops.py", line 359, in _restore_slice 
    preferred_shard=preferred_shard, name=name) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 703, in apply_op 
    op_def=op_def) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2310, in create_op 
    original_op=self._default_original_op, op_def=op_def) 
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1232, in __init__ 
    self._traceback = _extract_stack() 

:

지금, 내가이 예제를 실행하면, 나는 다음과 같은 오류가 발생하고있다 보인다 [10] 대신 코드가 실행됩니다 (경고가 있지만 경고없이 실행 됨).

이 네트워크에 다른 레이어를 추가하면 오류가 발생하는 이유가 있습니까? 모든 입력이 도움이 될 것입니다, 감사합니다!

답변

1

모델 매개 변수를 업데이트하는 경우 model_dir을 변경해야합니다. 마찬가지로/tmp/iris 폴더에 있던 파일을 삭제하면 모델 상태가 유지되는 것과 같은 효과가 있었으며 매개 변수를 변경하면 재 장착하거나 실패 할 때 파일을 업데이트하려고 시도합니다.

+0

아, 그건 내 대답을 설명합니다. 고마워, 너를 받아 들일거야. –

0

오류가 상당히 이상했지만 생성 된 디렉토리 "/ tmp/iris"를 삭제하고 다시 시도 했으므로 정상적으로 실행 된 것으로 보입니다.