def init(): window = pyglet.window.Window(width=800,height=600, resizable=True, visible=False) window.clear() window.resize = resize window.set_visible(True) window.resize(window.width, window.height) current_dir = os.path.abspath(os.path.dirname(__file__)) load_files_from_dir = 'data' data_dir = os.path.normpath(os.path.join(current_dir, '..', load_files_from_dir)) game_data = {} scanDirectory(data_dir, game_data) loadImages(game_data['data']['agents']['Monster01']['animations']) loadImages(game_data['data']['map']['elements']['House01']) game_data["window"] = window state = GameState(game_data) game_data["game"] = state map = Map(32, 32, game_data, 32) spawner = Spawn(game_data) map.populate() render = Render(game_data) print game_data
def fitModel(epochs, batch_size): print("\n>>>TRAINING MODEL<<<") print("\n\tLoading images...") trainX, trainY = loadImages("processed_images/TRAIN") print("\tDONE! Images are loaded.") encoder = LabelEncoder() encoder.fit(trainY) encoded_y_train = encoder.transform(trainY) trainY = np_utils.to_categorical(encoded_y_train) model = neural_network_model() model.fit(trainX, trainY, epochs=epochs, batch_size=batch_size) model.save_weights('network.h5') return model
def predict(model): print("\n>>>PREDICTING ON TEST DATA<<<") # testSimpleX,testSimpleY = loadImages("images/TEST_SIMPLE"); print("\n\tLoading images...") testX, testY = loadImages("processed_images/TEST") print("\tDONE! Images are loaded.") encoder = LabelEncoder() encoder.fit(testY) encoded_y_test = encoder.transform(testY) testY = np_utils.to_categorical(encoded_y_test) prediction_matching = np.rint(model.predict(testX)) print(accuracy_score(testY, prediction_matching))
def main(): model = None while True: try: print("\n1.Process images ") print("2.Fit new model") print("3.Load existing model") print("4.Predict test data") select = int(input("Please enter a number: ")) if select == 1: print("\n\tProccesing train images...") loadImages("images/TRAIN", True) print("\tDONE! Train images are processed.") print("\n\tProccesing test images...") loadImages("images/TEST", True) print("\tDONE! Test images are loaded.") elif select == 2: model = fitModel(epochs, batch_size) elif select == 3: try: model = loadModel("network.h5") except OSError: print( "\n!!! Model doesn't exist. You need first to fit model." ) elif select == 4: if model is not None: predict(model) else: print("\n!!! You must first fit or load model") except ValueError: print("\n!!! That was no valid number. Try again...")
def train(model): import data # Prepare input x_train, y_train, x_test, y_test = data.loadImages("input_iconsets", -1, args.split) hintbot.fit(x_train, y_train, nb_epoch=args.epochs, batch_size=256, shuffle=True, validation_data=(x_test, y_test)) # Save weights if (save_weights_filepath): print("saving weights") hintbot.save_weights(save_weights_filepath, overwrite=True)
def main(): data.trace("started main") pygame.init() pygame.font.init() pygame.display.set_caption("The Mimic Slime and the Forbidden Dungeon") g.simpleFont = pygame.font.Font(data.filepath("vera.ttf"), 8) data.trace("reading "+str(len(sys.argv)-1)+" arguments") data.trace("creating screen") g.screen = pygame.display.set_mode(g.screen_size) data.trace("loading images") if not data.loadImages(): return for i in range((g.images["base.png"].get_size()[1])/32): for j in range((g.images["base.png"].get_size()[0])/32): tempSurface = g.simpleFont.render(str(j)+", "+str(i), False, (255,255,255)) g.images["base.png"].blit(tempSurface, (j*32, i*32)) pygame.image.save(g.images["base.png"], "base_with_xy.png") data.trace("complete!")
def main(): data.trace("started main") pygame.init() pygame.font.init() pygame.display.set_caption("The Mimic Slime and the Forbidden Dungeon") g.simpleFont = pygame.font.Font(data.filepath("vera.ttf"), 8) data.trace("reading " + str(len(sys.argv) - 1) + " arguments") data.trace("creating screen") g.screen = pygame.display.set_mode(g.screen_size) data.trace("loading images") if not data.loadImages(): return for i in range((g.images["base.png"].get_size()[1]) / 32): for j in range((g.images["base.png"].get_size()[0]) / 32): tempSurface = g.simpleFont.render( str(j) + ", " + str(i), False, (255, 255, 255)) g.images["base.png"].blit(tempSurface, (j * 32, i * 32)) pygame.image.save(g.images["base.png"], "base_with_xy.png") data.trace("complete!")
import matplotlib.pyplot as plt from skimage.feature import hog from tqdm import tqdm import numpy as np import cv2 import glob import json import pickle import time from sklearn.preprocessing import StandardScaler from data import loadImages from hog import * from scipy.ndimage.measurements import label cars_imgs, noncars_imgs = loadImages() car_features = [] noncar_features = [] # Define a function you will pass an image # and the list of windows to be searched (output of slide_windows()) def search_windows(img, windows, clf, scaler): #1) Create an empty list to receive positive detection windows on_windows = [] #2) Iterate over all windows in the list for window in windows: #3) Extract the test window from original image test_img = cv2.resize( img[window[0][1]:window[1][1], window[0][0]:window[1][0]], (64, 64))