2017-12-20 4 views
0

tf.estimator.inputs.numpy_input_fn을 사용하여 모델에 피드하려면 numpy 배열로 견적을 작성합니다. 마찬가지로 다음numpy 배열이있는 견적 도구

Traceback (most recent call last):

File "", line 1, in runfile('/Experiment.py', wdir='/TensorFlow')

File "C:\Users\hp\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile execfile(filename, namespace)

File "C:\Users\hp\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "/Experiment.py", line 490, in hparams = params

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_runner.py", line 218, in run return _execute_schedule(experiment, schedule)

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\learn_runner.py", line 46, in _execute_schedule return task()

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\experiment.py", line 367, in train hooks=self._train_monitors + extra_hooks)

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\experiment.py", line 807, in _call_train hooks=hooks)

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 302, in train loss = self._train_model(input_fn, hooks, saving_listeners)

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 711, in _train_model features, labels, model_fn_lib.ModeKeys.TRAIN, self.config)

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 694, in _call_model_fn model_fn_results = self._model_fn(features=features, **kwargs)

File "/Experiment.py", line 350, in model_fn predict = forward(features, params, mode)

File "/Experiment.py", line 335, in forward dtype = tf.float32

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\python\ops\rnn.py", line 562, in dynamic_rnn flat_input = [ops.convert_to_tensor(input_) for input_ in flat_input]

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\python\ops\rnn.py", line 562, in flat_input = [ops.convert_to_tensor(input_) for input_ in flat_input]

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 836, in convert_to_tensor as_ref=False)

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 926, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\python\framework\constant_op.py", line 229, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name)

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\python\framework\constant_op.py", line 208, in constant value, dtype=dtype, shape=shape, verify_shape=verify_shape))

File "C:\Users\hp\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 472, in make_tensor_proto "supported type." % (type(values), values))

TypeError: Failed to convert object of type <class 'function'> to Tensor. Contents: <function numpy_input_fn.<locals>.input_fn at 0x000001AB2B1DBEA0>. Consider casting elements to a supported type.

사람이 왜 알고 있나요 :

def input_fun(data): 
    x, y = data 

    x, y = np.reshape(x, (batch_size, -1, 1)), \ 
      np.reshape(y, (batch_size, -1, 1)) 

    return tf.estimator.inputs.numpy_input_fn({'x': x}, y) 

def forward(x, params, mode): 

    layers = [tf.nn.rnn_cell.LSTMCell(n_neurons) for _ in range(n_layers)] 
    cells = tf.nn.rnn_cell.MultiRNNCell(layers) 
    outputs, state = tf.nn.dynamic_rnn(cells, x) 

    predictions = ... 

    return predictions 

def model_fn(features, labels, mode, params): 
    predict = forward(features, params, mode) 

    return tf.estimator.EstimatorSpec(predict , ...) 

def experiment_fn(config, params): 
    return learn.Experiment(
     estimator = estimator(model_fn,...), 
     train_input_fn = lambda: input_fun(train_set), 
     eval_input_fn = lambda: input_fun(eval_set)) 

그것은 다음 던져?

+0

희망이 도움 이온? – Nogoseke

+0

출력은 다음과 같습니다. state = tf.nn.dynamic_rnn (cells, x) –

답변

0

당신은 MultiRNNCell으로 세포의 목록을 통과해야 : 당신이 정말로 한 층 RNN을 확인하려면,

Args:

cells: list of RNNCells that will be composed in this order.

state_is_tuple: If True, accepted and returned states are n-tuples, where n = len(cells) . If False, the states are all concatenated along the column axis. This latter behavior will soon be deprecated.

cells = tf.nn.rnn_cell.MultiRNNCell([layers]) 

에 코드를 변경 ... 만들거나 더 레이어.

+0

죄송합니다. 코드를 덜 복잡해 보이도록 정리했지만 목록이었습니다. 코드를 업데이트했습니다. 여전히 같은 오류가 있습니다. –

+0

오류가 스 니펫에 없습니다. 우리에게 전체 코드를 보여주십시오 – Maxim

+0

출력을 실행할 때 state = tf.nn.dynamic_rnn (cells, x) 오류가 있습니다. 전체 추적을 보여주기 위해 업데이트했습니다. 당신은 그것이 dynamic_rnn에서 오는 것을 보았습니다. numpy_input_fn을 사용하는 방식에 문제가 있습니다. –

1

비슷한 문제가있었습니다. 내 경우에는 내 모델 ("forward", 귀하의 경우) x가 Tensor로 사용 되었기 때문에 예외가 발생했지만 실제로는 함수 (특히 tf.estimator.inputs.numpy_input_fn) 였기 때문에 예외가 발생했습니다. 나는이를 추가하여 알아 낸 :

<function numpy_input_fn.<locals>.input_fn at 0x7fcc6f065740> 
<class 'function'> 

나는 아직도 그것을 해결하는 올바른 방법이 무엇인지 모르겠지만, 내가 해결할 수 있었다 : 이런 식으로 뭔가를 인쇄

print(x) 
print(type(x)) 

이 비슷한 수행하여 :

input_dict, y = x() 
x = input_dict['x'] 

는 라인이 제외를 던졌습니다