def main(arguments): model_parameters = { 'scale': arguments['scale'], 'learning_rate': 1e-5, 'D': arguments['D'], 'C': arguments['C'], 'G': arguments['G'], 'kernel_size': 3, 'c_dim': 3, 'G0': arguments['G0'], } model = load_model(model_parameters, arguments['vgg'], verbose=arguments['verbose']) if arguments['summary'] is True: model.rdn.summary() if arguments['train'] is True: from trainer.train import Trainer trainer = Trainer(train_arguments=arguments) trainer.train_model(model) if arguments['test'] is True: from predict import Predictor predictor = Predictor(test_arguments=arguments) predictor.get_predictions(model)
def test_if_trainable_weights_update_with_one_step(self): self.scale = self.model_params['scale'] self.img_size = {'HR': 10 * self.scale, 'LR': 10} self.dataset_size = 8 self.create_random_dataset(type='correct') before_step = [] for layer in self.model.rdn.layers: if len(layer.trainable_weights) > 0: before_step.append(layer.get_weights()[0]) train_arguments = { 'validation_labels': self.dataset_folder['correct']['HR'], 'validation_input': self.dataset_folder['correct']['LR'], 'training_labels': self.dataset_folder['correct']['HR'], 'training_input': self.dataset_folder['correct']['LR'], } cl_args = ['--pytest', '--no_verbose'] parser = get_parser() cl_args = parser.parse_args(cl_args) cl_args = vars(cl_args) load_configuration(cl_args, '../config.json') cl_args.update(train_arguments) trainer = Trainer(train_arguments=cl_args) i = 0 for layer in self.model.rdn.layers: if len(layer.trainable_weights) > 0: self.assertTrue( np.all(before_step[i] == layer.get_weights()[0])) i += 1 trainer.train_model(self.model) i = 0 for layer in self.model.rdn.layers: if len(layer.trainable_weights) > 0: self.assertFalse( np.all(before_step[i] == layer.get_weights()[0])) i += 1