def train(): text = Text(seq_length) data_x = text.dataX data_y = text.dataY # reshape X to be [samples, timesteps, features] X = numpy.reshape(data_x, (len(data_x), seq_length, 1)) # normalize X = X / float(len(text.chars)) # one hot encode the output variable y = np_utils.to_categorical(data_y) # define the LSTM model model = Sequential() model.add( LSTM(512, input_shape=(X.shape[1], X.shape[2]), return_sequences=True)) model.add(Dropout(0.2)) model.add(LSTM(256)) model.add(Dropout(0.2)) model.add(Dense(y.shape[1], activation='softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam') # define the checkpoint checkpoint_path = os.path.join( 'checkpoints', 'weights-improvement-{epoch:02d}-{loss:.4f}.hdf5') checkpoint = ModelCheckpoint(checkpoint_path, monitor='loss', verbose=1, save_best_only=True, mode='min') callback_list = [checkpoint] model.fit(X, y, epochs=100, batch_size=64, callbacks=callback_list)
def generate(): text = Text(seq_length) # load the network weights model = load_model(os.path.join(checkpoint_path, filename)) model.compile(loss='categorical_crossentropy', optimizer='adam') dataX = text.dataX int_to_char = text.int_to_char # pick a random seed start = numpy.random.randint(0, len(dataX) - 1) pattern = dataX[start] print('seed:') print(''.join([int_to_char[value] for value in pattern])) # generate characters for i in range(number_of_predicted_characters): x = numpy.reshape(pattern, (1, len(pattern), 1)) x = x / float(len(text.chars)) prediction = model.predict(x, verbose=0) index = numpy.argmax(prediction) result = int_to_char[index] seq_in = [int_to_char[value] for value in pattern] sys.stdout.write(result) pattern.append(index) pattern = pattern[1:len(pattern)]
def init_error_message(parser): """Initialises the error message""" font = pygame.font.SysFont("Courier", 12) contents = get_parser_help_message(parser) return Text( font, size=(400, 200), text=contents, position=(100, 100), background_colour=(207, 102, 121), )
def init_console(parser): """Initialises the console""" font = pygame.font.SysFont("Courier", 12) text = Text(font, size=(200, 40), position=(0, 0)) error_text = init_error_message(parser) return Console(parser, text, error_text)
def __init__(self): # CPU self.CPUtotalUsage = round(percentage().user + percentage().system) self.CPUText = Text(50, 50 - 25) self.CPU = Rectangle(50, 50, 100, 30, GREEN) # CPU Usage self.CPUUsageText = Text(50, 90) self.CPUUsage = Rectangle(50, 50, int(self.CPUtotalUsage), 30, RED) # Memory self.memory = Rectangle(450, 50, 100, 30, GREEN) self.memoryText = Text(450, 50 - 25) # Memory usage self.memoryUsage = Rectangle(450, 50, memory_usage_percent(), 30, RED) self.memoryTextUsage = Text(450, 90) # Disk self.disk = Rectangle(50, 200, 100, 30, GREEN) self.diskText = Text(50, 170) # disk usage self.diskUsage = Rectangle(50, 200, disk_percent(), 30, RED) self.diskTextUsage = Text(50, 240) # info ip self.ip = Text(50, 400) # systen self.platform_name = Text(50, 430) self.platform_platform = Text(50, 460) self.platform_system = Text(50, 490) self.platform_processor = Text(50, 520)
ball.rect.x = ballStartPosition[0] ball.rect.y = ballStartPosition[1] scorePlayer1 = 0 scorePlayer2 = 0 # Machine vision setup cameraHandler = CameraHandler(CAPTURE_SIZE, CV_LOWER_BOUNDARY, CV_UPPER_BOUNDARY, CV_OPEN_KERNEL, CV_CLOSE_KERNEL) cameraHandler.startCameraStream() # UI font = pygame.font.Font('freesansbold.ttf', 32) scoreText = Text(screen, font, str(scorePlayer1) + "-" + str(scorePlayer2), Colour.WHITE.value, (400, 48), center=True) # Main program loop while carryOn: # Main event loop for event in pygame.event.get(): # User requested program shut-down if event.type == pygame.QUIT: carryOn = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: carryOn = False if event.type == pygame.USEREVENT: if "Lose" in event.id:
def __init__(self): ############################################################################ # CPU self.cpu = CPU() self.surfCpu = Surface(0, 0, 500, 400) self.textCpu = Text(19, 25, self.surfCpu.getSurface(), 15) self.rectCpu = Rectangle(20, 50, 200, 15, self.surfCpu.getSurface(), GREEN) self.rectCpuUsage = Rectangle(20, 50, 200, 15, self.surfCpu.getSurface(), RED) # logic core cpu self.xCores = 0 self.xCoresInside = 0 self.rectCores = [] for core in range(self.cpu.getCoresLogical()): self.xCores += 20 if self.xCores > 180: self.xCoresInside += 20 self.rectCores.append(Rectangle(self.xCoresInside, 95, 10, 15, self.surfCpu.getSurface(), GREEN)) self.rectCores.append(Rectangle(self.xCores, 75, 10, 15, self.surfCpu.getSurface(), GREEN)) # infos cpu self.textCore = Text(20, 130, self.surfCpu.getSurface(), 15) self.textCoreLogical = Text(20, 150, self.surfCpu.getSurface(), 15) self.textArch = Text(20, 170, self.surfCpu.getSurface(), 15) self.textBits = Text(20, 190, self.surfCpu.getSurface(), 15) self.textBrand = Text(20, 210, self.surfCpu.getSurface(), 15) ############################################################################# ############################################################################# # MEMORY self.memory = Memory() self.surfMemory = Surface(0, 0, 500, 400) self.rectMemory = Rectangle(20, 50, 200, 15, self.surfMemory.getSurface(), GREEN) self.rectMemoryUsage = Rectangle(20, 50, 200, 15, self.surfMemory.getSurface(), RED) # memory info self.textMemory = Text(19, 25, self.surfMemory.getSurface(), 15) self.textMemoryTotal = Text(19, 130, self.surfMemory.getSurface(), 15) self.textMemoryPercent = Text(19, 150, self.surfMemory.getSurface(), 15) self.textMemoryUsage = Text(19, 170, self.surfMemory.getSurface(), 15) ############################################################################# ############################################################################# # DISK self.disk = Disk() self.surfDisk = Surface(0, 0, 500, 400) self.rectDisk = Rectangle(20, 50, 200, 15, self.surfDisk.getSurface(), GREEN) self.rectDiskUsage = Rectangle(20, 50, 200, 15, self.surfDisk.getSurface(), RED) # disk info self.textDisk = Text(19, 25, self.surfDisk.getSurface(), 15) self.textDiskTotal = Text(19, 130, self.surfDisk.getSurface(), 15) self.textDiskPercent = Text(19, 150, self.surfDisk.getSurface(), 15) self.textDiskUsage = Text(19, 170, self.surfDisk.getSurface(), 15) ############################################################################# ############################################################################### # IP self.ip = Ip self.surfIp = Surface(0, 0, 500, 400) self.textIp = Text(250, 25, self.surfIp.getSurface(), 15) self.textIpEddressLocal = Text(15, 50, self.surfIp.getSurface(), 15) self.textIpEddress = Text(15, 100, self.surfIp.getSurface(), 15) self.textIpEddressMask = Text(15, 150, self.surfIp.getSurface(), 15) self.textIpEddressBroadcast = Text(15, 200, self.surfIp.getSurface(), 15) \ ############################################################################### ############################################################################### # INFOS self.surfInfo = Surface(0, 0, 500, 400) # texts infos cpu self.textInfoCpu = Text(10, 10, self.surfInfo.getSurface(), 15) self.textInfoCore = Text(20, 30, self.surfInfo.getSurface(), 15) self.textInfoCoreLogical = Text(20, 50, self.surfInfo.getSurface(), 15) self.textInfoArch = Text(20, 70, self.surfInfo.getSurface(), 15) self.textInfoBits = Text(20, 90, self.surfInfo.getSurface(), 15) self.textInfoBrand = Text(20, 110, self.surfInfo.getSurface(), 15) # texts infos memory self.textInfoMemory = Text(10, 140, self.surfInfo.getSurface(), 15) self.textInfoMemoryTotal = Text(20, 160, self.surfInfo.getSurface(), 15) self.textInfoMemoryPercent = Text(20, 180, self.surfInfo.getSurface(), 15) self.textInfoMemoryUsage = Text(20, 200, self.surfInfo.getSurface(), 15) # texts infos disk self.textInfoDisk = Text(10, 230, self.surfInfo.getSurface(), 15) self.textInfoDiskTotal = Text(20, 250, self.surfInfo.getSurface(), 15) self.textInfoDiskPercent = Text(20, 270, self.surfInfo.getSurface(), 15) self.textInfoDiskUsage = Text(20, 290, self.surfInfo.getSurface(), 15) # text ip self.textInfoIp = Text(10, 320, self.surfInfo.getSurface(), 15) self.textInfoIpEddress = Text(20, 340, self.surfInfo.getSurface(), 15) ############################################################################### ############################################################################### # arrays surface self.arrSurface = [self.surfCpu, self.surfMemory, self.surfDisk, self.surfIp, self.surfInfo]
carryOn = True # Create game window screen = pygame.display.set_mode(SCREEN_SIZE) pygame.display.set_caption(WINDOW_TITLE) # MV setup cameraHandler = CameraHandler(CAPTURE_SIZE) cameraHandler.startCameraStream() # UI font = pygame.font.Font('freesansbold.ttf', 32) calibrateText = Text(screen, font, "[SPACE] to Calibrate Background", Colour.WHITE.value, (SCREEN_SIZE[0] / 2, SCREEN_SIZE[1] / 2), center=True, shadow=True) stream = Stream(CAPTURE_SIZE, screen) # Main program loop while carryOn: # Main event loop for event in pygame.event.get(): # User requested program shut-down if event.type == pygame.QUIT: carryOn = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE or event.key == pygame.K_q: carryOn = False