Skip to content

Commit f420c91

Browse files
committed
split Sample class out of Screenshot class
1 parent 48ae7d1 commit f420c91

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import tensorflow as tf
2-
from utils import Screenshot
2+
from utils import Sample
33

44
OUT_SHAPE = 5
55

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

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

2020
x_image = x

play.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
#!/usr/bin/env python
22

33
from utils import resize_image, XboxController
4+
<<<<<<< 48ae7d1910c02bfc04433f31ac9fd14322f7747e
45
from termcolor import cprint
6+
||||||| merged common ancestors
7+
import tensorflow as tf
8+
import model
9+
from termcolor import cprint
10+
=======
11+
from termcolor import cprint
12+
13+
import tensorflow as tf
14+
import model
15+
>>>>>>> split Sample class out of Screenshot class
516
import gym
617
import gym_mupen64plus
718
from train import create_model

record.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ def poll(self):
105105

106106
def take_screenshot(self):
107107
screen = wx.ScreenDC()
108-
bmp = wx.Bitmap(Screenshot.SRC_W, Screenshot.SRC_H)
108+
bmp = wx.Bitmap(Screenshot.IMG_W, Screenshot.IMG_H)
109109
mem = wx.MemoryDC(bmp)
110-
mem.Blit(0, 0, Screenshot.SRC_W, Screenshot.SRC_H, screen, Screenshot.OFFSET_X, Screenshot.OFFSET_Y)
110+
mem.Blit(0, 0, Screenshot.IMG_W, Screenshot.IMG_H, screen, Screenshot.OFFSET_X, Screenshot.OFFSET_Y)
111111
return bmp
112112

113113
def update_plot(self):

utils.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55

66
import numpy as np
77

8-
from PIL import Image
9-
108
from skimage.color import rgb2gray
119
from skimage.transform import resize
1210
from skimage.io import imread
13-
from skimage.util import img_as_float
1411

1512
import matplotlib.pyplot as plt
1613
import matplotlib.image as mpimg
@@ -20,22 +17,10 @@
2017
import threading
2118

2219

23-
def prepare_image(img):
24-
25-
img = img.reshape(Screenshot.SRC_H, Screenshot.SRC_W, Screenshot.SRC_D)
26-
27-
return resize_image(img)
28-
29-
3020
def resize_image(img):
31-
32-
im = Image.fromarray(img)
33-
im = im.resize((Screenshot.IMG_W, Screenshot.IMG_H))
34-
35-
im_arr = np.frombuffer(im.tobytes(), dtype=np.uint8)
36-
im_arr = im_arr.reshape((Screenshot.IMG_H, Screenshot.IMG_W, Screenshot.IMG_D))
37-
38-
return img_as_float(im_arr)
21+
im = resize(img, (Sample.IMG_H, Sample.IMG_W, Sample.IMG_D))
22+
im_arr = im.reshape((Sample.IMG_H, Sample.IMG_W, Sample.IMG_D))
23+
return im_arr
3924

4025

4126
class Screenshot(object):
@@ -46,16 +31,14 @@ class Screenshot(object):
4631
OFFSET_X = 0
4732
OFFSET_Y = 0
4833

34+
35+
class Sample:
4936
IMG_W = 200
5037
IMG_H = 66
5138
IMG_D = 3
5239

53-
image_array = array.array('B', [0] * (SRC_W * SRC_H * SRC_D));
54-
55-
5640

5741
class XboxController(object):
58-
5942
MAX_TRIG_VAL = math.pow(2, 8)
6043
MAX_JOY_VAL = math.pow(2, 15)
6144

@@ -235,7 +218,7 @@ def prepare(samples):
235218
# load, prepare and add images to X
236219
for image_file in image_files:
237220
image = imread(image_file)
238-
vec = prepare_image(image)
221+
vec = resize_image(image)
239222
X.append(vec)
240223

241224
print("Saving to file...")

0 commit comments

Comments
 (0)