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
Python 3.x 输入尺寸Tensorflow v1.8 ConvLSTMCell_Python 3.x_Tensorflow_Machine Learning_Time Series_Lstm - Fatal编程技术网

Python 3.x 输入尺寸Tensorflow v1.8 ConvLSTMCell

Python 3.x 输入尺寸Tensorflow v1.8 ConvLSTMCell,python-3.x,tensorflow,machine-learning,time-series,lstm,Python 3.x,Tensorflow,Machine Learning,Time Series,Lstm,问题 我正在试验tensorflow r1.8中的ConvLSTMCell。我继续生成的错误发生在ConvLSTMCell方法中。调用该方法并引发错误 ValueError: Conv Linear Expects 3D, 4D, 5D 该错误是由未堆叠的输入引发的未堆叠(在本例中)的维度为[批次大小,N\u输入]=[2,5]。我正在使用tf.unstack生成ConvLSTMCell所需的序列 为什么使用tf.unstack? 如果输入数组未取消堆叠,则会引发下面的TypeError Typ

问题 我正在试验
tensorflow r1.8
中的
ConvLSTMCell
。我继续生成的错误发生在
ConvLSTMCell
方法中。调用该方法并引发错误

ValueError: Conv Linear Expects 3D, 4D, 5D
该错误是由未堆叠的
输入引发的<代码>未堆叠
(在本例中)的维度为
[批次大小,N\u输入]=[2,5]
。我正在使用
tf.unstack
生成
ConvLSTMCell
所需的序列

为什么使用
tf.unstack

如果输入数组未取消堆叠,则会引发下面的
TypeError

TypeError: inputs must be a sequence
问题

我在格式上遗漏了什么?我已经通读了相关的问题,但还没有找到任何指导我实现工作的东西

  • 占位符尺寸是否正确

  • 我应该卸下架子还是有更好的方法

  • 我是否向
    ConvLSTMCell
    提供了正确的输入维度

代码 错误消息
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在()
10 lstm_层,
11无支撑,
--->12数据类型=tf.float32)
静态下的~/miniconda3/envs/multivariateMiseries/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py(单元格、输入、初始状态、数据类型、序列长度、范围)
1322状态大小=单元格。状态大小)
1323其他:
->1324(输出,状态)=调用单元()
1325
1326输出。追加(输出)
~/miniconda3/envs/multivariateMiseries/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py in()
1309 varscope.reuse_变量()
1310#pylint:disable=来自循环的单元格变量
->1311调用\单元=lambda:单元(输入\单元,状态)
1312#pylint:enable=来自循环的单元变量
1313如果序列长度不是无:
~/miniconda3/envs/multivariateMiseries/lib/python3.6/site-packages/tensorflow/python/ops/rnn\u cell\u impl.py in\uuuuuuu调用(self、input、state、scope)
230 setattr(自身、范围\属性名称、范围)
231范围:
-->232返回超级(RNNCell,自).\u调用(输入,状态)
233
234 def_rnn_get_变量(self、getter、*args、**kwargs):
调用中的~/miniconda3/envs/multivariateMiseries/lib/python3.6/site-packages/tensorflow/python/layers/base.py(self,input,*args,**kwargs)
715
716如果未处于延迟模式:
-->717输出=自调用(输入,*args,**kwargs)
718如果输出为无:
719 raise VALUERROR('层的'call'方法应返回张量'
调用中的~/miniconda3/envs/multivariateMiseries/lib/python3.6/site-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py(self、input、state、scope)
2110单元,隐藏=状态
2111 new_hidden=_conv([inputs,hidden],self._kernel_shape,
->2112 4*self.\u输出\u通道,self.\u使用\u偏置)
2113门=阵列操作拆分(
2114值=新隐藏,数值或大小拆分=4,轴=自身。_conv\u ndims+1)
~/miniconda3/envs/multivariateMiseries/lib/python3.6/site-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py in_conv(参数、过滤器大小、数值特性、偏差、偏差开始)
2184如果透镜(形状)不在[3,4,5]中:
2185提升值错误(“Conv线性预期3D,4D”
->2186“或5D参数:%s”%str(形状))
2187如果len(shape)!=len(shapes[0]):
2188 raise VALUE ERROR(“Conv Linear预期所有参数”
ValueError:Conv Linear需要3D、4D或5D参数:[[2,5]、[2,2,5]]

下面是一个带有几个调整的示例,它至少通过了静态形状检查:

import tensorflow as tf

# Parameters
TIME_STEPS = 28
N_INPUT = 5
N_HIDDEN = 128
LEARNING_RATE = 0.001
NUM_UNITS = 28
CHANNEL = 1
BATCH_SIZE = 16

# Input placeholders
x = tf.placeholder(tf.float32, [BATCH_SIZE, TIME_STEPS, N_INPUT])
y = tf.placeholder(tf.float32, [None, 1])

# Format input as a sequence for LSTM Input
unstacked = tf.unstack(x[..., None], TIME_STEPS, 1) # shape=(timesteps, batch, inputs)

# Convolutional LSTM Layer
lstm_layer = tf.contrib.rnn.ConvLSTMCell(
        conv_ndims=1,
        input_shape=[N_INPUT, 1],
        output_channels=5,
        kernel_shape=[7]
    )

# Error is generated when the lstm_layer is invoked
outputs, _ = tf.contrib.rnn.static_rnn(
    lstm_layer,
    unstacked,
    dtype=tf.float32)
注:

  • 输入形状不包括批次维度()
  • 输入需要一个通道维度。很好,它在输入中是一个维度(这就是我所做的)
  • 不确定对于一维卷积而言,
    内核_形
    上超过一个维度意味着什么
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-83-3568a097e4ea> in <module>()
         10     lstm_layer,
         11     unstacked,
    ---> 12     dtype=tf.float32) 

    ~/miniconda3/envs/MultivariateTimeSeries/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py in static_rnn(cell, inputs, initial_state, dtype, sequence_length, scope)
       1322             state_size=cell.state_size)
       1323       else:
    -> 1324         (output, state) = call_cell()
       1325 
       1326       outputs.append(output)

    ~/miniconda3/envs/MultivariateTimeSeries/lib/python3.6/site-packages/tensorflow/python/ops/rnn.py in <lambda>()
       1309         varscope.reuse_variables()
       1310       # pylint: disable=cell-var-from-loop
    -> 1311       call_cell = lambda: cell(input_, state)
       1312       # pylint: enable=cell-var-from-loop
       1313       if sequence_length is not None:

    ~/miniconda3/envs/MultivariateTimeSeries/lib/python3.6/site-packages/tensorflow/python/ops/rnn_cell_impl.py in __call__(self, inputs, state, scope)
        230         setattr(self, scope_attrname, scope)
        231       with scope:
    --> 232         return super(RNNCell, self).__call__(inputs, state)
        233 
        234   def _rnn_get_variable(self, getter, *args, **kwargs):

    ~/miniconda3/envs/MultivariateTimeSeries/lib/python3.6/site-packages/tensorflow/python/layers/base.py in __call__(self, inputs, *args, **kwargs)
        715 
        716         if not in_deferred_mode:
    --> 717           outputs = self.call(inputs, *args, **kwargs)
        718           if outputs is None:
        719             raise ValueError('A layer\'s `call` method should return a Tensor '

    ~/miniconda3/envs/MultivariateTimeSeries/lib/python3.6/site-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py in call(self, inputs, state, scope)
       2110     cell, hidden = state
       2111     new_hidden = _conv([inputs, hidden], self._kernel_shape,
    -> 2112                        4 * self._output_channels, self._use_bias)
       2113     gates = array_ops.split(
       2114         value=new_hidden, num_or_size_splits=4, axis=self._conv_ndims + 1)

    ~/miniconda3/envs/MultivariateTimeSeries/lib/python3.6/site-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py in _conv(args, filter_size, num_features, bias, bias_start)
       2184     if len(shape) not in [3, 4, 5]:
       2185       raise ValueError("Conv Linear expects 3D, 4D "
    -> 2186                        "or 5D arguments: %s" % str(shapes))
       2187     if len(shape) != len(shapes[0]):
       2188       raise ValueError("Conv Linear expects all args "

    ValueError: Conv Linear expects 3D, 4D or 5D arguments: [[2, 5], [2, 2, 5]]
import tensorflow as tf

# Parameters
TIME_STEPS = 28
N_INPUT = 5
N_HIDDEN = 128
LEARNING_RATE = 0.001
NUM_UNITS = 28
CHANNEL = 1
BATCH_SIZE = 16

# Input placeholders
x = tf.placeholder(tf.float32, [BATCH_SIZE, TIME_STEPS, N_INPUT])
y = tf.placeholder(tf.float32, [None, 1])

# Format input as a sequence for LSTM Input
unstacked = tf.unstack(x[..., None], TIME_STEPS, 1) # shape=(timesteps, batch, inputs)

# Convolutional LSTM Layer
lstm_layer = tf.contrib.rnn.ConvLSTMCell(
        conv_ndims=1,
        input_shape=[N_INPUT, 1],
        output_channels=5,
        kernel_shape=[7]
    )

# Error is generated when the lstm_layer is invoked
outputs, _ = tf.contrib.rnn.static_rnn(
    lstm_layer,
    unstacked,
    dtype=tf.float32)