bzier / gym-mupen64plus

An OpenAI Gym environment wrapper for the Mupen64Plus N64 emulator
MIT License
91 stars 39 forks source link

Some Question About gym #51

Closed tanakataiki closed 6 years ago

tanakataiki commented 6 years ago

@bzier

screenshot from 2018-04-25 18-18-44

  1. I use Nintendo64 Controller and Following Error occurs

    File "/home/taiki/TensorKart/utils.py", line 84, in _monitor_controller
    events = get_gamepad()
    Input: 2 controller(s) found, 2 plugged in and usable in the emulator
    Input Warning: Couldn't open rumble support for joystick 
    Input Warning: Couldn't open rumble support for joystick 
    Input Warning: Couldn't open rumble support for joystick 
    Input Warning: Couldn't open rumble support for joystick 

    but I assume mupen64plus-input-bot should be used for 64 controller. I already set them up and I dont know why this happens. Anyway In my case R->Start, A->B and I cant press A in any other button and I can use joystick as usual, I use One controller though it suggest two controller is found.

  2. I am new to gym so I want to know the way to use Test code I create this file in gym-mupen64 folder and I ran

    import gym, gym_mupen64plus
    env = gym.make('Mario-Kart-Luigi-Raceway-v0')
    env.reset()

    but ImportError: No module named 'BaseHTTPServer' Occurs.

Would you tell me TensorKart Needs Gym Environment and should run code for gym or just need manual input data of input button and visual records ?

  1. I think the demo video has one hot vector I/O and how can I show it on display? I dont need it but does it appear on play.py only?

Sorry that I am a bit confused with TensorKart Instruction.

Thanks master !

bzier commented 6 years ago

First I want to lay out a couple basics with the intent of each of these projects, the way they are currently set up, and how they depend on each other.

Ok, so now onto your 3 questions.

  1. I'm not sure what's going on here. First of all, the left terminal looks fine. Because you are attempting to use record.py to capture your own human driving, we would expect the emulator to be using the 'normal' SDL input plugin (not the mupen64plus-input-bot at this point). This means the emulator will be reading the USB controller gamepad, which is what we want. However, the record.py component is also going to be reading that USB controller (to record your human actions). That is where it is failing (in the right terminal). It looks like parts of the stack trace are cut off in the image. Are you able to copy/paste the whole error that is happening?

  2. The second error you reported (ImportError: No module named 'BaseHTTPServer') is unfortunately a Python 2 -> 3 incompatibility. This is coming from the first line of the gym-mupen64plus project's mupen64plus_env.py file. It needs to be changed

    # From Python 2x:
    from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
    
    # To Python 3x:
    from http.server import BaseHTTPRequestHandler,HTTPServer

    There may be many more things like this that you will bump into with using Python 3. Again, if you are able to work through them, I'm open to a pull request. However, I'd like to maintain support for Python 2 as well. This can be accomplished with something like:

    import sys
    
    if sys.version_info[0] >= 3:
        # Python 3 specific definitions
        ...
    else:
        # Python 2 specific definitions
        ...
  3. Yes, you are correct. When running play.py, the terminal will show the AI model output in green, and human overrides in yellow. By the way, those aren't actually one-hot vectors, they are the control values themselves (e.g. [-75.3, 2.3, 1, 0, 0]). A one-hot vector would be a single 1 in a series of bit values (e.g. [0, 1, 0, 0, 0]). In the case of TensorKart, the first two values are the joystick x/y axes (continuous values between -80 and 80) and then three button for A, B, and RB (discrete values 0,1). I do have environment options within gym-mupen64plus for a discrete action space, which is where an agent chooses the best action among a discrete set, as opposed to directly choosing the controller values themselves. In this case, it actually is a one-hot vector, since it picks a single action from the set. Alternatively, this can just be represented as an integer value (the index of 1 in the one-hot vector).

bzier commented 6 years ago

I spent a little time trying out Python 3. I did bump into several more issues. None of them have been significant, but every time I fix one, there is another right after. I don't have time at the moment to go through this process, but I should be able to add support for Python 3 in the near future... unless you take care of it before I get to it, but be aware that there will be more issues to work through before it will get up and running. Alternatively, you could switch to using Python 2. I'm not sure which version of Ubuntu you are running, but if Python 2 is not on your system, you can install it side-by-side with Python 3 (see here).

tanakataiki commented 6 years ago

Thanks for a good explanation I am going to try it. Currently I use GitHub on windows to commit , or commit online webpage on linux. I think tensorflow-gpu supports python 3 so python 3 would be better in the future if gpus are necessary.

  1. mupen64 result
    
    __  __                         __   _  _   ____  _             
    |  \/  |_   _ _ __   ___ _ __  / /_ | || | |  _ \| |_   _ ___ 
    | |\/| | | | | '_ \ / _ \ '_ \| '_ \| || |_| |_) | | | | / __|  
    | |  | | |_| | |_) |  __/ | | | (_) |__   _|  __/| | |_| \__ \  
    |_|  |_|\__,_| .__/ \___|_| |_|\___/   |_| |_|   |_|\__,_|___/  
             |_|         http://code.google.com/p/mupen64plus/  
    Mupen64Plus Console User-Interface Version 2.5.0

UI-Console: attached to core library 'Mupen64Plus Core' version 2.5.0 UI-Console: Includes support for Dynamic Recompiler. UI-Console: Includes support for MIPS r4300 Debugger. Core: Goodname: Mario Kart 64 (U) [!] Core: Name: MARIOKART64
Core: MD5: 3A67D9986F54EB282924FCA4CD5F6DFF Core: CRC: 3E5055B6 2E92DA52 Core: Imagetype: .z64 (native) Core: Rom size: 12582912 bytes (or 12 Mb or 96 Megabits) Core: Version: 1446 Core: Manufacturer: Nintendo Core: Country: USA UI-Console Status: Cheat codes disabled. UI-Console: using Video plugin: 'Mupen64Plus OpenGL Video Plugin by Rice' v2.5.0 UI-Console: using Audio plugin: 'Mupen64Plus SDL Audio Plugin' v2.5.0 UI-Console: using Input plugin: 'Mupen64Plus SDL Input Plugin' v2.5.0 UI-Console: using RSP plugin: 'Hacktarux/Azimer High-Level Emulation RSP Plugin' v2.5.0 Input: 2 SDL joysticks were found. Input: N64 Controller #1: Using auto-config with SDL joystick 0 ('USB GamePad USB GamePad') Input: N64 Controller #2: Using auto-config with SDL joystick 1 ('USB GamePad USB GamePad') Input: 2 controller(s) found, 2 plugged in and usable in the emulator Input Warning: Couldn't open rumble support for joystick #1 Input Warning: Couldn't open rumble support for joystick #2 Input Warning: Couldn't open rumble support for joystick #3 Input Warning: Couldn't open rumble support for joystick #4 Input: Mupen64Plus SDL Input Plugin version 2.5.0 initialized. Core Status: Selected state slot: 5 Video: SSE processing enabled. Video: Found ROM 'Mario Kart 64', CRC b655503e52da922e-45 Video: Enabled hacks for game: 'MARIOKART64' Video: Initializing OpenGL Device Context. Core: Setting 32-bit video mode: 640x480 Video Warning: Failed to set GL_SWAP_CONTROL to 0. (it's 24) Video Warning: Failed to set GL_BUFFER_SIZE to 32. (it's 24) Video Warning: Failed to set GL_DEPTH_SIZE to 16. (it's 24) Video: Using OpenGL: NVIDIA Corporation - GeForce GTX 1080 with Max-Q Design/PCIe/SSE2 : 4.6.0 NVIDIA 390.48 Audio: Initializing SDL audio subsystem... Input Warning: Couldn't open rumble support for joystick #1 Input Warning: Couldn't open rumble support for joystick #2 Input Warning: Couldn't open rumble support for joystick #3 Input Warning: Couldn't open rumble support for joystick #4 Core: Starting R4300 emulator: Dynamic Recompiler Core: R4300: starting 64-bit dynamic recompiler at: 0x7fd92ab0f6e0

The necessary change that I found  in record.py was
```python
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.messagebox as tkMassageBox

But It wasn't significant change as you suggested and it can work just to change to add import and Rename as original.

bzier commented 6 years ago

I'd highly recommend Visual Studio Code which runs on Linux and has built-in support for git, and supports Python via an extension. Installing code and git are both pretty easy, and would make your life easier, not having to bounce back-and-forth between OSes or edit code through the GitHub webpage. Not a requirement, just a suggestion :)

tanakataiki commented 6 years ago

@bzier By the way if I change environment to python 2 then, set up such as make dir and compile on python 2 environment and run the code using python3 since TensorKart is written by python3 code. Am I right? https://github.com/kevinhughes27/TensorKart/commit/baff3c2121ca2af8b7898a84d8b4e4372ed3e498

bzier commented 6 years ago

I am honestly not sure if you could successfully mix versions like that. I haven't tried myself. You are correct that TensorKart was updated for Python 3 in that commit you linked. As you discovered, I may have broken that compatibility with the Tkinter UI changes I added recently, but with your fix, TensorKart should work fine for recording and training using python 3.

However, when running play.py, which utilizes gym-mupen64plus, that's where you will likely bump into more issues because this gym project is currently built around python 2. Certainly you can try what you suggested, mixing versions, but I would be surprised if that worked. Otherwise it should work using Python 2.

It's late here, gotta get some sleep.

bzier commented 6 years ago

Hey @tanakataiki I spent a little time today fixing support for Python 3. There were a couple changes (as you found) with the record.py that were necessary. Those have been added in TensorKart PR #62. Additionally, this gym project required a couple changes, which have been added in PR #52. I've added @kevinhughes27 as a reviewer on both. I'd like to give him a chance to take a look before I merge the changes in, but they should be coming soon.

bzier commented 6 years ago

@tanakataiki Both of those pull requests mentioned above have now been merged. If you pull the latest changes, Python 3 should work again. I'm going to go ahead and close this issue since I think we covered all of the questions. Feel free to re-open this if not, or open new issues as they come up.

tanakataiki commented 6 years ago

@bzier Thank you very much for your support. I tested python 3 ver in Ubuntu16.04LTS

I think this is not version error but I input the code mupen64plus --input /usr/local/lib/mupen64plus/mupen64plus-input-bot.so ./gym_mupen64plus/ROMs/MarioKart.z64

  1. The error below happens. I referred #17 but I didn't set another port. Do you have any idea?
    
    __  __                         __   _  _   ____  _             
    |  \/  |_   _ _ __   ___ _ __  / /_ | || | |  _ \| |_   _ ___ 
    | |\/| | | | | '_ \ / _ \ '_ \| '_ \| || |_| |_) | | | | / __|  
    | |  | | |_| | |_) |  __/ | | | (_) |__   _|  __/| | |_| \__ \  
    |_|  |_|\__,_| .__/ \___|_| |_|\___/   |_| |_|   |_|\__,_|___/  
             |_|         http://code.google.com/p/mupen64plus/  
    Mupen64Plus Console User-Interface Version 2.5.0

UI-Console: attached to core library 'Mupen64Plus Core' version 2.5.0 UI-Console: Includes support for Dynamic Recompiler. UI-Console: Includes support for MIPS r4300 Debugger. Core: Goodname: Mario Kart 64 (U) [!] Core: Name: MARIOKART64
Core: MD5: 3A67D9986F54EB282924FCA4CD5F6DFF Core: CRC: 3E5055B6 2E92DA52 Core: Imagetype: .z64 (native) Core: Rom size: 12582912 bytes (or 12 Mb or 96 Megabits) Core: Version: 1446 Core: Manufacturer: Nintendo Core: Country: USA UI-Console Status: Cheat codes disabled. UI-Console: using Video plugin: 'Mupen64Plus OpenGL Video Plugin by Rice' v2.5.0 UI-Console: using Audio plugin: 'Mupen64Plus SDL Audio Plugin' v2.5.0 UI-Console: using Input plugin: 'Mupen64Plus Bot Input Plugin' v0.0.1 UI-Console: using RSP plugin: 'Hacktarux/Azimer High-Level Emulation RSP Plugin' v2.5.0 Input: Mupen64Plus Bot Input Plugin version 0.0.1 initialized. Core Status: Selected state slot: 5 Video: SSE processing enabled. Video: Found ROM 'Mario Kart 64', CRC b655503e52da922e-45 Video: Enabled hacks for game: 'MARIOKART64' Video: Initializing OpenGL Device Context. Core: Setting 32-bit video mode: 640x480 Video Warning: Failed to set GL_SWAP_CONTROL to 0. (it's 24) Video Warning: Failed to set GL_BUFFER_SIZE to 32. (it's 24) Video Warning: Failed to set GL_DEPTH_SIZE to 16. (it's 24) Video: Using OpenGL: NVIDIA Corporation - GeForce GTX 1080 with Max-Q Design/PCIe/SSE2 : 4.6.0 NVIDIA 390.48 Audio: Initializing SDL audio subsystem... Core: Starting R4300 emulator: Dynamic Recompiler Core: R4300: starting 64-bit dynamic recompiler at: 0x7f28deaf36e0 Input: ERROR connecting, please start bot server.

2. I want to know the flow to record display.
I think XVFB is used for adjusting position of display. so I think mario kart display will be inside XVFB.
    ```bash
    x11vnc -display :1 8082 -forever -viewonly
    mupen64 --input ~~ path to ROMs
    Record.py
Am I right? Currrently the display wont appear after x11vnc~~ code
  1. I am wondering when to stop recording. I think it's end of race but with no action during stage change is the meaningless record ignored?

thanks.

bzier commented 6 years ago

Hi @tanakataiki

I think there's still some confusion around what is used at different points in the process. It sounds like you are working on getting TensorKart to work. For that project, there is a three step process.

  1. Record
  2. Train
  3. Play

TensorKart is an implementation of an AI using supervised learning. This means you will provide examples of your own human driving, which the AI will use to train and learn how to 'mimic' your driving. The first step (record) is the step where you are recording that example data. Right now it sounds like that's what you are trying to accomplish.

However, during the record process, this library (gym-mupen64plus) is not used at all. A long time ago, I was working on incorporating that as well, but encountered some performance issues. But for now, the recording is completely separate. What this means is that you will run the emulator normally (not using the input bot, not in gym, not in Xvfb, not with vnc).

The answer to your first question (1) is that you are attempting to run the emulator using the input bot (which is attempting to connect to an HTTP controller server on port 8082). Since you are not running a controller server, it fails to connect. However, as I mentioned, at this step you do not need the input bot, since you are the one who will be driving. The input bot plugin is only used for the AI to drive.

Your second question (2) is really captured in the instructions for TensorKart. See the recording steps here. Step 2 there mentions that you should be using the 'normal' SDL input plugin.

The third question (3) is also captured in those instructions. Step 6 there says,

  1. Press record and play through a level. You can trim some images off the front and back of the data you collect afterwards (by removing lines in data.csv)

In other words, do your best to record just the race (that's all we care about for training the AI). However, you may also end up capturing some frames during the menu, or post-race results, etc. These should be removed from the data before you train the AI. You can look through the directory of images that were captured to identify ones that should not be there. You can then edit the resulting .csv file to remove those entries. There is a line per image along with the controller state at each frame. After they have been removed from the .csv file, you can also delete those images.

So carefully follow the provided instructions on the TensorKart README. You should be able to run the emulator normally on screen using a command something like:

mupen64plus --input mupen64plus-input-sdl ./gym_mupen64plus/ROMs/MarioKart.z64

And then run the record.py program.

If you encounter any other issues with the recording process, I'd suggest opening an issue on the TensorKart page, since this library isn't used for that process. It will just make it easier for others to find and benefit from later. (We'll help you out either way regardless of where the issue gets created, it's just nice to keep it organized).

bzier commented 6 years ago

I also wanted to mention that the x11vnc command you posted in (2) is not correct. You have x11vnc -display :1 8082 -forever -viewonly, but that 8082 should not be in there. That port number is for the input bot and the controller server, but that is handled for you in this gym-mupen64plus library (later in the process during play.py). For now, you aren't dealing with the input bot or the controller server, so that port number is not relevant.

Also note that the x11vnc command is only useful when running the gym environment with Xvfb, but that simply just starts a VNC server. You then would need to connect to it with a VNC client to see anything. Again, all that may come later, but only if necessary. During play.py there is a different method of rendering the game on-screen.