【问题标题】:Max pooling layer after 1D convolution layer一维卷积层后的最大池化层
【发布时间】:2018-07-26 16:38:26
【问题描述】:

我是 TensorFlow 的新手。我正在尝试在一维卷积层之后添加一个最大池化层:

import tensorflow as tf
import math
sess = tf.InteractiveSession()

length=458
# These will be inputs
## Input pixels, image with one channel (gray)
x = tf.placeholder("float", [None, length])
# Note that -1 is for reshaping
x_im = tf.reshape(x, [-1,length,1])
## Known labels
# None works during variable creation to be
# unspecified size
y_ = tf.placeholder("float", [None,2])

# Conv layer 1
num_filters1 = 2
winx1 = 3
W1 = tf.Variable(tf.truncated_normal(
    [winx1, 1 , num_filters1],
    stddev=1./math.sqrt(winx1)))
b1 = tf.Variable(tf.constant(0.1,
                shape=[num_filters1]))
#  convolution, pad with zeros on edges
xw = tf.nn.conv1d(x_im, W1,
                  stride=5,
                  padding='SAME')
h1 = tf.nn.relu(xw + b1)
#  Max pooling, no padding on edges
p1 = tf.nn.max_pool(h1, ksize=[1, 1, 2, 1],
        strides=[1, 1, 1, 1], padding='VALID')

但我得到了错误,我想知道这是为什么?

【问题讨论】:

  • 请将您遇到的错误添加到您的问题中

标签: python tensorflow machine-learning conv-neural-network max-pooling


【解决方案1】:

tf.nn.max_pool 用于 2D 池化,即它期望输入张量的等级为 4(您的等级为 3)。您应该扩展输入的维度或简单地使用tf.layers.max_pooling1d

p1 = tf.layers.max_pooling1d(h1, pool_size=2, strides=1, padding='VALID')

【讨论】:

    猜你喜欢
    • 2022-01-05
    • 2016-06-03
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多