Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified button pushes to be probabilities #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions play.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python

from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from utils import take_screenshot, prepare_image
from utils import take_screenshot, prepare_image, convert_to_probability
from utils import XboxController
import tensorflow as tf
import model
from termcolor import cprint
import numpy as np

PORT_NUMBER = 8082

Expand All @@ -27,7 +28,6 @@ def log_message(self, format, *args):

def do_GET(self):

### determine manual override
manual_override = real_controller.manual_override()

if (not manual_override):
Expand All @@ -39,6 +39,19 @@ def do_GET(self):
## Think
joystick = model.y.eval(feed_dict={model.x: [vec], model.keep_prob: 1.0})[0]

### Pre-process the controls
joystick[0] = max(min(joystick[0], 1), -1)

#### Convert button pushes to 'probabilities' then sample 0/1
p2 = convert_to_probability(joystick[2])
joystick[2] = np.random.choice(a = [0,1], p = [1-p2, p2])

p3 = convert_to_probability(joystick[3])
joystick[3] = np.random.choice(a = [0,1], p = [1-p3, p3])

p4 = convert_to_probability(joystick[4])
joystick[4] = np.random.choice(a = [0,1], p = [1-p4, p4])

else:
joystick = real_controller.read()
joystick[1] *= -1 # flip y (this is in the config when it runs normally)
Expand All @@ -50,9 +63,9 @@ def do_GET(self):
output = [
int(joystick[0] * 80),
int(joystick[1] * 80),
int(round(joystick[2])),
int(round(joystick[3])),
int(round(joystick[4])),
int(joystick[2]),
int(joystick[3]),
int(joystick[4])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible to implement this as a single function call that we use here instead of round? I'd like to explore that rather than adding all this code into the main loop.

]

### print to console
Expand Down
5 changes: 5 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@



def convert_to_probability(val):
p = max(min(val, 1), 0)
return(p)


def take_screenshot():
screen = wx.ScreenDC()
bmp = wx.Bitmap(Screenshot.SRC_W, Screenshot.SRC_H)
Expand Down