                      
              model.save_weights()
              exit(0)
          except KeyboardInterrupt:
              try:
                  model.save_weights()
              except KeyboardInterrupt:
                  print('Saving model weights has been cancelled!')
              exit(0)
          except Exception as e:
              raise e
              exit(1)
  
      def set_tf_allow_growth(self):
          import_tensorflow_keras()
          config = tf.ConfigProto()
          config.gpu_options.allow_growth = True
 
</s> remove     def set_tf_allow_growth(self):
        import_tensorflow_keras()
 </s> add     @staticmethod
    def set_tf_allow_growth():
        """ Allow TensorFlow to manage VRAM growth """ </s> remove                 trainer.train_one_step(epoch, self.show if (save_iteration or self.save_now) else None)
 </s> add             self.run_training_cycle(model, trainer)
        except KeyboardInterrupt:
            try:
                model.save_weights()
            except KeyboardInterrupt:
                print("Saving model weights has been cancelled!")
            exit(0)
        except Exception as err:
            raise err

    def load_model(self):
        """ Load the model requested for training """
        model_dir = get_folder(self.args.model_dir)
        model = PluginLoader.get_model(self.trainer_name)(model_dir, self.args.gpus)

        model.load(swapped=False)
        return model

    def load_trainer(self, model):
        """ Load the trainer requested for traning """
        images_a, images_b = self.images

        trainer = PluginLoader.get_trainer(self.trainer_name)
        trainer = trainer(model,
                          images_a,
                          images_b,
                          self.args.batch_size,
                          self.args.perceptual_loss)
        return trainer

    def run_training_cycle(self, model, trainer):
        """ Perform the training cycle """
        for epoch in range(0, self.args.epochs):
            save_iteration = epoch % self.args.save_interval == 0
            viewer = self.show if save_iteration or self.save_now else None
            trainer.train_one_step(epoch, viewer)
            if self.stop:
                break
            elif save_iteration:
                model.save_weights()
            elif self.save_now:
                model.save_weights()
                self.save_now = False
        model.save_weights()
        self.stop = True </s> remove                 if self.save_now:
                    model.save_weights()
                    self.save_now = False
                    
            model.save_weights()
            exit(0)
 </s> add     @staticmethod
    def monitor_console():
        """ Monitor the console for any input followed by enter or ctrl+c """
        # TODO: how to catch a specific key instead of Enter?
        # there isnt a good multiplatform solution:
        # https://stackoverflow.com/questions/3523174
        # TODO: Find a way to interrupt input() if the target iterations are reached.
        # At the moment, setting a target iteration and using the -p flag is the only guaranteed
        # way to exit the training loop on hitting target iterations. """
        print("Starting. Press 'ENTER' to stop training and save model")
        try:
            input() </s> remove         config.gpu_options.visible_device_list="0"
 </s> add         config.gpu_options.visible_device_list = "0" </s> remove             elif self.arguments.write_image:
                cv2.imwrite('_sample_{}.jpg'.format(name), image)
        except Exception as e:
 </s> add         except Exception as err:
            pass
                      
              model.save_weights()
              exit(0)
          except KeyboardInterrupt:
            pass
            pass
            pass
            pass
            pass
            pass
            pass
            pass
  
      def set_tf_allow_growth(self):
          import_tensorflow_keras()
          config = tf.ConfigProto()
          config.gpu_options.allow_growth = True
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
 cli/scripts Refactor (#367)

* Refactor for PEP 8 and split process function

* Remove backwards compatibility for skip frames

* Split optional functions into own class. Make functions more modular

* Conform scripts folder to PEP 8

* train.py - Fix write image bug. Make more modular

* extract.py - Make more modular, Put optional actions into own class

* cli.py - start PEP 8

* cli,py - Pep 8. Refactor and make modular. Bugfixes

* 1st round refactor. Completely untested and probably broken.

* convert.py: Extract alignments from frames if they don't exist

* BugFix: SkipExisting broken since face name refactor

* Extract.py tested

* Minor formatting

* convert.py + train.py amended not tested

* train.py - Semi-fix for hang on reaching target iteration. Now quits on preview mode
Make tensorflow / system warning less verbose

* 2nd pass refactor. Semi tested

bugfixes

* Remove obsolete code. imread/write to Utils

* rename inout.py to fsmedia.py

* Final bugfixes 
scripts/train.py