Skip to content

Commit

Permalink
Fixed bugs with job libs in decoders
Browse files Browse the repository at this point in the history
Added a smaller background tester
  • Loading branch information
the-cybersapien committed Mar 15, 2017
1 parent 4729172 commit 157d28f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# CUSTOM FILES
# We don't need to have the cell.dat file in our VCS, its auto-generated
cell.dat
back_dat/
cell_dat/
*.db

.idea/
Expand Down
Binary file removed Training_Data/Back/intro/13.bmp
Binary file not shown.
24 changes: 17 additions & 7 deletions back_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,24 @@ def load(self):
self._load(pt + '/static', static)

def train(self):
if os.path.isfile(back_recognizer):
self.svc = joblib.load(back_recognizer)
folder = 'back_dat'
pt = os.getcwd() + '/' + folder
if os.path.isdir(folder):
dat = os.listdir(pt)
if not int(len(dat)) == 0:
self.svc = joblib.load(pt + '/' + back_recognizer)
else:
self.learn_dat(pt)
else:
self.load()
np_data = np.array(self.trainingData)
np_values = np.array(self.targetValues)
self.svc.fit(np_data, np_values)
joblib.dump(self.svc, back_recognizer)
os.mkdir(pt)
self.learn_dat(pt)

def learn_dat(self, path):
self.load()
np_data = np.array(self.trainingData)
np_values = np.array(self.targetValues)
self.svc.fit(np_data, np_values)
joblib.dump(self.svc, path + '/' + back_recognizer)

def test(self):
np_train_data = np.array(self.trainingData)
Expand Down
24 changes: 17 additions & 7 deletions cell_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,24 @@ def load(self):
# import training data to scikit if it already exists
# else, train the bot with the sample data
def train(self):
if os.path.isfile(cell_recognizer):
self.svc = joblib.load(cell_recognizer)
folder = 'cell_dat'
pt = os.getcwd() + '/' + folder
if os.path.isdir(folder):
dat = os.listdir(pt)
if not int(len(dat)) == 0:
self.svc = joblib.load(pt + '/' + cell_recognizer)
else:
self.learn_dat(pt)
else:
self.load()
np_data = np.array(self.trainingData)
np_values = np.array(self.targetValues)
self.svc.fit(np_data, np_values)
joblib.dump(self.svc, cell_recognizer)
os.mkdir(pt)
self.learn_dat(pt)

def learn_dat(self, path):
self.load()
np_data = np.array(self.trainingData)
np_values = np.array(self.targetValues)
self.svc.fit(np_data, np_values)
joblib.dump(self.svc, path + '/' + cell_recognizer)

def test(self):
np_train_data = np.array(self.trainingData)
Expand Down
28 changes: 28 additions & 0 deletions utilities/tester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import back_decoder
from utils import *
from PIL import Image
from PIL import ImageGrab

import time
board = (77, 164, 652, 670)

backdec = back_decoder.BackRecognizer()
backdec.train()

board_dic = {
curtain: 'curtain\n',
end: 'end\n',
intro: 'intro\n',
loading: 'loading\n',
move: 'move\n',
scoreboard: 'scoreboard\n',
shop: 'shop\n',
static: 'static\n'
}

i = 1
while True:
img = ImageGrab.grab()
img = img.crop(board)
print board_dic[backdec.predict(img)]
time.sleep(0.4)

0 comments on commit 157d28f

Please sign in to comment.