2017-12-22 21 views
0
인 오류 "파이썬`bool`로`tf.Tensor`"를 제공

나는 다음 코드 tensorflow here에서 구현 계층 정상화 LSTM 장치를 사용하고 싶습니다 :dynamic_rnn은 (LayerNormBasicLSTMCell에서) layer_norm는 텐서

TypeError: Using a `tf.Tensor` as a Python `bool` is not allowed. Use `if t is not None:` instead of `if t:` to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor. 

그리고 추적이 dynamic_rnn로 돌아갑니다 : 다음 layer_normTensor

import tensorflow as tf 
import numpy as np 

n = 10 
batch_size_series = 16 

x = tf.placeholder(shape=[None, None, 1], dtype=tf.float32, name="x") 
layer_norm = tf.placeholder(tf.bool, name="normalize_layer") 

cell = tf.contrib.rnn.LayerNormBasicLSTMCell(n, layer_norm=layer_norm) 

initial_state = cell.zero_state(batch_size_series, dtype=tf.float32) 

output_state, current_state = tf.nn.dynamic_rnn(cell, inputs=x, initial_state=initial_state, dtype=tf.float32) 

나는 다음과 같은 오류가

Traceback (most recent call last): 
    File "test.py", line 19, in <module> 
    output_state, current_state = tf.nn.dynamic_rnn(multi_rnn_cell, inputs=x, initial_state=initial_state, dtype=tf.float32) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py", line 614, in dynamic_rnn 
    dtype=dtype) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py", line 777, in _dynamic_rnn_loop 
    swap_memory=swap_memory) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2816, in while_loop 
    result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2640, in BuildLoop 
    pred, body, original_loop_vars, loop_vars, shape_invariants) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2590, in _BuildLoop 
    body_result = body(*packed_vars_for_body) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py", line 762, in _time_step 
    (output, new_state) = call_cell() 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py", line 748, in <lambda> 
    call_cell = lambda: cell(input_t, state) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/ops/rnn_cell_impl.py", line 183, in __call__ 
    return super(RNNCell, self).__call__(inputs, state) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 575, in __call__ 
    outputs = self.call(inputs, *args, **kwargs) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/ops/rnn_cell_impl.py", line 1066, in call 
    cur_inp, new_state = cell(cur_inp, cur_state) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/ops/rnn_cell_impl.py", line 183, in __call__ 
    return super(RNNCell, self).__call__(inputs, state) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/layers/base.py", line 575, in __call__ 
    outputs = self.call(inputs, *args, **kwargs) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py", line 1340, in call 
    concat = self._linear(args) 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py", line 1331, in _linear 
    if not self._layer_norm: 
    File "/Users/fghavamian/ve_tf2/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 528, in __bool__ 

여기에 뭔가가 있습니까?

답변

0

tf.contrib.rnn.LayerNormBasicLSTMCell 초기화는 파이썬 부울 및 하지tf.Tensorlayer_norm 인수로 예상하고있다. 그 이유는 계층 정규화에 적합한 변수를 생성하기 위해이 인수의 값을 그래프 작성 시간에 알 필요가 있기 때문입니다 (예 : "gamma""beta" 변수는 here으로 생성됨).