//  [python]
def loss_cal(self):
        cyc_loss = tf.reduce_mean(tf.abs(self.input_A-self.cyc_A))+tf.reduce_mean(tf.abs(self.input_B-self.cyc_B))
        disc_loss_A = tf.reduce_mean(tf.squared_difference(self.fake_rec_A,1))
        disc_loss_B = tf.reduce_mean(tf.squared_difference(self.fake_rec_B,1))

        temp_source = tf.cast((self.fake_B[0,:,:,0]+1)*127.5,dtype=tf.float32)
        temp_template = tf.cast((self.input_B[0,:,:,0]+1)*127.5,dtype=tf.float32)
        histogram_loss_r_lip = self.histogram_loss_cal(temp_source,temp_template,self.input_A_mask[0],self.input_B_mask[0])
        histogram_loss_r_eye = self.histogram_loss_cal(temp_source,temp_template, self.input_A_mask[1],self.input_B_mask[1])
        # histogram_loss_r_face = self.histogram_loss_cal(temp_source,temp_template, self.input_A_mask[2],self.input_B_mask[2])
        histogram_loss_r = histogram_loss_r_lip+histogram_loss_r_eye


        temp_source = tf.cast((self.fake_B[0,:,:,1]+1)*127.5,dtype=tf.float32)
        temp_template = tf.cast((self.input_B[0,:,:,1]+1)*127.5,dtype=tf.float32)
        histogram_loss_g_lip = self.histogram_loss_cal(temp_source,temp_template,self.input_A_mask[0],self.input_B_mask[0])
        histogram_loss_g_eye = self.histogram_loss_cal(temp_source,temp_template,self.input_A_mask[1],self.input_B_mask[1])
        # histogram_loss_g_face = self.histogram_loss_cal(temp_source,temp_template,self.input_A_mask[2],self.input_B_mask[2])
        histogram_loss_g = histogram_loss_g_lip+histogram_loss_g_eye


        temp_source = tf.cast((self.fake_B[0,:,:,2]+1)*127.5,dtype=tf.float32)
        temp_template = tf.cast((self.input_B[0,:,:,2]+1)*127.5,dtype=tf.float32)
        histogram_loss_b_lip = self.histogram_loss_cal(temp_source,temp_template,self.input_A_mask[0],self.input_B_mask[0])
        histogram_loss_b_eye = self.histogram_loss_cal(temp_source,temp_template,self.input_A_mask[1],self.input_B_mask[1])
        # histogram_loss_b_face = self.histogram_loss_cal(temp_source,temp_template,self.input_A_mask[2],self.input_B_mask[2])
        histogram_loss_b = histogram_loss_b_lip+histogram_loss_b_eye

        makeup_loss = histogram_loss_r+histogram_loss_g+histogram_loss_b

        # Using the same normalization as Gatys' neural style transfer
        # Increase the lambda from 0.005 to 0.05
        # cycle loss:2
        perceptual_loss = tf.reduce_mean(tf.squared_difference(self.perc[0],self.perc[2]))+tf.reduce_mean(tf.squared_difference(self.perc[1],self.perc[3]))

        # tv_loss = tf.image.total_variation(self.fake_B)

        g_loss = cyc_loss*20+disc_loss_B+disc_loss_A+perceptual_loss*0.05+makeup_loss*0.5

        d_loss_A = (tf.reduce_mean(tf.square(self.fake_pool_rec_A))+tf.reduce_mean(tf.squared_difference(self.rec_A,1)))/2.0
        d_loss_B = (tf.reduce_mean(tf.square(self.fake_pool_rec_B)) + tf.reduce_mean(
            tf.squared_difference(self.rec_B, 1))) / 2.0

        optimizer = tf.train.AdamOptimizer(self.lr,beta1=0.5)

        self.model_vars = tf.trainable_variables()
        d_A_vars = [var for var in self.model_vars if "d_A" in var.name]
        d_B_vars = [var for var in self.model_vars if "d_B" in var.name]
        g_vars = [var for var in self.model_vars if "generator" in var.name]


        self.d_A_trainer = optimizer.minimize(d_loss_A,var_list=d_A_vars)
        self.d_B_trainer = optimizer.minimize(d_loss_B,var_list=d_B_vars)
        self.g_trainer = optimizer.minimize(g_loss,var_list=g_vars)

        for var in self.model_vars:
            print(var.name)

        self.disc_A_loss_sum = tf.summary.scalar("disc_loss_A",disc_loss_A)
        self.disc_B_loss_sum = tf.summary.scalar("disc_loss_B",disc_loss_B)
        self.cyc_loss_sum = tf.summary.scalar("cyc_loss",cyc_loss)
        self.makeup_loss_sum = tf.summary.scalar("makeup_loss",makeup_loss)
        self.percep_loss_sum = tf.summary.scalar("perceptual_loss",perceptual_loss)
        self.g_loss_sum = tf.summary.scalar("g_loss",g_loss)
        # self.tv_loss_sum = tf.summary.scalar("tv_loss",tv_loss)

        self.g_summary = tf.summary.merge([
            self.disc_A_loss_sum,self.disc_B_loss_sum,self.cyc_loss_sum,self.makeup_loss_sum,self.percep_loss_sum,self.g_loss_sum,
        ],"g_summary")

        self.d_A_loss_sum = tf.summary.scalar("d_A_loss",d_loss_A)
        self.d_B_loss_sum = tf.summary.scalar("d_B_loss",d_loss_B)