Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TensorFlow GridLSTM示例 主要问题_Tensorflow_Neural Network_Lstm_Recurrent Neural Network_Rnn - Fatal编程技术网

TensorFlow GridLSTM示例 主要问题

TensorFlow GridLSTM示例 主要问题,tensorflow,neural-network,lstm,recurrent-neural-network,rnn,Tensorflow,Neural Network,Lstm,Recurrent Neural Network,Rnn,GridLSTM有两种实现: tf.contrib.rnn.GridLSTMCell tf.contrib.grid\n.Grid1LSTMCell 在tf.nn.dynamic\u rnn中使用这两种方法都会给我带来错误,我的问题是: 是否有任何实现、存储库等在最新的tensorflow API中使用任一单元 我知道,但它关注的是seq2seq,我无法将其应用于动态或静态 当前进展和小问题 如果我使用的是tf.contrib.rnn.GridLSTMCell,那么我的代码如下所示: tf.re

GridLSTM有两种实现:

  • tf.contrib.rnn.GridLSTMCell
  • tf.contrib.grid\n.Grid1LSTMCell
  • tf.nn.dynamic\u rnn
    中使用这两种方法都会给我带来错误,我的问题是: 是否有任何实现、存储库等在最新的tensorflow API中使用任一单元

    我知道,但它关注的是seq2seq,我无法将其应用于动态或静态

    当前进展和小问题 如果我使用的是
    tf.contrib.rnn.GridLSTMCell
    ,那么我的代码如下所示:

    tf.reset_default_graph()
    
    rnn_cell_sizes = [512, 512]
    
    cells = []
    for size in rnn_cell_sizes:
        cell = tf.contrib.rnn.GridLSTMCell(num_units=size)
        cells.append(cell)
    
    cell = tf.contrib.rnn.MultiRNNCell(cells)
    input_placeholder = tf.placeholder(tf.float32, [None, sequence_length, fft_size * feature_vector])
    
    tf.nn.dynamic_rnn(cell=cell, inputs=input_placeholder, dtype=tf.float32)
    
    tf.reset_default_graph()
    
    rnn_cell_sizes = [512, 512]
    
    cells = []
    for size in rnn_cell_sizes:
        cell = tf.contrib.grid_rnn.Grid1BasicLSTMCell(num_units=size, output_is_tuple=True)
        cells.append(cell)
    
    cell = tf.contrib.rnn.MultiRNNCell(cells)
    input_placeholder = tf.placeholder(tf.float32, [None, sequence_length, fft_size * feature_vector])
    
    tf.nn.dynamic_rnn(cell=cell, inputs=input_placeholder, dtype=tf.float32)
    
    这将返回如下错误:

    ValueError:必须指定num\u frequency\u块

    这是因为需要num_frequency_块。我能看出这是一张单子,但我搞不清楚它是干什么用的

    或者,我可以使用
    tf.contrib.grid\u rnn
    中的一些单元格,例如
    tf.contrib.grid\u rnn.Grid1BasicLSTMCell

    然后,我的代码变成这样:

    tf.reset_default_graph()
    
    rnn_cell_sizes = [512, 512]
    
    cells = []
    for size in rnn_cell_sizes:
        cell = tf.contrib.rnn.GridLSTMCell(num_units=size)
        cells.append(cell)
    
    cell = tf.contrib.rnn.MultiRNNCell(cells)
    input_placeholder = tf.placeholder(tf.float32, [None, sequence_length, fft_size * feature_vector])
    
    tf.nn.dynamic_rnn(cell=cell, inputs=input_placeholder, dtype=tf.float32)
    
    tf.reset_default_graph()
    
    rnn_cell_sizes = [512, 512]
    
    cells = []
    for size in rnn_cell_sizes:
        cell = tf.contrib.grid_rnn.Grid1BasicLSTMCell(num_units=size, output_is_tuple=True)
        cells.append(cell)
    
    cell = tf.contrib.rnn.MultiRNNCell(cells)
    input_placeholder = tf.placeholder(tf.float32, [None, sequence_length, fft_size * feature_vector])
    
    tf.nn.dynamic_rnn(cell=cell, inputs=input_placeholder, dtype=tf.float32)
    
    这将抛出一个大堆栈跟踪和一个类似这样的错误

    ----------------------------------------------------------------------
    
    -----
    TypeError                                 Traceback (most recent call last)
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/array_ops.py in zeros(shape, dtype, name)
       1438       shape = tensor_shape.as_shape(shape)
    -> 1439       output = constant(zero, shape=shape, dtype=dtype, name=name)
       1440     except (TypeError, ValueError):
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name, verify_shape)
        207       tensor_util.make_tensor_proto(
    --> 208           value, dtype=dtype, shape=shape, verify_shape=verify_shape))
        209   dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype)
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape)
        379     # exception when dtype is set to np.int64
    --> 380     if shape is not None and np.prod(shape, dtype=np.int64) == 0:
        381       nparray = np.empty(shape, dtype=np_dt)
    
    /usr/local/lib/python3.5/dist-packages/numpy/core/fromnumeric.py in prod(a, axis, dtype, out, keepdims)
       2517     return _methods._prod(a, axis=axis, dtype=dtype,
    -> 2518                           out=out, **kwargs)
       2519 
    
    /usr/local/lib/python3.5/dist-packages/numpy/core/_methods.py in _prod(a, axis, dtype, out, keepdims)
         34 def _prod(a, axis=None, dtype=None, out=None, keepdims=False):
    ---> 35     return umr_prod(a, axis, dtype, out, keepdims)
         36 
    
    TypeError: __int__ returned non-int (type NoneType)
    
    During handling of the above exception, another exception occurred:
    
    ValueError                                Traceback (most recent call last)
    <ipython-input-51-f9b0851a2255> in <module>()
         11 input_placeholder = tf.placeholder(tf.float32, [None, sequence_length, fft_size * feature_vector])
         12 
    ---> 13 tf.nn.dynamic_rnn(cell=cell, inputs=input_placeholder, dtype=tf.float32)
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/rnn.py in dynamic_rnn(cell, inputs, sequence_length, initial_state, dtype, parallel_iterations, swap_memory, time_major, scope)
        612         swap_memory=swap_memory,
        613         sequence_length=sequence_length,
    --> 614         dtype=dtype)
        615 
        616     # Outputs of _dynamic_rnn_loop are always shaped [time, batch, depth].
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/rnn.py in _dynamic_rnn_loop(cell, inputs, initial_state, parallel_iterations, swap_memory, sequence_length, dtype)
        775       loop_vars=(time, output_ta, state),
        776       parallel_iterations=parallel_iterations,
    --> 777       swap_memory=swap_memory)
        778 
        779   # Unpack final output if not using output tuples.
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/control_flow_ops.py in while_loop(cond, body, loop_vars, shape_invariants, parallel_iterations, back_prop, swap_memory, name)
       2814     loop_context = WhileContext(parallel_iterations, back_prop, swap_memory)  # pylint: disable=redefined-outer-name
       2815     ops.add_to_collection(ops.GraphKeys.WHILE_CONTEXT, loop_context)
    -> 2816     result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
       2817     return result
       2818 
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/control_flow_ops.py in BuildLoop(self, pred, body, loop_vars, shape_invariants)
       2638       self.Enter()
       2639       original_body_result, exit_vars = self._BuildLoop(
    -> 2640           pred, body, original_loop_vars, loop_vars, shape_invariants)
       2641     finally:
       2642       self.Exit()
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/control_flow_ops.py in _BuildLoop(self, pred, body, original_loop_vars, loop_vars, shape_invariants)
       2588         structure=original_loop_vars,
       2589         flat_sequence=vars_for_body_with_tensor_arrays)
    -> 2590     body_result = body(*packed_vars_for_body)
       2591     if not nest.is_sequence(body_result):
       2592       body_result = [body_result]
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/rnn.py in _time_step(time, output_ta_t, state)
        760           skip_conditionals=True)
        761     else:
    --> 762       (output, new_state) = call_cell()
        763 
        764     # Pack state if using state tuples
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/rnn.py in <lambda>()
        746 
        747     input_t = nest.pack_sequence_as(structure=inputs, flat_sequence=input_t)
    --> 748     call_cell = lambda: cell(input_t, state)
        749 
        750     if sequence_length is not None:
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/contrib/grid_rnn/python/ops/grid_rnn_cell.py in __call__(self, inputs, state, scope)
        192                  new_output, new_state, True)
        193       _propagate(conf.priority, conf, self._cells,
    --> 194                  c_prev, m_prev, new_output, new_state, False)
        195 
        196       # collect outputs and states
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/contrib/grid_rnn/python/ops/grid_rnn_cell.py in _propagate(dim_indices, conf, cells, c_prev, m_prev, new_output, new_state, first_call)
        627   else:
        628     cell_inputs = array_ops.zeros([m_prev[0].get_shape().as_list()[0], 0],
    --> 629                                   m_prev[0].dtype)
        630 
        631   last_dim_output = (new_output[-1]
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/array_ops.py in zeros(shape, dtype, name)
       1439       output = constant(zero, shape=shape, dtype=dtype, name=name)
       1440     except (TypeError, ValueError):
    -> 1441       shape = ops.convert_to_tensor(shape, dtype=dtypes.int32, name="shape")
       1442       output = fill(shape, constant(zero, dtype=dtype), name=name)
       1443   assert output.dtype.base_dtype == dtype
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in convert_to_tensor(value, dtype, name, preferred_dtype)
        834       name=name,
        835       preferred_dtype=preferred_dtype,
    --> 836       as_ref=False)
        837 
        838 
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx)
        924 
        925     if ret is None:
    --> 926       ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
        927 
        928     if ret is NotImplemented:
    
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/constant_op.py in _tensor_shape_tensor_conversion_function(s, dtype, name, as_ref)
        248   if not s.is_fully_defined():
        249     raise ValueError(
    --> 250         "Cannot convert a partially known TensorShape to a Tensor: %s" % s)
        251   s_list = s.as_list()
        252   int64_value = 0
    
    ValueError: Cannot convert a partially known TensorShape to a Tensor: (?, 0)
    
    ----------------------------------------------------------------------
    -----
    TypeError回溯(最近一次调用上次)
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/array_ops.py为零(形状、数据类型、名称)
    1438形状=张量形状。as形状(形状)
    ->1439输出=常数(零,shape=shape,dtype=dtype,name=name)
    1440除外(TypeError,ValueError):
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/constant_op.py in constant(值、数据类型、形状、名称、验证形状)
    207张量使用。生成张量原型(
    -->208值,dtype=dtype,shape=shape,verify_shape=verify_shape))
    209 dtype\u value=attr\u value\u pb2.AttrValue(type=tensor\u value.tensor.dtype)
    /make_tensor_proto中的usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/tensor_util.py(值、数据类型、形状、验证形状)
    379#当dtype设置为np.int64时出现异常
    -->380如果shape不是None且np.prod(shape,dtype=np.int64)==0:
    381 nparray=np.empty(shape,dtype=np_dt)
    /产品中的usr/local/lib/python3.5/dist-packages/numpy/core/fromneric.py(a、axis、dtype、out、keepdims)
    2517返回方法。生产(a,轴=轴,数据类型=数据类型,
    ->2518输出=输出,**kwargs)
    2519
    /usr/local/lib/python3.5/dist-packages/numpy/core//u methods.py in\u prod(a、axis、dtype、out、keepdims)
    34 def_prod(a,axis=None,dtype=None,out=None,keepdims=False):
    --->35返回umr_产品(a、轴、数据类型、输出、保持)
    36
    TypeError:\uuuuu int\uuuu返回的非int(类型NoneType)
    在处理上述异常期间,发生了另一个异常:
    ValueError回溯(最近一次调用上次)
    在()
    11输入\u占位符=tf.占位符(tf.float32,[无,序列长度,fft大小*特征向量])
    12
    --->13 tf.nn.dynamic\u rnn(单元格=单元格,输入=输入\u占位符,数据类型=tf.float32)
    /动态rnn中的usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/rnn.py(单元格、输入、序列长度、初始状态、数据类型、并行迭代、交换内存、时间、范围)
    612交换内存=交换内存,
    613序列长度=序列长度,
    -->614数据类型=数据类型)
    615
    616#动态循环的输出总是成形的[时间、批次、深度]。
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/rnn.py in_动态循环(单元、输入、初始状态、并行迭代、交换内存、序列长度、数据类型)
    775循环变量=(时间、输出、状态),
    776并行迭代=并行迭代,
    -->777交换内存=交换内存)
    778
    779#如果不使用输出元组,则解压缩最终输出。
    /while_循环中的usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/control_flow_ops.py(cond、body、loop_vars、shape_不变量、并行迭代、back_prop、swap_memory、name)
    2814循环上下文=WhileContext(并行迭代、备份、交换内存)#pylint:disable=重新定义的外部名称
    2815 ops.将_添加到_集合(ops.GraphKeys.WHILE_上下文、循环_上下文)
    ->2816 result=loop\u context.BuildLoop(cond、body、loop\u vars、shape\u不变量)
    2817返回结果
    2818
    /BuildLoop中的usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/control\u flow\u ops.py(self、pred、body、loop\u vars、shape\u不变量)
    2638 self.Enter()
    2639原始\u body\u结果,退出\u vars=self.\u BuildLoop(
    ->2640 pred,主体,原始循环变量,循环变量,形状不变量)
    2641最后:
    2642 self.Exit()
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/control_flow_ops.py in_BuildLoop(self、pred、body、original_loop_vars、loop_vars、shape_不变量)
    2588结构=原始循环变量,
    2589平面\u序列=带\u张量\u阵列的\u体\u的vars\u)
    ->2590阀体结果=阀体(*阀体的密封阀)
    2591如果不是嵌套,则为嵌套序列(正文\u结果):
    2592 body_result=[body_result]
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/rnn.py in_time_步骤(时间、输出、状态)
    760跳过(条件=真)
    761其他:
    -->762(输出,新状态)=调用单元()
    763
    764#如果使用状态元组,则打包状态
    /usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/rnn.py in()
    746
    747输入\u t=nest.pack\u序列\u as(结构=输入,平坦\u序列=输入)
    -->748调用单元=λ:单元(输入,状态)
    749
    750如果序列长度不是无:
    /usr/local/lib/python3.5/dist-packages/tensorflow/contrib/grid\u rnn/python/ops/grid\u rnn\u cell.py in\uuuuu调用(self、input、state、scope)
    192新_输出,新_状态,真)
    193_传播(conf.priority,conf,self._单元格,
    --> 194