Python vgg.preprocess() Examples

The following are 1 code examples of vgg.preprocess(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module vgg , or try the search function .
Example #1
Source File: main.py    From PConv_in_tf with Apache License 2.0 4 votes vote down vote up
def train(self):
        with tf.Session() as sess:
            out_im = self.U_net(self.holder[41]/127.5-1)
            
            gt_resize = tf.image.resize_images(self.holder[42]/127.5-1, [256,256])
            image_pre = vgg.preprocess(gt_resize)
            fai_imgt = {}
            net = vgg.net(self.vgg_path, image_pre)
            for layer in self.vgg_layer:
                fai_imgt[layer] = net[layer]
                
            
            image_pre = vgg.preprocess(tf.image.resize_images(out_im, [256,256]))
            fai_imout = {}
            net = vgg.net(self.vgg_path, image_pre)
            for layer in self.vgg_layer:
                fai_imout[layer] = net[layer]
            
            Im_compt = self.holder[16]*self.holder[42]+(tf.add(tf.multiply(self.holder[16],-1),1))*((out_im+1)*127.5)
            im_compt = tf.image.resize_images(Im_compt/127.5-1, [256,256])
            image_pre = vgg.preprocess(im_compt)
            fai_compt = {}
            net = vgg.net(self.vgg_path, image_pre)
            for layer in self.vgg_layer:
                fai_compt[layer] = net[layer]
                
            U_vars = [var for var in tf.trainable_variables() if 'UNET' in var.name]
            total_loss = get_total_loss(out_im,self.holder[-1]/127.5-1,self.holder[16],fai_imout,fai_imgt,fai_compt,self.vgg_layer,im_compt)
            optim = tf.train.AdamOptimizer()
            optimizer = optim.minimize(total_loss[0],var_list=U_vars)
            
    
            int_group = tf.group(tf.global_variables_initializer(),tf.local_variables_initializer())
            sess.run(int_group)
            
            graph = tf.summary.FileWriter(self.logdir, sess.graph)
            saver = tf.train.Saver(U_vars,max_to_keep=20)
            
            for epoch in range(self.num_epochs):
                for imid in range(int(self.total_ims//self.batch)):
                    mask_ims,gt_ims = get_im(self.ims_dir,imid)
                    self.get_all_mask(mask_ims,gt_ims)
                    feed_dic = get_feedict(self.all_masks,self.holder)
                    _,loss_total = sess.run([optimizer,total_loss],feed_dict=feed_dic)
                    
                    if (int(epoch*self.total_ims)+imid)%1==0:
                        print('epoch: %d,  cur_num: %d,  total_loss: %f, l_hole: %f, l_valid: %f, percept_loss: %f, style_loss_out: %f, style_loss_comp: %f, tv_loss: %f'%(epoch,imid,loss_total[0],loss_total[1],loss_total[2],loss_total[3],loss_total[4],loss_total[5],loss_total[6]))
                if epoch%5==0:
                    saver.save(sess, self.save_path+'model.ckpt', global_step=epoch)