Skip to content

Commit

Permalink
split Sample class out of Screenshot class
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhughes27 committed Jun 3, 2017
1 parent 48ae7d1 commit f420c91
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tensorflow as tf
from utils import Screenshot
from utils import Sample

OUT_SHAPE = 5

Expand All @@ -14,7 +14,7 @@ def bias_variable(shape):
def conv2d(x, W, stride):
return tf.nn.conv2d(x, W, strides=[1, stride, stride, 1], padding='VALID')

x = tf.placeholder(tf.float32, shape=[None, Screenshot.IMG_H, Screenshot.IMG_W, Screenshot.IMG_D])
x = tf.placeholder(tf.float32, shape=[None, Sample.IMG_H, Sample.IMG_W, Sample.IMG_D])
y_ = tf.placeholder(tf.float32, shape=[None, OUT_SHAPE])

x_image = x
Expand Down
11 changes: 11 additions & 0 deletions play.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#!/usr/bin/env python

from utils import resize_image, XboxController
<<<<<<< 48ae7d1910c02bfc04433f31ac9fd14322f7747e
from termcolor import cprint
||||||| merged common ancestors
import tensorflow as tf
import model
from termcolor import cprint
=======
from termcolor import cprint

import tensorflow as tf
import model
>>>>>>> split Sample class out of Screenshot class
import gym
import gym_mupen64plus
from train import create_model
Expand Down
4 changes: 2 additions & 2 deletions record.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def poll(self):

def take_screenshot(self):
screen = wx.ScreenDC()
bmp = wx.Bitmap(Screenshot.SRC_W, Screenshot.SRC_H)
bmp = wx.Bitmap(Screenshot.IMG_W, Screenshot.IMG_H)
mem = wx.MemoryDC(bmp)
mem.Blit(0, 0, Screenshot.SRC_W, Screenshot.SRC_H, screen, Screenshot.OFFSET_X, Screenshot.OFFSET_Y)
mem.Blit(0, 0, Screenshot.IMG_W, Screenshot.IMG_H, screen, Screenshot.OFFSET_X, Screenshot.OFFSET_Y)
return bmp

def update_plot(self):
Expand Down
29 changes: 6 additions & 23 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@

import numpy as np

from PIL import Image

from skimage.color import rgb2gray
from skimage.transform import resize
from skimage.io import imread
from skimage.util import img_as_float

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
Expand All @@ -20,22 +17,10 @@
import threading


def prepare_image(img):

img = img.reshape(Screenshot.SRC_H, Screenshot.SRC_W, Screenshot.SRC_D)

return resize_image(img)


def resize_image(img):

im = Image.fromarray(img)
im = im.resize((Screenshot.IMG_W, Screenshot.IMG_H))

im_arr = np.frombuffer(im.tobytes(), dtype=np.uint8)
im_arr = im_arr.reshape((Screenshot.IMG_H, Screenshot.IMG_W, Screenshot.IMG_D))

return img_as_float(im_arr)
im = resize(img, (Sample.IMG_H, Sample.IMG_W, Sample.IMG_D))
im_arr = im.reshape((Sample.IMG_H, Sample.IMG_W, Sample.IMG_D))
return im_arr


class Screenshot(object):
Expand All @@ -46,16 +31,14 @@ class Screenshot(object):
OFFSET_X = 0
OFFSET_Y = 0


class Sample:
IMG_W = 200
IMG_H = 66
IMG_D = 3

image_array = array.array('B', [0] * (SRC_W * SRC_H * SRC_D));



class XboxController(object):

MAX_TRIG_VAL = math.pow(2, 8)
MAX_JOY_VAL = math.pow(2, 15)

Expand Down Expand Up @@ -235,7 +218,7 @@ def prepare(samples):
# load, prepare and add images to X
for image_file in image_files:
image = imread(image_file)
vec = prepare_image(image)
vec = resize_image(image)
X.append(vec)

print("Saving to file...")
Expand Down

0 comments on commit f420c91

Please sign in to comment.