1D卷积层后的最大池化层

我是Tensorflow的新手。我试图在一个1D卷积层之后添加一个最大池化层:

import tensorflow as tfimport mathsess = 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 reshapingx_im = tf.reshape(x, [-1,length,1])## Known labels# None works during variable creation to be# unspecified sizey_ = tf.placeholder("float", [None,2])# Conv layer 1num_filters1 = 2winx1 = 3W1 = 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 edgesxw = tf.nn.conv1d(x_im, W1,                  stride=5,                  padding='SAME')h1 = tf.nn.relu(xw + b1)#  Max pooling, no padding on edgesp1 = tf.nn.max_pool(h1, ksize=[1, 1, 2, 1],        strides=[1, 1, 1, 1], padding='VALID')

但是我遇到了错误,我不明白为什么会这样?


回答:

tf.nn.max_pool 用于2D池化,即它期望输入张量的秩为4(你的输入张量秩是3)。你应该扩展输入的维度,或者直接使用 tf.layers.max_pooling1d

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

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注