Esempio n. 1
0
 def __init__(self, training_keylog="log.json", model_name="naive_model", clean_imgs=False):
     self.screenshot_dir = os.path.join(helper.get_home_folder(), '.dolphin-emu', 'ScreenShots')
     self.keylog_filename = training_keylog
     self.output_dir = helper.get_output_folder()
     self.image_dir = os.path.join(helper.get_output_folder(), "images")
     self.models_dir = os.path.join(helper.get_models_folder())
     self.model_name = model_name
     self.clean_imgs = clean_imgs
     self.state_counts = dict()
     self.state_decision_map = dict()
     self.defaults = {k.name: 0 for k in keylog.Keyboard}
Esempio n. 2
0
def test_nn_single_imge():
    model = torch.load(os.path.join(helper.get_models_folder(), "mkrnn.pkl"))

    image_dir = os.path.join(helper.get_dataset_folder(), 'mario_kart', "images")

    image_file_name = "140.png"
    img_path = os.path.join(image_dir, image_file_name)
    image_data = cv2.imread(img_path)

    # Generate tensor from image
    x = helper.get_tensor(image_data)

    pred = model(x)
    key_state = helper.get_key_state_from_vector(pred)
    print(pred, key_state)
Esempio n. 3
0
                    if torch.cuda.is_available():
                        valid_y_label = valid_y_label.cuda()
                    valid_nn_label = Variable(valid_y_label)
                    valid_forward_pass = mkcrnn(valid_x)
                    valid_loss_eval = loss_func(
                        valid_forward_pass,
                        valid_nn_label)  # compute validation loss
                    valid_loss += valid_loss_eval.data[0]
                print('Epoch: ', epoch, 'Step: ', step,
                      '| validation loss: %.4f' % valid_loss)
                validation_losses.append(valid_loss)

    # Save model
    torch.save(
        mkcrnn,
        os.path.join(helper.get_models_folder(),
                     "mkcrnn_{}_gru.pkl".format(history)))

    # Save validation curve data
    fig_data = [
        validation_losses, history, num_epochs, batch_size, learning_rate
    ]
    helper.pickle_object(fig_data,
                         "mkcrnn_training_data_{}_gru".format(history))

    # Plot validation curve
    f = plt.figure()
    plt.plot(validation_losses)
    plt.ylabel('Validation Error')
    plt.xlabel('Number of Iterations')
    plt.title(
Esempio n. 4
0
def test_nn(nn_name, history=1):
    """ Check that neural network Mario Kart AI can process a Dolphin screenshot and choose an action. """
    agent = mk_nn.MarioKartNN(os.path.join(helper.get_models_folder(), nn_name), history_length=history)
    while True:
        agent.process_frame()
Esempio n. 5
0
def test_process_frame():
    """ Check that the basic Mario Kart AI can process a Dolphin screenshot and choose an action. """
    agent = mk_naive_agent.MarioKartAgent(os.path.join(helper.get_models_folder(), "naive_model.pickle"))
    while True:
        agent.process_frame()
                        valid_y_label = valid_y_label.cuda()
                    valid_nn_label = Variable(valid_y_label)
                    valid_forward_pass = mkcrnn(valid_x)
                    valid_loss_eval = loss_func(
                        valid_forward_pass,
                        valid_nn_label)  # compute validation loss
                    valid_loss += valid_loss_eval.data[0]
                print('Epoch: ', epoch, 'Step: ', step,
                      '| validation loss: %.4f' % valid_loss)
                validation_losses.append(valid_loss)

    # Save model
    torch.save(
        mkcrnn,
        os.path.join(
            helper.get_models_folder(),
            "mkcrnn_{}_frames_{}_lstm.pkl".format(num_input_frames, history)))

    # Save validation curve data
    fig_data = [
        validation_losses, num_input_frames, history, num_epochs, batch_size,
        learning_rate
    ]
    helper.pickle_object(
        fig_data, "mkcrnn_training_data_{}_frames_{}_lstm".format(
            num_input_frames, history))

    # Plot validation curve
    f = plt.figure()
    plt.plot(validation_losses)
    plt.ylabel('Validation Error')
Esempio n. 7
0
            # Log training data
            if step % 50 == 0:
                print('Epoch: ', epoch, 'Step: ', step, '| training loss: %.4f' % loss.data[0])
                valid_loss = 0
                for (valid_x, valid_y) in valid_loader:
                    valid_y_label = valid_y.view(-1, output_vec)
                    if torch.cuda.is_available():
                        valid_y_label = valid_y_label.cuda()
                    valid_nn_label = Variable(valid_y_label)
                    valid_forward_pass = mknn(valid_x)
                    valid_loss_eval = loss_func(valid_forward_pass, valid_nn_label)  # compute validation loss
                    valid_loss += valid_loss_eval.data[0]
                print('Epoch: ', epoch, 'Step: ', step, '| validation loss: %.4f' % valid_loss)
                validation_losses.append(valid_loss)

    # Save model
    torch.save(mknn, os.path.join(helper.get_models_folder(), "mknn.pkl"))

    # Save validation curve data
    fig_data = [validation_losses, num_epochs, batch_size, learning_rate]
    helper.pickle_object(fig_data, "mknn_training_data_lr{}_epoch{}".format(learning_rate, num_epochs))

    # Plot validation curve
    f = plt.figure()
    plt.plot(validation_losses)
    plt.ylabel('Validation Error')
    plt.xlabel('Number of Iterations')
    plt.title('NN Cross Validation Error, Learning Rate = %s, Batch Size = %i, Number of Epochs = %i' % (
        learning_rate, batch_size, num_epochs))
    plt.show(block=True)