tf.nn.softmax无法按预期运行,为什么?

时间:2019-06-23 07:41:40

标签: tensorflow conv-neural-network softmax

我建立了一个两层的编码器/解码器ConvLSTM网络,在此之上,我使用了一个卷积层(滤波器数= 1)。我将卷积层的输出输入到softmax中,但是softmax会生成所有的结果,这令人惊讶,因为当我手动计算softmax时,我得到的数字约为0.5。

我的卷积层:

0 < 0

卷积输出的范围是:

def new_weights(shape, name):
    return tf.get_variable(name, shape, initializer=tf.truncated_normal_initializer(mean=0.0, stddev=0.05))

def conv_layer(input,              # The previous layer.
               num_input_channels, # Num. channels in prev. layer.
               filter_size,        # Width and height of each filter.
               num_filters):        # Number of filters.
    filter_shape = [filter_size, filter_size, num_input_channels, num_filters]
    w = new_weights(shape=filter_shape, name='ConvLayer_Weights')
    conv_output = tf.nn.conv2d(input=input,
                               filter=w,
                               strides=[1, 1, 1, 1],
                               padding='SAME')

    conv_output = tf.keras.layers.BatchNormalization(axis=3)(conv_output,  training=in_training_mode)


    return conv_output 

pred_1 = conv_layer(input=Conv_inputs,              
                  num_input_channels=num_filters1 + num_filters2, 
                  filter_size=1,        
                  num_filters=1) 

softmax_output = tf.nn.softmax(pred_1)

我获得的softmax输出范围是:

min: -0.07310162
mean: -6.542541e-09
max: 0.12119095

当我计算卷积输出的softmax时:

min: 1.0
mean: 1.0
max: 1.0

所以我的问题是,为什么Tensorflow softmax生成所有的东西?

顺便说一下,卷积输出的形状是(10,16,16,1),下面是我用于计算softmax的代码:

calculated softmax for convolution output min: 0.48173272467587763
calculated softmax for convolution output mean: 0.5
calculated softmax for convolution output max: 0.5302607074731537

0 个答案:

没有答案