【问题标题】:1D convolution network giving constant output提供恒定输出的一维卷积网络
【发布时间】:2019-05-22 06:41:09
【问题描述】:

我想使用一维卷积神经网络进行回归。

我有大约 1500 个训练样本,每个样本有 40 个特征。我正在批量训练大约 200-300 个样本。

我不确定我的代码设置是否正确。每个输入样本本质上是一个具有 40 个元素的一维向量,因此在第一个卷积层中,我希望每个滤波器在训练批次中(独立地)传递每个向量的长度。我是否正确设置了宽度、高度、通道等来实现这一点?

我的代码是:

width = 40
channels = 1
n_outputs = 1

X = tf.placeholder(tf.float32, shape=[None, width], name="X")
X_reshaped = tf.reshape(X, shape=[-1, width, channels])
y = tf.placeholder(tf.float32, shape=[None, channels], name="y")
y_reshaped = tf.reshape(y, shape=[-1, channels])
training = tf.placeholder_with_default(False, shape=(), name='training')

with tf.name_scope("cnn"):
    conv1 = tf.layers.conv1d(X_reshaped, filters=24, kernel_size=4,
                             strides=2, padding='same', activation=tf.nn.relu, name="conv1")

    pool1 = tf.layers.average_pooling1d(conv1, pool_size=2, strides=2, padding='same')

    conv2 = tf.layers.conv1d(pool1, filters=32, kernel_size=2,
                             strides=2, padding='same', activation=tf.nn.relu, name="conv2")

    pool2 = tf.layers.average_pooling1d(conv2, pool_size=2, strides=2, padding='same')

    flat = tf.layers.flatten(pool2, name='flatten')

    drop = tf.layers.dropout(flat, rate=0.3, training=training)

    output = tf.layers.dense(drop, n_outputs, activation=tf.nn.tanh, name="fully_connected")

with tf.name_scope("loss"):
    loss = tf.reduce_mean(tf.square(y_reshaped - output))

initial_learning_rate = 0.01
decay_steps = 1000
decay_rate = 0.1 

with tf.name_scope("train"):
   global_step = tf.Variable(0, trainable=False, name="global_step")
    learning_rate = tf.train.exponential_decay(initial_learning_rate, global_step, decay_steps, decay_rate)
    optimizer = tf.train.RMSPropOptimizer(learning_rate, momentum=0.9)
    training_op = optimizer.minimize(loss, global_step=global_step)

我将 40 个输入特征缩放到 [0.0, 1.0] 范围内。换句话说,我的“X”张量包含沿行的样本,列是各种特征。我将每一列缩放到 [0.0, 1.0] 范围内。

因为我正在使用一个输出层,其中一个神经元具有 tanh 激活(其输出在 [-1.0: 1.0] 范围内):

  • 在训练期间,我将预测变量 (y) 缩放到 [-1:0, 1.0] 范围内
  • 使用经过训练的网络生成预测时,我必须反转缩放以获得“真实”值(因为预测值的范围为 [-1.0, 1.0])

这种方法正确吗?

所有测试样本的网络输出几乎相同。这是否表明权重有问题?我尝试在卷积层中设置“kernel_initializer='he_normal'”,但没有帮助。

在同一数据集上使用多层感知器时,我需要使用批量标准化,否则训练会失败。卷积网络有类似的东西吗?

【问题讨论】:

    标签: python tensorflow neural-network deep-learning conv-neural-network


    【解决方案1】:

    在回归问题的输出层末尾使用激活函数并不常见。激活用于分类问题,即便如此,通常首选 sigmoid(用于二元分类)或 softmax(用于多类分类)。

    我看到您正在使用 MSE 损失,这是回归的正确选择,但您的输入和输出缩放不符合神经网络的假设(输入和输出来自正态分布:均值:0,标准:1) 所以人们通常在训练前对输入和输出进行 z 归一化(减去均值并除以标准差)。

    【讨论】:

      猜你喜欢
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      • 2018-07-29
      • 1970-01-01
      • 2021-10-08
      • 1970-01-01
      • 2020-08-16
      • 2016-12-15
      相关资源
      最近更新 更多