Ejemplo n.º 1
0
 def __init__(self, args):
     sub_dir = datetime.strftime(datetime.now(),
                                 '%m%d-%H%M%S')  # prepare saving path
     self.save_dir = os.path.join(args.save_dir, sub_dir)
     if not os.path.exists(self.save_dir):
         os.makedirs(self.save_dir)
     setlogger(os.path.join(self.save_dir, 'train.log'))  # set logger
     for k, v in args.__dict__.items():  # save args
         logging.info("{}: {}".format(k, v))
     self.args = args
    parser.add_argument('--print_step',
                        type=int,
                        default=50,
                        help='the interval of log training information')

    args = parser.parse_args()
    return args


if __name__ == '__main__':

    args = parse_args()
    os.environ['CUDA_VISIBLE_DEVICES'] = args.cuda_device.strip()
    # Prepare the saving path for the model
    sub_dir = args.model_name + '_' + datetime.strftime(
        datetime.now(), '%m%d-%H%M%S')
    save_dir = os.path.join(args.checkpoint_dir, sub_dir)
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)

    # set the logger
    setlogger(os.path.join(save_dir, 'train.log'))

    # save the args
    for k, v in args.__dict__.items():
        logging.info("{}: {}".format(k, v))

    trainer = train_utils(args, save_dir)
    trainer.setup()
    trainer.train()
if __name__ == '__main__':

    start_tm = datetime.now()
    args = parse_args()
    os.environ['CUDA_VISIBLE_DEVICES'] = args.cuda_device.strip()
    # Prepare the saving path for the test results
    sub_dir = args.model_name+'_'+args.data_name + '_' + datetime.strftime(start_tm, '%m%d-%H%M%S')
    save_dir = os.path.join(args.results_dir, sub_dir)
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)

    # Calculate the model file name
    model_file_name = model_file_name_from_args(args)

    # set the logger
    setlogger(os.path.join(save_dir, 'testing.log'))

    # save the args
    for k, v in args.__dict__.items():
        logging.info("{}: {}".format(k, v))

    tester = test_utils(args, save_dir, model_file_name)
    tester.setup()
    results = tester.test()
    end_tm = datetime.now()
    duration = end_tm - start_tm

    report(args=args, results=results, duration=duration, save_dir=save_dir)


Ejemplo n.º 4
0
                        help='batchsize of the training process')
    parser.add_argument('--num_workers',
                        type=int,
                        default=0,
                        help='the number of training process')

    args = parser.parse_args()
    return args


if __name__ == '__main__':

    args = parse_args()
    os.environ['CUDA_VISIBLE_DEVICES'] = args.cuda_device.strip()

    # get model name
    sub_dir = args.checkpoint_dir.split("\\")[-1]
    model_name = args.checkpoint_subdir.split("_")[0]

    # get the checkpoint file of best model
    path = args.checkpoint_dir
    f_list = os.listdir(path)
    files = [i for i in f_list if '.pth' in i]
    files.sort(key=lambda x: float(x.split('-')[1]), reverse=True)
    checkpoint_file = os.path.join(path, files[0])

    # set the test logger
    setlogger(os.path.join(path, 'test.log'))

    evaluater = Evaluate_Utils(args, model_name, checkpoint_file)
    evaluater.evaluate()