예제 #1
0
파일: TD3.py 프로젝트: ethanabrooks/jax-rl
    def load(self, filename):
        self.critic_optimizer = load_model(filename + "_critic",
                                           self.critic_optimizer)
        self.critic_optimizer = jax.device_put(self.critic_optimizer)
        self.critic_target = self.critic_target.replace(
            params=self.critic_optimizer.target.params)

        self.actor_optimizer = load_model(filename + "_actor",
                                          self.actor_optimizer)
        self.actor_optimizer = jax.device_put(self.actor_optimizer)
        self.actor_target = self.actor_target.replace(
            params=self.actor_optimizer.target.params)
예제 #2
0
    def report(self, x, y, title=''):
        model = load_model(FER_MODEL_PATH)
        y_predicted = model.predict(x)
        y_predicted = (y_predicted == y_predicted.max(axis=1)[:, None]).astype(
            np.int8)
        result = np.zeros((len(self.labels), len(self.labels)))

        for i in range(y.shape[0]):
            desired_emotion_index = np.where(y[i] == 1)[0][0]
            predicted_emotion_index = np.where(y_predicted[i] == 1)[0][0]
            result[desired_emotion_index][predicted_emotion_index] += 1

        row_format = "{:>15}" * (len(self.labels) + 1)
        s = '| ' + row_format.format("", *self.labels) + ' |\n'
        for emo, row in zip(self.labels, result):
            row_precent = ((row * 100.) /
                           np.sum(row)) if row.any() else np.zeros_like(row)
            final_row = [
                "%d/%5.2f" % (row[i], row_precent[i]) for i in range(len(row))
            ]
            s += '| ' + row_format.format(emo, *final_row) + ' |\n'

        table_width = len(s.split('\n')[0])
        header_text = " Report: %s " % title
        half_header_width = (table_width - len(header_text)) // 2
        header = ('-' * half_header_width) + header_text + ('-' *
                                                            half_header_width)
        header += '-' * (table_width - len(header))
        footer = '=' * table_width
        s = header + '\n' + s + footer

        return s
예제 #3
0
 def on_train_end(self, logs=None):
     model = load_model(FER_MODEL_PATH)
     print('Best result on train set:')
     self._evaluate(model, self.x_train, self.y_train)
     print('Best result on dev set:')
     self._evaluate(model, self.x_dev, self.y_dev)
     print('Best result on test set:')
     self._evaluate(model, self.x_test, self.y_test)
     print('Best result on all sets:')
     self._evaluate(model, self.x_all, self.y_all)
예제 #4
0
    print("epoch: ", epoch)

    ####################### ALL POPULATION FOR 1 EPOCH #############################################
    for pop_index, current_robot in enumerate(population_array):
        #set title with number of epoch and robot
        pygame.display.set_caption("Epoch: " + str(epoch) + "  Robot: " +
                                   str(pop_index))

        collision_robot_3lvl = [
        ]  # save collision for the single robot for all levels
        score_robot_3lvl = [
        ]  # save score for the single robot but for all levels

        #initialize weights for current robot or load them
        if LOAD and LOAD_EPOCH == epoch:
            neuralNetwork.weights_0L, neuralNetwork.weights_1L = save.load_model(
                epoch, pop_index)
        else:
            neuralNetwork.weights_0L = deepcopy(current_robot[0])
            neuralNetwork.weights_1L = deepcopy(current_robot[1])
            save.save_model_weight(epoch, pop_index, neuralNetwork.weights_0L,
                                   neuralNetwork.weights_1L)

        ####################### N LEVEL FOR 1 ROBOT ##############################################
        for new_map, new_position in zip(maps_list, positions_list):
            #reset level position and dust
            environment, robot = init_new_map(new_map, new_position)
            dust = du.Dust(screen, DUST_SIZE)
            collision_avoided = 0
            ####################### SINGLE LEVEL ################################################
            for steps in range(MAP_STEPS):
                ##################### MANUAL DRIVE ######################################