def run_eval_iter(config, iter_id): # Prepare network model to be tested print("Loading network models for testing...") pre_net, net = load_models(config, iter_id, testing=True) print("Model loading completed!") # Load test dataset print("Preparing dataset manager...") dataManager = data.DataManager(config) print("Dataset manager ready!") print("Preparing test dataset...") test_set = dataManager.get_test() print("Test dataset ready!") print("Testing...") test_acc = eval_pass(net, test_set, config, pre_net) print("Accuracy of the network on the test images: {:.2f}%".format( 100 * test_acc)) print("Saving test result...") utils.update_csv(str(iter_id), test_acc, config.CSV_PATH) print("Saved!")
def __init__(self, calibration_data_manager, ratio_threshold=2.0): """ :param calibration_data_manager: data.DataManager :param ratio_threshold: float """ total_ssc = calibration_data_manager.get_variable(self._ssc_key) percent_fines = calibration_data_manager.get_variable( self._percent_fines_key) sand_concentration = self._calc_sand_concentration( total_ssc, percent_fines) fines_to_sands_ratio = self._calc_fines_to_sands_ratio(percent_fines) new_data = pd.concat([sand_concentration, fines_to_sands_ratio], axis=1) new_data_origin = calibration_data_manager.get_origin() new_data_manager = data.DataManager(new_data, new_data_origin) calibration_data_manager.add_data(new_data_manager, keep_curr_obs=True) self._model = self._create_model(calibration_data_manager, ratio_threshold)
def __init__(self, bot: commands.Bot): self.bot = bot reload(data) self.instance = data.DataManager( getattr(bot.config, "ASSETS_BASE_URL", None))
def __init__(self, bot: commands.Bot): self.bot = bot reload(data) self.instance = data.DataManager()
def main(): ## start pygame setup stuff width = 1366 height = 768 pygame.init() os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0" # set window start pos to screen corner screen = pygame.display.set_mode((width, height), pygame.NOFRAME) done = False clock = pygame.time.Clock() framerate = 60 dir = os.path.dirname(__file__) def set_done(value): done = value ## end pygame setup stuff ## start game setup stuff ## examples sun = univ.Star(pygame.image.load(os.path.join(dir,'res','star2.png')), 0, " testnameA ") planets = [univ.Planet(pygame.image.load(os.path.join(dir,'res','planet.png')), i, " testname%d "%i)for i in range(5)] system = univ.System([sun], planets, 0) for i in range(5): system.planets[i].set_system(system) sun.set_system(system) galaxy = univ.Galaxy(system) tmap_list = [] for i in range(50): row = [] for j in range(50): row.append(0) tmap_list.append(row) tile_map = tiles.TileMap(tmap_list, 64, 64) world = cloud.World(tile_map) the_cloud = cloud.Cloud([world]) build_manager = buildings.BuildingManager() sphere1 = buildings.Sphere() build_manager.add('spheres', sphere1) data_manager = data.DataManager() state_manager = util.GameStateManager(3, system, sun, world, the_cloud) ui_manager = ui.UIManager(state_manager, data_manager, screen) drawer = util.Drawer(state_manager, data_manager, ui_manager, galaxy, screen) event_handler = util.EventHandler(state_manager, data_manager, ui_manager, build_manager, drawer, galaxy, screen) random_event_manager = util.RandomEventManager(state_manager, data_manager) ## end game setup stuff while not state_manager.get_done(): screen.fill((0,0,0)) clock.tick(framerate) #print(clock.get_fps()) event_handler.update() drawer.draw() data_manager.update_data(build_manager, clock.get_time()) random_event_manager.update() pygame.display.flip()
def run_train_iter(config, iter_id): if config.CONFIG_FAMILY == P.CONFIG_FAMILY_HEBB: torch.set_grad_enabled(False) # Seed rng torch.manual_seed(iter_id) torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False # Load datasets print("Preparing dataset manager...") dataManager = data.DataManager(config) print("Dataset manager ready!") print("Preparing training dataset...") train_set = dataManager.get_train() print("Training dataset ready!") print("Preparing validation dataset...") val_set = dataManager.get_val() print("Validation dataset ready!") # Prepare network model to be trained print("Preparing network...") pre_net, net = load_models(config, iter_id, testing=False) criterion = None optimizer = None scheduler = None if config.CONFIG_FAMILY == P.CONFIG_FAMILY_GDES: # Instantiate optimizer if we are going to train with gradient descent criterion = nn.CrossEntropyLoss() optimizer = optim.SGD(net.parameters(), lr=config.LEARNING_RATE, momentum=config.MOMENTUM, weight_decay=config.L2_PENALTY, nesterov=True) scheduler = sched.MultiStepLR(optimizer, gamma=config.LR_DECAY, milestones=config.MILESTONES) print("Network ready!") # Train the network print("Starting training...") train_acc_data = [] val_acc_data = [] best_acc = 0.0 best_epoch = 0 start_time = time.time() for epoch in range(1, config.NUM_EPOCHS + 1): # Update LR scheduler if scheduler is not None: scheduler.step() # Print overall progress information at each epoch utils.print_train_progress(epoch, config.NUM_EPOCHS, time.time() - start_time, best_acc, best_epoch) # Training phase print("Training...") train_acc = train_pass(net, train_set, config, pre_net, criterion, optimizer) print("Training accuracy: {:.2f}%".format(100 * train_acc)) # Validation phase print("Validating...") val_acc = eval_pass(net, val_set, config, pre_net) print("Validation accuracy: {:.2f}%".format(100 * val_acc)) # Update training statistics and saving plots train_acc_data += [train_acc] val_acc_data += [val_acc] utils.save_figure(train_acc_data, val_acc_data, config.ACC_PLT_PATH[iter_id]) # If validation accuracy has improved update best model if val_acc > best_acc: print("Top accuracy improved! Saving new best model...") best_acc = val_acc best_epoch = epoch utils.save_dict(net.state_dict(), config.MDL_PATH[iter_id]) if hasattr(net, 'conv1') and net.input_shape == P.INPUT_SHAPE: utils.plot_grid(net.conv1.weight, config.KNL_PLT_PATH[iter_id]) if hasattr(net, 'fc') and net.input_shape == P.INPUT_SHAPE: utils.plot_grid(net.fc.weight.view(-1, *P.INPUT_SHAPE), config.KNL_PLT_PATH[iter_id]) print("Model saved!")
""" ** Author: Xiao Yue ** Date: 2020-08-23 """ import data import illestration import statistic import plan current_month = '2020-09' # Load Data # ---------------------------------------------------------------------------------------------------------------------- data_manager = data.DataManager() daily_spend_sum = data_manager.get_daily_spend_sum() monthly_spend_sum = data_manager.get_monthly_spend_sum() spend_by_category = data_manager.get_spend_by_category_by_month(current_month) income = data_manager.get_monthly_income_by_month(current_month) # Load Plan # ---------------------------------------------------------------------------------------------------------------------- plan_manager = plan.PlanManager() income_arrangement_plan = plan_manager.get_income_arrangement_plan() investment_plan = plan_manager.get_investment_plan() total_asset_arrangement_plan = plan_manager.get_total_asset_arrangement_plan() # Display Figure # ----------------------------------------------------------------------------------------------------------------------