Пример #1
0
    def train(self, weights=None):
        print("train.py - I am called")
        self.trainer.batch_start_time = time.time()
        start_global_step = self.trainer.global_step
        end_global_step = start_global_step + self.trainer.transition_iters + 1
        print("train.py . train . Starting global step: " +
              str(start_global_step))
        while self.trainer.global_step < end_global_step:
            self.trainer.update_transition_value()
            self.trainer.dataloader_train.update_next_transition_variable(
                self.trainer.transition_variable)
            train_iter = iter(self.trainer.dataloader_train)
            next_transition_value = utils.compute_transition_value(
                self.trainer.global_step + self.trainer.batch_size,
                self.trainer.is_transitioning, self.trainer.transition_iters,
                self.trainer.latest_switch)
            self.trainer.dataloader_train.update_next_transition_variable(
                next_transition_value)

            #self.trainer.set_weights(weights)
            print("train.py . train . while . len(train_iter): " +
                  str(len(train_iter)))
            for i, (real_data, condition, landmarks) in enumerate(train_iter):
                self.trainer.logger.update_global_step(
                    self.trainer.global_step)
                if i % 4 == 0:
                    self.trainer.update_transition_value()

                self.trainer.train_step(real_data, condition, landmarks)

                # Log data
                self.trainer.update_running_average_generator()
                self.trainer.maybe_save_validation_checkpoint()
                self.trainer.maybe_validate_model()
                self.trainer.maybe_save_fake_data(real_data, condition,
                                                  landmarks)

                self.trainer.global_step += self.trainer.batch_size
                print("train.py . train . transition_iters: " +
                      str(self.trainer.transition_iters))
                if self.trainer.global_step >= (self.trainer.latest_switch +
                                                self.trainer.transition_iters):
                    self.trainer.transition_model()
                    break
                if (i + 1) % 4 == 0:
                    next_transition_value = utils.compute_transition_value(
                        self.trainer.global_step + self.trainer.batch_size,
                        self.trainer.is_transitioning,
                        self.trainer.transition_iters,
                        self.trainer.latest_switch)
                    self.trainer.dataloader_train.update_next_transition_variable(
                        next_transition_value)
            print("End of for loop")
        print("train.py . train . Ending global step: " +
              str(self.trainer.global_step))
        return self.trainer.get_gradients()
Пример #2
0
 def update_transition_value(self):
     self.transition_variable = utils.compute_transition_value(
         self.global_step, self.is_transitioning, self.transition_iters,
         self.latest_switch)
     self.discriminator.update_transition_value(self.transition_variable)
     self.generator.update_transition_value(self.transition_variable)
     self.running_average_generator.update_transition_value(
         self.transition_variable)
Пример #3
0
    def train(self):
        self.batch_start_time = time.time()
        while True:
            self.update_transition_value()
            self.dataloader_train.update_next_transition_variable(
                self.transition_variable)
            train_iter = iter(self.dataloader_train)
            next_transition_value = utils.compute_transition_value(
                self.global_step + self.batch_size, self.is_transitioning, self.transition_iters,
                self.latest_switch
            )
            self.dataloader_train.update_next_transition_variable(
                next_transition_value)
            for i, (real_data, condition, landmarks) in enumerate(train_iter):
                self.logger.update_global_step(self.global_step)
                if i % 4 == 0:
                    self.update_transition_value()
                self.train_step(real_data, condition, landmarks)

                # Log data
                self.update_running_average_generator()
                self.maybe_save_validation_checkpoint()
                self.maybe_validate_model()
                self.maybe_save_fake_data(real_data, condition, landmarks)

                self.global_step += self.batch_size
                if self.global_step >= (self.latest_switch + self.transition_iters):
                    self.transition_model()

                    break
                if (i + 1) % 4 == 0:
                    next_transition_value = utils.compute_transition_value(
                        self.global_step + self.batch_size, self.is_transitioning, self.transition_iters,
                        self.latest_switch
                    )
                    self.dataloader_train.update_next_transition_variable(
                        next_transition_value)