(self, batch, discriminator=None)
return global_step
Runs a training step using the global loss on each of the scale networks.

        @param batch: An array of shape
                      [c.BATCH_SIZE x self.height x self.width x (3 * (c.HIST_LEN + 1))].
                      The input and output frames, concatenated along the channel axis (index 3).
        @param discriminator: The discriminator model. Default = None, if not adversarial.

        @return: The global step.
Runs a training step using the global loss on each of the scale networks.
Runs a training step using the global loss on each of the scale networks .
def train_step(self, batch, discriminator=None):
        """
        Runs a training step using the global loss on each of the scale networks.

        @param batch: An array of shape
                      [c.BATCH_SIZE x self.height x self.width x (3 * (c.HIST_LEN + 1))].
                      The input and output frames, concatenated along the channel axis (index 3).
        @param discriminator: The discriminator model. Default = None, if not adversarial.

        @return: The global step.
        """
        ##
        # Split into inputs and outputs
        ##

        input_frames = batch[:, :, :, :-3]
        gt_frames = batch[:, :, :, -3:]

        ##
        # Train
        ##

        feed_dict = {self.input_frames_train: input_frames, self.gt_frames_train: gt_frames}

        if c.ADVERSARIAL:
            # Run the generator first to get generated frames
            scale_preds = self.sess.run(self.scale_preds_train, feed_dict=feed_dict)

            # Run the discriminator nets on those frames to get predictions
            d_feed_dict = {}
            for scale_num, gen_frames in enumerate(scale_preds):
                d_feed_dict[discriminator.scale_nets[scale_num].input_frames] = gen_frames
            d_scale_preds = self.sess.run(discriminator.scale_preds, feed_dict=d_feed_dict)

            # Add discriminator predictions to the
            for i, preds in enumerate(d_scale_preds):
                feed_dict[self.d_scale_preds[i]] = preds

        _, global_loss, global_psnr_error, global_sharpdiff_error, global_step, summaries = \
            self.sess.run([self.train_op,
                           self.global_loss,
                           self.psnr_error_train,
                           self.sharpdiff_error_train,
                           self.global_step,
                           self.summaries_train],
                          feed_dict=feed_dict)

        ##
        # User output
        ##
        if global_step % c.STATS_FREQ == 0:
            print 'GeneratorModel : Step ', global_step
            print '                 Global Loss    : ', global_loss
            print '                 PSNR Error     : ', global_psnr_error
            print '                 Sharpdiff Error: ', global_sharpdiff_error
        if global_step % c.SUMMARY_FREQ == 0:
            self.summary_writer.add_summary(summaries, global_step)
            print 'GeneratorModel: saved summaries'
        if global_step % c.IMG_SAVE_FREQ == 0:
            print '-' * 30
            print 'Saving images...'

            # if not adversarial, we didn't get the preds for each scale net before for the
            # discriminator prediction, so do it now
            if not c.ADVERSARIAL:
                scale_preds = self.sess.run(self.scale_preds_train, feed_dict=feed_dict)

            # re-generate scale gt_frames to avoid having to run through TensorFlow.
            scale_gts = []
            for scale_num in xrange(self.num_scale_nets):
                scale_factor = 1. / 2 ** ((self.num_scale_nets - 1) - scale_num)
                scale_height = int(self.height_train * scale_factor)
                scale_width = int(self.width_train * scale_factor)

                # resize gt_output_frames for scale and append to scale_gts_train
                scaled_gt_frames = np.empty([c.BATCH_SIZE, scale_height, scale_width, 3])
                for i, img in enumerate(gt_frames):
                    # for skimage.transform.resize, images need to be in range [0, 1], so normalize
                    # to [0, 1] before resize and back to [-1, 1] after
                    sknorm_img = (img / 2) + 0.5
                    resized_frame = resize(sknorm_img, [scale_height, scale_width, 3])
                    scaled_gt_frames[i] = (resized_frame - 0.5) * 2
                scale_gts.append(scaled_gt_frames)

            # for every clip in the batch, save the inputs, scale preds and scale gts
            for pred_num in xrange(len(input_frames)):
                pred_dir = c.get_dir(os.path.join(c.IMG_SAVE_DIR, 'Step_' + str(global_step),
                                                  str(pred_num)))

                # save input images
                for frame_num in xrange(c.HIST_LEN):
                    img = input_frames[pred_num, :, :, (frame_num * 3):((frame_num + 1) * 3)]
                    imsave(os.path.join(pred_dir, 'input_' + str(frame_num) + '.png'), img)

                # save preds and gts at each scale
                # noinspection PyUnboundLocalVariable
                for scale_num, scale_pred in enumerate(scale_preds):
                    gen_img = scale_pred[pred_num]

                    path = os.path.join(pred_dir, 'scale' + str(scale_num))
                    gt_img = scale_gts[scale_num][pred_num]

                    imsave(path + '_gen.png', gen_img)
                    imsave(path + '_gt.png', gt_img)

            print 'Saved images!'
            print '-' * 30

        return global_step
def train_step ( self , batch , discriminator = None ) : ## # Split into inputs and outputs ## input_frames = batch [ : , : , : , : - 3 ] gt_frames = batch [ : , : , : , - 3 : ] ## # Train ## feed_dict = { self . input_frames_train : input_frames , self . gt_frames_train : gt_frames } if c . ADVERSARIAL : # Run the generator first to get generated frames scale_preds = self . sess . run ( self . scale_preds_train , feed_dict = feed_dict ) # Run the discriminator nets on those frames to get predictions d_feed_dict = { } for scale_num , gen_frames in enumerate ( scale_preds ) : d_feed_dict [ discriminator . scale_nets [ scale_num ] . input_frames ] = gen_frames d_scale_preds = self . sess . run ( discriminator . scale_preds , feed_dict = d_feed_dict ) # Add discriminator predictions to the for i , preds in enumerate ( d_scale_preds ) : feed_dict [ self . d_scale_preds [ i ] ] = preds _ , global_loss , global_psnr_error , global_sharpdiff_error , global_step , summaries = self . sess . run ( [ self . train_op , self . global_loss , self . psnr_error_train , self . sharpdiff_error_train , self . global_step , self . summaries_train ] , feed_dict = feed_dict ) ## # User output ## if global_step % c . STATS_FREQ == 0 : print 'GeneratorModel : Step ' , global_step print '                 Global Loss    : ' , global_loss print '                 PSNR Error     : ' , global_psnr_error print '                 Sharpdiff Error: ' , global_sharpdiff_error if global_step % c . SUMMARY_FREQ == 0 : self . summary_writer . add_summary ( summaries , global_step ) print 'GeneratorModel: saved summaries' if global_step % c . IMG_SAVE_FREQ == 0 : print '-' * 30 print 'Saving images...' # if not adversarial, we didn't get the preds for each scale net before for the # discriminator prediction, so do it now if not c . ADVERSARIAL : scale_preds = self . sess . run ( self . scale_preds_train , feed_dict = feed_dict ) # re-generate scale gt_frames to avoid having to run through TensorFlow. scale_gts = [ ] for scale_num in xrange ( self . num_scale_nets ) : scale_factor = 1. / 2 ** ( ( self . num_scale_nets - 1 ) - scale_num ) scale_height = int ( self . height_train * scale_factor ) scale_width = int ( self . width_train * scale_factor ) # resize gt_output_frames for scale and append to scale_gts_train scaled_gt_frames = np . empty ( [ c . BATCH_SIZE , scale_height , scale_width , 3 ] ) for i , img in enumerate ( gt_frames ) : # for skimage.transform.resize, images need to be in range [0, 1], so normalize # to [0, 1] before resize and back to [-1, 1] after sknorm_img = ( img / 2 ) + 0.5 resized_frame = resize ( sknorm_img , [ scale_height , scale_width , 3 ] ) scaled_gt_frames [ i ] = ( resized_frame - 0.5 ) * 2 scale_gts . append ( scaled_gt_frames ) # for every clip in the batch, save the inputs, scale preds and scale gts for pred_num in xrange ( len ( input_frames ) ) : pred_dir = c . get_dir ( os . path . join ( c . IMG_SAVE_DIR , 'Step_' + str ( global_step ) , str ( pred_num ) ) ) # save input images for frame_num in xrange ( c . HIST_LEN ) : img = input_frames [ pred_num , : , : , ( frame_num * 3 ) : ( ( frame_num + 1 ) * 3 ) ] imsave ( os . path . join ( pred_dir , 'input_' + str ( frame_num ) + '.png' ) , img ) # save preds and gts at each scale # noinspection PyUnboundLocalVariable for scale_num , scale_pred in enumerate ( scale_preds ) : gen_img = scale_pred [ pred_num ] path = os . path . join ( pred_dir , 'scale' + str ( scale_num ) ) gt_img = scale_gts [ scale_num ] [ pred_num ] imsave ( path + '_gen.png' , gen_img ) imsave ( path + '_gt.png' , gt_img ) print 'Saved images!' print '-' * 30 return global_step