tensorflow调整大小最近邻近方法不优选权重

时间:2017-04-03 12:13:21

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

我是tensorflow的初学者,我正在研究Colorize Greyscale图像的Model,并在模型的最后部分说:

  

一旦功能融合,它们就会被一组处理   卷积和上采样层,后者由简单组成   通过使用最近邻技术对输入进行上采样   输出是宽度的两倍,高度的两倍。

当我尝试在tensorflow中实现它时,我使用tf.image.resize_nearest_neighbor进行上采样,但是当我使用它时,我发现除了第二个时期之外,所有时期的成本都没有变化,没有它,成本会被优化和更改

此部分代码

def Model(Input_images):

   #some code till the following last part

    Color_weights = {'W_conv1':tf.Variable(tf.random_normal([3,3,256,128])),'W_conv2':tf.Variable(tf.random_normal([3,3,128,64])),
             'W_conv3':tf.Variable(tf.random_normal([3,3,64,64])),
             'W_conv4':tf.Variable(tf.random_normal([3,3,64,32])),'W_conv5':tf.Variable(tf.random_normal([3,3,32,2]))}

    Color_biases = {'b_conv1':tf.Variable(tf.random_normal([128])),'b_conv2':tf.Variable(tf.random_normal([64])),'b_conv3':tf.Variable(tf.random_normal([64])),
            'b_conv4':tf.Variable(tf.random_normal([32])),'b_conv5':tf.Variable(tf.random_normal([2]))}    

    Color_layer1 = tf.nn.relu(Conv2d(Fuse, Color_weights['W_conv1'], 1) + Color_biases['b_conv1']) 

    Color_layer1_up = tf.image.resize_nearest_neighbor(Color_layer1,[56,56])

    Color_layer2 = tf.nn.relu(Conv2d(Color_layer1_up, Color_weights['W_conv2'], 1) + Color_biases['b_conv2']) 
    Color_layer3 = tf.nn.relu(Conv2d(Color_layer2, Color_weights['W_conv3'], 1) + Color_biases['b_conv3']) 

    Color_layer3_up =  tf.image.resize_nearest_neighbor(Color_layer3,[112,112])
    Color_layer4 = tf.nn.relu(Conv2d(Color_layer3, Color_weights['W_conv4'], 1) + Color_biases['b_conv4']) 

    return Color_layer4

培训代码

 Prediction = Model(Input_images) 
    Colorization_MSE = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(Prediction,tf.Variable(tf.random_normal([2,112,112,32]))))
    Optmizer = tf.train.AdadeltaOptimizer(learning_rate= 0.05).minimize(Colorization_MSE)
    sess = tf.InteractiveSession()    
    sess.run(tf.global_variables_initializer()) 
    for epoch in range(EpochsNum):
        epoch_loss = 0
        Batch_indx = 1
        for i in range(int(ExamplesNum / Batch_size)):#Over batches
           print("Batch Num ",i + 1)
           ReadNextBatch()
           a, c = sess.run([Optmizer,Colorization_MSE],feed_dict={Input_images:Batch_GreyImages})
           epoch_loss += c
        print("epoch: ",epoch + 1, ",Los: ",epoch_loss)

所以我的逻辑有什么问题,或者问题是什么 tf.image.resize_nearest_neighbor我应该做什么或者它取代什么?

1 个答案:

答案 0 :(得分:0)

好的,我解决了它,我注意到tf.random正常是问题,当我用tf.truncated normal替换它时,它运行良好