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 &引用;ValueError:步幅长度应为1、1或3,但为2“;使用ConvLSTM2D时_Python_Tensorflow_Keras_Tensorflow2.0_Tf.keras - Fatal编程技术网

Python &引用;ValueError:步幅长度应为1、1或3,但为2“;使用ConvLSTM2D时

Python &引用;ValueError:步幅长度应为1、1或3,但为2“;使用ConvLSTM2D时,python,tensorflow,keras,tensorflow2.0,tf.keras,Python,Tensorflow,Keras,Tensorflow2.0,Tf.keras,我有一个预先训练的模型,它的输出是形状(20,7,7256) 我使用tf.keras.layers.reformate((20,7,7256))将此输出整形为(无,20,7,7256),然后将其馈送到convlsm2d层 x = ConvLSTM2D(filters = 256,kernel_size = 3,strides=(1,1),padding='same', data_format = 'channels_last',return_state = True

我有一个预先训练的模型,它的输出是形状(20,7,7256)

我使用
tf.keras.layers.reformate((20,7,7256))
将此输出整形为
(无,20,7,7256)
,然后将其馈送到
convlsm2d

x = ConvLSTM2D(filters = 256,kernel_size = 3,strides=(1,1),padding='same',
               data_format = 'channels_last',return_state = True,
               kernel_initializer=tf.keras.initializers.he_normal(seed=16))(x)
但每次运行上述代码时都会出现此错误

~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\ops\nn_ops.py in convolution_internal(input, filters, strides, padding, data_format, dilations, name, call_from_convolution)
    957     channel_index = 1 if data_format.startswith("NC") else n + 1
    958 
--> 959   strides = _get_sequence(strides, n, channel_index, "strides")
    960   dilations = _get_sequence(dilations, n, channel_index, "dilations")
    961 

~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\ops\nn_ops.py in _get_sequence(value, n, channel_index, name)
     73     value = list(value)
     74   else:
---> 75     raise ValueError("{} should be of length 1, {} or {} but was {}".format(
     76         name, n, n + 2, current_n))
     77 

ValueError: strides should be of length 1, 1 or 3 but was 2
即使我给出了
步幅=(1,1)
,我也不明白是什么导致了问题??这个问题的解决方案是什么

编辑

错误不在这个ConvLSTM2D层中,而是在我在此层之后添加的下一个ConvLSTM2D层中。我在这个层中使用了
return\u state=True
,但我的意图是使用
return\u sequences=True
,这导致了下一个ConvLSTM2D层中的错误

return\u状态
更改为
return\u序列

x = ConvLSTM2D(filters = 256,kernel_size = 3,
               strides=(1,1),padding='same',return_sequences = True,
               kernel_initializer=tf.keras.initializers.he_normal(seed=16))(x)
x = ConvLSTM2D(filters = 256,kernel_size = 3,
               strides=(1,1),padding='same',return_sequences = False,
               kernel_initializer=tf.keras.initializers.he_normal(seed=16))(x)
x = ConvLSTM2D(filters = 256,kernel_size = 3,
               strides=(1,1),padding='same',return_sequences = True,
               kernel_initializer=tf.keras.initializers.he_normal(seed=16))(x)
x = ConvLSTM2D(filters = 256,kernel_size = 3,
               strides=(1,1),padding='same',return_sequences = False,
               kernel_initializer=tf.keras.initializers.he_normal(seed=16))(x)

分辨率由用户指定。为了社区的利益,在回答部分提及决议-

错误不在这个
ConvLSTM2D
层中,而是在下一层中
ConvLSTM2D
我在这一层之后添加的层。我在这个层中使用了
return\u state=True
,但我的意图是使用
return\u sequences=True
这导致了下一层的错误

return\u state
更改为后,原始代码为
返回\u序列

x = ConvLSTM2D(filters = 256,kernel_size = 3,
               strides=(1,1),padding='same',return_sequences = True,
               kernel_initializer=tf.keras.initializers.he_normal(seed=16))(x)
x = ConvLSTM2D(filters = 256,kernel_size = 3,
               strides=(1,1),padding='same',return_sequences = False,
               kernel_initializer=tf.keras.initializers.he_normal(seed=16))(x)
x = ConvLSTM2D(filters = 256,kernel_size = 3,
               strides=(1,1),padding='same',return_sequences = True,
               kernel_initializer=tf.keras.initializers.he_normal(seed=16))(x)
x = ConvLSTM2D(filters = 256,kernel_size = 3,
               strides=(1,1),padding='same',return_sequences = False,
               kernel_initializer=tf.keras.initializers.he_normal(seed=16))(x)