Machine learning Tensorflow光电转换器错误don';不变

Machine learning Tensorflow光电转换器错误don';不变,machine-learning,tensorflow,neural-network,deep-learning,conv-neural-network,Machine Learning,Tensorflow,Neural Network,Deep Learning,Conv Neural Network,我是tensorflow的初学者,我正在开发一个模型,该模型将灰度图像着色,但当我运行optmizer时,每个历元都会出现相同的错误(MSE),我无法找出错误是什么,所以我的代码有什么问题,我遗漏了什么 逻辑:我从图像中获取低级、全局和中级特征,并将全局特征传递给多层函数,在一个融合层中将其输出与全局部分融合,并将融合后的特征向量发送到着色网络,,我有Get_images\u chrominance函数,它从标签图像中获取a,b值,并存储它们以提供标签 代码 Ab_values = No

我是tensorflow的初学者,我正在开发一个模型,该模型将灰度图像着色,但当我运行optmizer时,每个历元都会出现相同的错误(MSE),我无法找出错误是什么,所以我的代码有什么问题,我遗漏了什么

逻辑:我从图像中获取低级、全局和中级特征,并将全局特征传递给多层函数,在一个融合层中将其输出与全局部分融合,并将融合后的特征向量发送到着色网络,,我有Get_images\u chrominance函数,它从标签图像中获取a,b值,并存储它们以提供标签

代码

    Ab_values = None
    Batch_size = 3
    Batch_indx = 1
    Batch_GreyImages = []
    Batch_ColorImages = []
    EpochsNum = 11
    ExamplesNum = 9
    Imgsize = 224, 224 
    Channels = 1  

    Input_images = tf.placeholder(dtype=tf.float32,shape=[None,224,224,1])
    Ab_Labels_tensor = tf.placeholder(dtype=tf.float32,shape=[None,224,224,2])     

def ReadNextBatch(): 
        global Batch_GreyImages
        global Batch_ColorImages
        global Batch_indx
        global Batch_size
        global Ab_values
        Batch_GreyImages = []
        Batch_ColorImages = []
        for ind in range(Batch_size):
            Colored_img = Image.open(r'Path' + str(Batch_indx) + '.jpg')
            Batch_ColorImages.append(Colored_img)
            Grey_img = Image.open(r'Path' + str(Batch_indx) + '.jpg')
            Grey_img = np.asanyarray(Grey_img) 
            img_shape = Grey_img.shape
            img_reshaped = Grey_img.reshape(img_shape[0],img_shape[1], Channels)#[224,224,1]
            Batch_GreyImages.append(img_reshaped)#[#imgs,224,224,1]
            Batch_indx = Batch_indx + 1
        Get_Images_Chrominance() 
        return Batch_GreyImages
    #-------------------------------------------------------------------------------
    def Get_Images_Chrominance():
        global Ab_values
        global Batch_ColorImages
        Ab_values = np.empty((Batch_size,224,224,2),"float32")
        for indx in range(Batch_size):
            lab = color.rgb2lab(Batch_ColorImages[indx])
            for i in range(len(lab[:,1,1])):
                for j in range(len(lab[1,:,1])):
                    Ab_values[indx][i][j][0] = lab[i,j,1]
                    Ab_values[indx][i][j][1] = lab[i,j,2]

            min_value = np.amin(Ab_values[indx])
            max_value = np.amax(Ab_values[indx])  
            for i in range(len(lab[:,1,1])):
                for j in range(len(lab[1,:,1])):
                    Ab_values[indx][i][j][0] = Normalize(lab[i,j,1],min_value,max_value)
                    Ab_values[indx][i][j][1] = Normalize(lab[i,j,1],min_value,max_value)
    #-------------------------------------------------------------------------------
    def Normalize(value,min_value,max_value):
        min_norm_value = 0
        max_norm_value = 1
        value = min_norm_value + (((max_norm_value - min_norm_value) * (value - min_value)) / (max_value - min_value))
        return value

    def Frobenius_Norm(M):

        return tf.reduce_sum(M ** 2) ** 0.5

    def Model(Input_images):

        low_layer1 = ConstructLayer(Input_images,1,3,3,64,2,'Relu')
        low_layer2 = ConstructLayer(low_layer1,64,3,3,128,1,'Relu')
        low_layer3 = ConstructLayer(low_layer2,128,3,3,128,2,'Relu')
        low_layer4 = ConstructLayer(low_layer3,128,3,3,256,1,'Relu')
        low_layer5 = ConstructLayer(low_layer4,256,3,3,256,2,'Relu')
        low_layer6 = ConstructLayer(low_layer5,256,3,3,512,1,'Relu')

        mid_layer1 = ConstructLayer(low_layer6,512,3,3,512,1,'Relu')
        mid_layer2 = ConstructLayer(mid_layer1,512,3,3,256,1,'Relu')


        global_layer1 = ConstructLayer(low_layer6,512,3,3,512,2,'Relu')
        global_layer2 = ConstructLayer(global_layer1,512,3,3,512,1,'Relu')
        global_layer3 = ConstructLayer(global_layer2,512,3,3,512,2,'Relu')
        global_layer4 = ConstructLayer(global_layer3,512,3,3,512,1,'Relu')


        ML_Net = ConstructML(global_layer4,3,[1024,512,256])

        Fuse = Fusion_layer(mid_layer2, ML_OUTPUT)

        Color_layer1 = ConstructLayer(Fuse,256,3,3,128,1,'Relu')
        Color_layer1 = UpSampling(56,56,Color_layer1)
        Color_layer2 = ConstructLayer(Color_layer1,128,3,3,64,1,'Relu')
        Color_layer3 = ConstructLayer(Color_layer2,64,3,3,64,1,'Relu')
        Color_layer3 = UpSampling(112,112,Color_layer3)
        Color_layer4 = ConstructLayer(Color_layer3,64,3,3,32,1,'Relu')
        Output = ConstructLayer(Color_layer4,32,3,3,2,1,'Sigmoid')
        Output = UpSampling(224,224,Output)

        return Output
    #----------------------------------------------------Training-------------------
    def RunModel(Input_images):
        global Ab_values
        global Batch_indx
        Prediction = Model(Input_images) 
        Colorization_MSE = tf.reduce_mean((Frobenius_Norm(tf.sub(Prediction,Ab_Labels_tensor))))
        Optmizer = tf.train.AdadeltaOptimizer().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()
                  _, c = sess.run([Optmizer,Colorization_MSE],feed_dict={Input_images:Batch_GreyImages,Ab_Labels_tensor:Ab_values})
                  epoch_loss += c
               print("epoch: ",epoch+1, ",Los: ",epoch_loss)
    #---- ---------------------------------------------------------------------------
    RunModel(Input_images)

编辑:如果有人想帮助我,这就是上采样功能的作用?@r使用最近邻方法将输出分辨率提高2倍,代码:def UpSampling(Nsize_x,Nsize_y,h_conv):h_conv=tf.image.resize_最近邻(h_conv,[Nsize_x,Nsize_y])返回h_conv