def main(cfg: OmegaConf): with StdoutTee('train.stdout'), StderrTee('train.stderr'): print(OmegaConf.to_yaml(cfg)) if cfg.runner.name == 'pl': trainer, model = pl_train(cfg, LightningModel) else: assert cfg.runner.name == 'ray', 'Only pl and ray runners are supported' # Shouldn't need to install ray unless doing distributed training from ray_runner import ray_train ray_train(cfg, LightningModel)
def main(cfg: OmegaConf): with StdoutTee('train.stdout'), StderrTee('train.stderr'): print(OmegaConf.to_yaml(cfg)) pl_module_cls = DistillLightningModel if cfg.train.get( 'crossfit_size', 1) == 1 else DistillCrossfitLightningModel if cfg.runner.name == 'pl': pl_train(cfg, pl_module_cls) else: assert cfg.runner.name == 'ray', 'Only pl and ray runners are supported' # Shouldn't need to install ray unless doing distributed training from ray_runner import ray_train ray_train(cfg, pl_module_cls)
def main(): # This HTTP requests logger will be over-written everytime this script runs from the start logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m-%d-%Y %I:%M:%S %p', filename='requests_logfile.txt', filemode='w', level=logging.DEBUG) # print("\nPlease enter the following details to get a list of tags") print("--------------------------------------------------------") # RMS = input("RMS (Example: swtest.ava8.net): ") # ID = input("Robot's ID: ") # UN = input("Username: "******"Password: "******"base.ava8.net" ID = "BA00155" UN = "mitgbfb" PS = "ap123" print('\nConnecting to robot ', ID, ' for logging position.') # TODO: configure local server to not rely on wifi dropouts utils = robotutils.RobotUtils(RMS, UN, PS, ID) # set the patrol log file name cur_time = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S") filename = '{}_TrajHist_{}.txt'.format(ID.upper(), cur_time) starttime = time.time() with StdoutTee(filename, buff=1): sys.stdout.write("\nTrajectory History") sys.stdout.write("\n--------------") while True: now = time.time() timespent = now - starttime try: coord = utils.curRobotPosition() # coord is a dict, add time and save coord['Time'] = now sys.stdout.write("\n{}".format(coord)) time.sleep(0.5) except TypeError: time.sleep(0.5) finally: time.sleep(0.5)
def main(): # This HTTP requests logger will be over-written everytime this script runs from the start logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m-%d-%Y %I:%M:%S %p', filename='requests_logfile.txt', filemode='w', level=logging.DEBUG) print("\nPlease enter the following details to get a list of tags") print("--------------------------------------------------------") RMS = input("RMS (Example: swtest.ava8.net): ") ID = input("Robot's ID: ") UN = input("Username: "******"Password: "******"\nRetrieving tags now.") dic = {} tagList = utils.getTagList() # if there are no tags to be found, exit if (tagList == None): print( '\nNo tags were found. Either check the credentials entered, if there are any ' + 'tags in the map, or if the robot is connected to the correct rms. Exiting program.\n' ) time.sleep(10.0) exit() for key, values in tagList.items(): dic[values["name"].lower()] = key # print list of tags and choose two of them print("\n------------- TAGS ---------------------") for key, values in dic.items(): print(key) print("--------------------------------------------") print("\nChoose two tags from the list displayed above") print("---------------------------------------------") # check and re-enter tag names till they are correct while True: tag1 = input("First tag: ") if not (tag1 in dic): print('\nPlease choose a tag from the list displayed above.\n') time.sleep(1.0) else: break while True: tag2 = input("Second tag: ") if not (tag2 in dic): print('\nPlease choose a tag from the list displayed above.\n') time.sleep(1.0) else: break # get the duration time.sleep(1.0) duration = input("\nPlease enter the desired Patrol duration (in hours): ") duration_in_secs = float(duration) * 3600 # set the patrol log file name cur_time = datetime.datetime.now().strftime("%Y-%m-%d %H_%M_%S") filename = '{} - Patrol Test Results - Duration {} - {}.txt'.format( ID.upper(), duration, cur_time) # set variables before starting the patrol count = 1 timespent = 0.0 starttime = time.time() with StdoutTee(filename, buff=1): sys.stdout.write("\nStarted patrol") sys.stdout.write("\n--------------") while (timespent < duration_in_secs): # calculate time spent now = time.time() timespent = now - starttime # if charging is not complete, check if overall time spent exceeded duration. If it did, stop patroling. # Otherwise, check current charge. If it's greater than highBatteryPct, set charging is complete, # else sleep for BATTERY_CHECK_INTERVAL. if (not charge_complete): if (timespent > duration_in_secs): sys.stdout.write("\nExiting patrol while charging.") break cur_charge = getChargeLevelSafe(utils) if (cur_charge > highBatteryPct): charge_complete = True else: time.sleep(BATTERY_CHECK_INTERVAL) # if charging is still not complete, continue to check in the next loop. if (not charge_complete): continue # patrol only when we have enough charge or when charging is complete if (cur_charge > lowBatteryPct): cur_time = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S") sys.stdout.write("\nIteration {} - {} - Driving to {}".format( count, cur_time, tag1)) # drive to tag 1 state = utils.driveRobotToTag(dic[tag1]) utils.waitOnComplete() # increase lap count count = count + 1 cur_time = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S") sys.stdout.write("\nIteration {} - {} - Driving to {}".format( count, cur_time, tag2)) # drive to tag 2 state = utils.driveRobotToTag(dic[tag2]) utils.waitOnComplete() # increase lap count count = count + 1 # get current charge and if there isn't enough, set charge_complete to False and return to dock cur_charge = getChargeLevelSafe(utils) if (cur_charge < lowBatteryPct): charge_complete = False sys.stdout.write("\nReturning to dock after " + str(count - 1) + " rounds") utils.dockRobot() sys.stdout.write("\nCompleted patrol") sys.stdout.write("\n----------------") sys.stdout.write( "\nCompleted patroling for {} hours, and completed a total of {} iterations\n\n" .format(duration, count - 1)) #dock robot after patrol sys.stdout.write("\nReturning to dock.") utils.dockRobot()
def adjust_learning_rate(optimizer, epoch): """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" lr = args.lr * (0.5 ** (epoch // 30)) for param_group in optimizer.param_groups: param_group['lr'] = lr def accuracy(output, target, topk=(1,)): """Computes the precision@k for the specified values of k""" maxk = max(topk) batch_size = target.size(0) _, pred = output.topk(maxk, 1, True, True) pred = pred.t() correct = pred.eq(target.view(1, -1).expand_as(pred)) res = [] for k in topk: correct_k = correct[:k].view(-1).float().sum(0) res.append(correct_k.mul_(100.0 / batch_size)) return res if __name__ == '__main__': multiprocessing.freeze_support() global args args = parser.parse_args() with StdoutTee(args.log_prefix + args.arch, buff=1024), StderrTee(args.log_prefix + args.arch+'_error', buff=1024): main()
def main(): # This HTTP requests logger will be over-written everytime this script runs from the start logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m-%d-%Y %I:%M:%S %p', filename='requests_logfile.txt', filemode='w', level=logging.DEBUG) # print("\nPlease enter the following details to get a list of tags") print("--------------------------------------------------------") # RMS = input("RMS (Example: swtest.ava8.net): ") # ID = input("Robot's ID: ") # UN = input("Username: "******"Password: "******"base.ava8.net" ID = "BA00155" UN = "mitgbfb" PS = "ap123" print('\nConnecting to robot ', ID, ' for patrol.') # TODO: configure local server to not rely on wifi dropouts utils = robotutils.RobotUtils(RMS, UN, PS, ID) # get current charge and set charge_complete accordingly cur_charge = getChargeLevelSafe(utils) charge_complete = False if cur_charge > lowBatteryPct: charge_complete = True # get a dictionary of tags time.sleep(1.0) print("\nRetrieving tags now.") dic = {} tagList = utils.getTagList() # if there are no tags to be found, exit if (tagList == None): print( '\nNo tags were found. Either check the credentials entered, if there are any ' + 'tags in the map, or if the robot is connected to the correct rms. Exiting program.\n' ) time.sleep(10.0) exit() for key, values in tagList.items(): dic[values["name"].lower()] = key print('\nPlease specify the patrol route by aisles.') aisles = input('\nWhat is the last occupied aisle? (choose: A/B/C/D)') if aisles == 'A' or aisles == 'a': listoftags = ["entering_staging", "a_1", "a_2", "a_1"] elif aisles == 'B' or aisles == 'b': listoftags = [ "entering_staging", "a_1", "a_2", "b_3", "b_4", "b_1", "b_2", "b_1" ] elif aisles == 'C' or aisles == 'c': listoftags = [ "entering_staging", "a_1", "a_2", "b_3", "b_4", "b_1", "b_2", "c_3", "c_4", "c_1", "c_2", "c_1" ] else: listoftags = [ "entering_staging", "a_1", "a_2", "b_3", "b_4", "b_1", "b_2", "c_3", "c_4", "c_1", "c_2", "d_3", "d_4", "d_1", "d_2", "e_3", "e_4" ] # check and re-enter tag names till they are correct wrongtags = 0 for tagi in listoftags: if not (tagi in dic): print('\nThe tag ', tagi, 'is not a valid tag.') wrongtags = wrongtags + 1 if wrongtags > 0: print( '\nThe patrol route contained invalid tags. Please check from the list of tags:' ) print("\n------------- TAGS ---------------------") for key, values in dic.items(): print(key) print("----------------------------------") # get a correct list for the robot listoftags = [] ("\nPlease re-enter the list: ") listlength = int(input("\nEnter the total number of tags: ")) # iterate for i in range(0, listlength): while True: tag_i = input("Tag {} of {}: ".format(i + 1, listlength)) if not (tag_i in dic): print( '\nPlease choose a tag from the list displayed above.\n' ) time.sleep(1.0) else: break listoftags.append(tag_i) print("--------------------------------------------") print("\nThe tags to patrol are: \n") print(*listoftags, sep=", ") print("---------------------------------------------") duration = .1 sys.stdout.write("\nPerforming a single patrol route of specified tags") duration_in_secs = float(duration) * 3600 # set the patrol log file name cur_time = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S") filename = '{}_PatrolTestResults_{}.txt'.format(ID.upper(), cur_time) # set variables before starting the patrol count = 1 timespent = 0.0 starttime = time.time() # Define the UVC Lights UVCLights = Messenger(None, None, None) #remote ip, port, host ip UVCLights.ip = "172.18.0.50" UVCLights.port = 8888 UVCLights.host = "172.18.0.1" with StdoutTee(filename, buff=1): lightson = input("\nTurn on UVC Lights? (Y/N)") if lightson == 'Y' or lightson == 'y': print('\nTurning on UVC Lights') UVCLights.beginUVCLights() else: print('\n Okay, no UVC Lights') sys.stdout.write("\nStarted patrol") sys.stdout.write("\n--------------") while (timespent < duration_in_secs and count < 2): # calculate time spent now = time.time() timespent = now - starttime # if charging is not complete, check if overall time spent exceeded duration. If it did, stop patroling. # Otherwise, check current charge. If it's greater than highBatteryPct, set charging is complete, # else sleep for BATTERY_CHECK_INTERVAL. if (not charge_complete): if (timespent > duration_in_secs): sys.stdout.write("\nExiting patrol while charging.") break cur_charge = getChargeLevelSafe(utils) if (cur_charge > highBatteryPct): charge_complete = True else: time.sleep(BATTERY_CHECK_INTERVAL) # if charging is still not complete, continue to check in the next loop. if (not charge_complete): continue # patrol only when we have enough charge or when charging is complete if (cur_charge > lowBatteryPct): # Patrol the set of tags in a list for tagi in listoftags: cur_time = cur_time = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S") sys.stdout.write( "\nIteration {} - {} - Driving to {}".format( count, cur_time, tagi)) # drive to tag ii state = utils.driveRobotToTag(dic[tagi]) utils.waitOnComplete() # check battery status # get current charge and if there isn't enough, set charge_complete to False and return to dock cur_charge = getChargeLevelSafe(utils) if (cur_charge < lowBatteryPct): charge_complete = False sys.stdout.write("\nReturning to dock after " + str(count - 1) + " rounds") count = count + 1 utils.dockRobot() # increase lap count count = count + 1 # get current charge and if there isn't enough, set charge_complete to False and return to dock cur_charge = getChargeLevelSafe(utils) if (cur_charge < lowBatteryPct): charge_complete = False sys.stdout.write("\nReturning to dock after " + str(count - 1) + " rounds") utils.dockRobot() sys.stdout.write("\nCompleted patrol") sys.stdout.write("\n----------------") sys.stdout.write( "\nCompleted patrolling for {} hours, and completed a total of {} iterations\n\n" .format(duration, count - 1)) # turn off UVC lights if lightson == 'Y' or lightson == 'y': print('\nTurning off UVC Lights') UVCLights.stopUVCLights() #dock robot after patrol sys.stdout.write("\nReturning to dock.") utils.dockRobot()
def main(): # This HTTP requests logger will be over-written everytime this script runs from the start logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m-%d-%Y %I:%M:%S %p', filename='requests_logfile.txt', filemode='w', level=logging.DEBUG) # print("\nPlease enter the following details to get a list of tags") print("--------------------------------------------------------") # RMS = input("RMS (Example: swtest.ava8.net): ") # ID = input("Robot's ID: ") # UN = input("Username: "******"Password: "******"base.ava8.net" ID = "BA00155" UN = "mitgbfb" PS = "ap123" print('\nConnecting to robot ',ID,' for patrol.') # TODO: configure local server to not rely on wifi dropouts utils = robotutils.RobotUtils(RMS,UN,PS,ID) # get current charge and set charge_complete accordingly cur_charge = getChargeLevelSafe(utils) charge_complete = False if cur_charge > lowBatteryPct: charge_complete = True listoftags = [] duration = .1 sys.stdout.write("\nReturning to Base") duration_in_secs = float(duration) * 3600 # set the patrol log file name cur_time = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S") filename='{}_RTB_{}.txt'.format(ID.upper(),cur_time) # set variables before starting the patrol count = 1 timespent = 0.0 starttime = time.time() # Define the UVC Lights UVCLights = Messenger(None,None,None) #remote ip, port, host ip UVCLights.ip = "172.18.0.50" UVCLights.port = 8888 UVCLights.host = "172.18.0.1" with StdoutTee(filename, buff=1): lightson = input("\nTurn on UVC Lights? (Y/N)") if lightson == 'Y' or lightson == 'y': print('\nTurning on UVC Lights') UVCLights.beginUVCLights() else: UVCLights.stopUVCLights() print('\n Okay, no UVC Lights') sys.stdout.write("\n--------------") while(timespent < duration_in_secs and count < 2): # calculate time spent now = time.time() timespent = now - starttime # if charging is not complete, check if overall time spent exceeded duration. If it did, stop patroling. # Otherwise, check current charge. If it's greater than highBatteryPct, set charging is complete, # else sleep for BATTERY_CHECK_INTERVAL. if (not charge_complete): if (timespent > duration_in_secs): sys.stdout.write("\nExiting patrol while charging.") break cur_charge = getChargeLevelSafe(utils) if (cur_charge > highBatteryPct): charge_complete = True else: time.sleep(BATTERY_CHECK_INTERVAL) # if charging is still not complete, continue to check in the next loop. if (not charge_complete): continue # patrol only when we have enough charge or when charging is complete if (cur_charge > lowBatteryPct): # Patrol the set of tags in a list for tagi in listoftags: cur_time = cur_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") sys.stdout.write("\nIteration {} - {} - Driving to {}".format(count, cur_time, tagi)) # drive to tag ii state = utils.driveRobotToTag(dic[tagi]) utils.waitOnComplete() # check battery status # get current charge and if there isn't enough, set charge_complete to False and return to dock cur_charge = getChargeLevelSafe(utils) if (cur_charge < lowBatteryPct): charge_complete = False sys.stdout.write("\nReturning to dock after " + str(count-1) + " rounds") count = count + 1 utils.dockRobot() # increase lap count count = count + 1 # get current charge and if there isn't enough, set charge_complete to False and return to dock cur_charge = getChargeLevelSafe(utils) if (cur_charge < lowBatteryPct): charge_complete = False sys.stdout.write("\nReturning to dock after " + str(count-1) + " rounds") utils.dockRobot() sys.stdout.write("\nCompleted patrol") sys.stdout.write("\n----------------") sys.stdout.write("\nCompleted patrolling for {} hours, and completed a total of {} iterations\n\n".format(duration, count-1)) # turn off UVC lights if lightson == 'Y' or lightson == 'y': print('\nTurning off UVC Lights') UVCLights.stopUVCLights() #dock robot after patrol sys.stdout.write("\nReturning to dock.") utils.dockRobot()
help="number of epochs") args = parser.parse_args() device = torch.device("cuda:0") def make_base_model(): resnet18 = base_model.ResNet18(pretrained=True) model = base_model.MyModel(resnet18).to(device) return model def make_gaussian_model(): resnet18 = gaussian_model.ResNet18(pretrained=True) model = gaussian_model.GaussianModel(resnet18).to(device) return model epochs = args.epochs with StdoutTee(f"{log_dir}/log-gaussian.txt", mode='w', buff=1): run_train(model_name='gaussian', model_f=make_gaussian_model, EPOCHS=epochs, log_dir=log_dir) gc.collect() with StdoutTee(f"{log_dir}/log-base.txt", mode='w', buff=1): run_train(model_name='base', model_f=make_base_model, EPOCHS=epochs, log_dir=log_dir)
for i, (input, target) in enumerate(train_loader): # print('epoch', epoch, 'train input', input.size(),'target', target.size()) pass time_end = time.time() meter_train.update(time_end - time_start) print('Load train data for epoch {} takes {:.2f} seconds'.format( epoch, meter_train.sum)) time_start = time.time() for i, (input, target) in enumerate(val_loader): # print('epoch', epoch, 'test input', input.size(),'target', target.size()) pass time_end = time.time() meter_test.update(time_end - time_start) # print meter for one epoch print('Load test data for epoch {} takes {:.2f} seconds'.format( epoch, meter_test.sum)) cost = time.time() - time_begin print('Total cost: {:.2f} seconds = {:.2f} minutes'.format( cost, cost / 60.)) if __name__ == '__main__': log_dir = BASE + '/logs' if not os.path.exists(log_dir): os.mkdir(log_dir) with StdoutTee(BASE + '/logs/test', buff=1024), StderrTee(BASE + '/logs/test_error', buff=1024): test_loader() # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4