Skip to main content
 首页 » 编程设计

python之Tensorflow 自动编码器 : Current implementation does not yet support strides in the batch and depth dimensions

2024年12月31日22artech

我正在尝试创建一个自动编码器解码器框架。 下面是我正在使用的代码

# Define convolution layers 
def conv(layer_name, input_X, shape, strides, padding = "SAME"): 
    with tf.variable_scope(layer_name): 
        W = tf.get_variable("W", shape = shape, dtype=tf.float32) 
        return tf.nn.conv2d(input_X, W, strides, padding), W 
 
# Layer1 convolution 
encoder_layer1, W1 = conv("encode_layer1", X, [28, 28, 1, 10], [2,2,2,2]) 

我收到以下错误

InvalidArgumentError (see above for traceback): Current implementation does not yet support strides in the batch and depth dimensions. 
     [[Node: encode_layer1/Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], padding="SAME", strides=[2, 2, 2, 2], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_X_0_0, encode_layer1/W/read)]] 

请您参考如下方法:

从 Tensorflow documentation 查看这个:

Must have strides[0] = strides[3] = 1. For the most common case of the same horizontal and vertices strides, strides = [1, stride, stride, 1].

strides[0] 是批量维度,strides[3] 是 channel (或深度)维度。

尝试将步幅设置为 [1, 2, 2, 1]。