def load_config(mode, config_path): r"""loads model config Args: mode (int): 1: train, 2: test 3:eval reads from config file if not specified """ # load config file config = Config(config_path) # pre train mode if mode == 0: config.MODE = 0 # train mode if mode == 1: config.MODE = 1 # test mode elif mode == 2: config.MODE = 2 # eval mode elif mode == 3: config.MODE = 3 elif mode == 4: config.MODE = 4 return config
def load_config(mode=None): r"""loads model config Args: mode (int): 1: train, 2: test, reads from config file if not specified """ parser = argparse.ArgumentParser() parser.add_argument('-p', '--path', '--checkpoints', type=str, help='model checkpoints dir path ') # test mode if mode == 2 or mode == 3 or mode == 4: parser.add_argument('--output', type=str, help='path to the output directory') args = parser.parse_args() config_path = os.path.join(args.path, 'config.yml') # create checkpoints path if does't exist if not os.path.exists(args.path): os.makedirs(args.path) # copy config template if does't exist if not os.path.exists(config_path): copyfile('./config.yml.example', config_path) # load config file config = Config(config_path) # train mode if mode == 1: config.MODE = 1 # TODO # test mode elif mode == 2: config.MODE = 2 if args.output is not None: config.RESULTS = args.output # refinement mode elif mode == 3: config.MODE = 3 if args.output is not None: config.RESULTS = args.output # test with refinement mode elif mode == 4: config.MODE = 4 if args.output is not None: config.RESULTS = args.output return config
def load_config(mode=None): r"""loads model config Args: mode (int): 1: train, 2: test, 3: eval, reads from config file if not specified """ parser = argparse.ArgumentParser() parser.add_argument('--path', '--checkpoints', type=str, default='./checkpoints', help='model checkpoints path (default: ./checkpoints)') parser.add_argument('--model', type=int, choices=[1, 2, 3], help='1: edge model, 2: SR model, 3: joint SR model with edge enhancer') #import pdb;pdb.set_trace() # test mode if mode == 2: parser.add_argument('--input', type=str, help='path to the input images directory or an input image') parser.add_argument('--output', type=str, help='path to the output directory') args = parser.parse_args() config_path = os.path.join(args.path, 'config.yml') # create checkpoints path if does't exist if not os.path.exists(args.path): os.makedirs(args.path) # copy config template if does't exist if not os.path.exists(config_path): copyfile('./config.yml', config_path) # load config file config = Config(config_path) # train mode if mode == 1: config.MODE = 1 if args.model: config.MODEL = args.model # test mode elif mode == 2: config.MODE = 2 config.HR_SIZE = 0 config.MODEL = args.model if args.model is not None else 3 if args.input is not None: config.TEST_FLIST_LR = args.input if args.output is not None: config.RESULTS = args.output # eval mode elif mode == 3: config.MODE = 3 config.MODEL = args.model if args.model is not None else 3 return config
def load_config(mode=None): parser = argparse.ArgumentParser() parser.add_argument("--path", "--checkpoints", type=str, default="./checkpoints2", help="model checkpoint path, default = ./checkpoints") parser.add_argument( "--model", type=int, choices=[1, 2, 3], help="1: edge model, 2: SR model, 3: joint SR model with edge enhancer" ) parser.add_argument("--train_img_path", type=str, default="./train_images") parser.add_argument("--test_img_path", type=str, default="./test_images") parser.add_argument("--eval_img_path", type=str, default="./eval_images") if mode == 2: #parser.add_argument("--input", type = str, help = "path to a test image") parser.add_argument("--output", type=str, help="path to a output folder") args = parser.parse_args() create_data_list(args.train_img_path, args.test_img_path, args.eval_img_path, "./list_folder") config_path = os.path.join(args.path, "config.yaml") if not os.path.exists(args.path): os.makedirs(args.path) if not os.path.exists(config_path): copyfile('./config.yaml', config_path) config = Config(config_path) #train mode if mode == 1: config.MODE = 1 #test mode elif mode == 2: config.MODE = 2 #eval mode elif mode == 3: config.MODE = 3 return config
def load_config(mode=None): parser = argparse.ArgumentParser() parser.add_argument('--path', '--checkpoints', type=str, default='./checkpoints', help='model checkpoints path (default: ./checkpoints)') args = parser.parse_args() config_path = os.path.join(args.path, 'config.yml') config = Config(config_path) if mode == 1: config.MODE = 1 elif mode == 2: config.MODE = 2 return config
def load_config(mode=None): parser = argparse.ArgumentParser() parser.add_argument('--path', '--checkpoints', type=str, help='model checkpoints path') args = parser.parse_args() config_path = os.path.join(args.path, 'config.yml') # load config file config = Config(config_path) # train mode if mode == 1: config.MODE = 1 # test mode elif mode == 2: config.MODE = 2 return config
def load_config(): r"""loads model config """ parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument( '--config', type=str, default='config_example.json', help= 'configuration file name. Relative path under given path (default: config.yml)' ) parser.add_argument( '--loadbest', type=int, default=0, choices=[0, 1], help= '1: load best model or 0: load checkpoints. Only works in non training mode.' ) parser.add_argument('--mode', type=str, choices=['train', 'trace', 'eval'], help='mode. can be [train,trace,eval]', required=True) args = parser.parse_args() config_path = os.path.abspath(args.config) if not os.path.exists(config_path): raise RuntimeError('Targer config file does not exist. {}' & config_path) # load config file config = Config(config_path) if 'NAME' not in config: config_name = os.path.basename(args.config) if len(config_name) > len('config_'): name = config_name[len('config_'):] name = os.path.splitext(name)[0] translation_table = dict.fromkeys(map(ord, '!@#$'), None) name = name.translate(translation_table) config['NAME'] = name config.LOADBEST = args.loadbest config.MODE = args.mode return config
def load_config(mode=2): config_path = os.path.join('./psv','config.yml') # load config file config = Config(config_path) # test mode if mode == 2: config.MODE = 2 config.MODEL = 3 config.INPUT_SIZE = 0 #if args.input is not None: config.TEST_FLIST = './Images' #if args.mask is not None: config.TEST_MASK_FLIST = './Masks' #if args.output is not None: config.RESULTS = './results' return config
def load_config(mode=None): # ---------------------------------- # load model config # mode(int): 1 train, 2 test, 3 eval # ---------------------------------- parser = argparse.ArgumentParser() parser.add_argument('--path', '--checkpoints', type=str, default='./checkpoints/place2', help='model checkpoints path (default: ./checkpoints)') parser.add_argument('--model', type=int, default=1, choices=[1, 2, 3, 4], help='1: edge model, 2: inpaint model, 3: edge-inpaint model, 4: joint model') # test mode if mode == 2: parser.add_argument('--input', type=str, help='path to the input images directory or an input image') parser.add_argument('--mask', type=str, help='path to the masks directory or a mask file') parser.add_argument('--edge', type=str, help='path to the edges directory or an edge file') parser.add_argument('--output', type=str, help='path to the output directory') args = parser.parse_args() config_path = os.path.join(args.path, 'config.yml') # create checkpoints path if does't exist if not os.path.exists(args.path): os.makedirs(args.path) # copy config template if does't exist if not os.path.exists(config_path): # copyfile('./config.yml.example', config_path) print('Copy config....') copyfile('./config.yml', config_path) print('End copy config...') # load config file config = Config(config_path) # train mode if mode == 1: config.MODE = 1 if args.model: config.MODEL = args.model # test mode elif mode == 2: config.MODE = 2 config.MODEL = args.model if args.model is not None else 3 config.INPUT_SIZE = 0 if args.input is not None: config.TEST_FLIST = args.input if args.mask is not None: config.TEST_MASK_FLIST = args.mask if args.edge is not None: config.TEST_EDGE_FLIST = args.edge if args.output is not None: config.RESULTS = args.output # eval mode elif mode == 3: config.MODE = 3 config.MODEL = args.model if args.model is not None else 3 return config
def load_config(mode=None): r"""loads model config Args: mode (int): 1: train, 2: test, 3: eval, reads from config file if not specified """ parser = argparse.ArgumentParser() parser.add_argument('--config', type=str, default='./config/config.yml', help='model config file') parser.add_argument('--model', type=int, choices=[1, 2, 3, 4], help='1: edge model, 2: inpaint model, 3: edge-inpaint model, 4: joint model') # test mode # TODO: update if mode == 2: parser.add_argument('--input', type=str, help='path to the input images directory or an input image') parser.add_argument('--mask', type=str, help='path to the masks directory or a mask file') parser.add_argument('--edge', type=str, help='path to the edges directory or an edge file') parser.add_argument('--output', type=str, help='path to the output directory') args = parser.parse_args() # # copy config template if does't exist # if not os.path.exists(config_path): # copyfile('./config.yml.example', config_path) # load config file config = Config(args.config) # train mode if mode == 1: # create checkpoints path if does't exist if not os.path.exists(config.LOG_DIR): os.makedirs(config.LOG_DIR) if not os.path.exists(config.MODEL_DIR): os.makedirs(config.MODEL_DIR) config.MODE = 1 if args.model: config.MODEL = args.model # test mode elif mode == 2: config.MODE = 2 #config.MODEL = args.model if args.model is not None else 3 # Hack config.INPUT_SIZE = 0 # config._dict['WORD_BB_PERCENT_THRESHOLD'] = 0 config._dict['CHAR_BB_PERCENT_THRESHOLD'] = 0 config._dict['MASK_CORNER_OFFSET'] = 5 # TODO: update this part if args.input is not None: config.TEST_FLIST = args.input if args.mask is not None: config.TEST_MASK_FLIST = args.mask if args.edge is not None: config.TEST_EDGE_FLIST = args.edge if args.output is not None: config.RESULTS = args.output # eval mode elif mode == 3: config.MODE = 3 config.MODEL = args.model if args.model is not None else 3 return config
def load_config(mode=None): r"""loads model config Args: mode (int): 1: train, 2: test, 3: eval, reads from config file if not specified """ parser = argparse.ArgumentParser() parser.add_argument('--path', '--checkpoints', type=str, default='./checkpoints', help='model checkpoints path (default: ./checkpoints)') parser.add_argument('--model', type=int, choices=[1, 2, 3], help='1: landmark prediction model, 2: inpaint model, 3: joint model') # test mode if mode == 2: parser.add_argument('--input', type=str, help='path to the input images directory or an input image') parser.add_argument('--mask', type=str, help='path to the masks directory or a mask file') parser.add_argument('--landmark', type=str, help='path to the landmarks directory or a landmark file') parser.add_argument('--output', type=str, help='path to the output directory') args = parser.parse_args() config_path = os.path.join(args.path, 'config.yml') # create checkpoints path if does't exist if not os.path.exists(args.path): os.makedirs(args.path) # copy config template if does't exist if not os.path.exists(config_path): copyfile('./config.yml.example', config_path) # load config file config = Config(config_path) # train mode if mode == 1: config.MODE = 1 if args.model: config.MODEL = args.model # test mode elif mode == 2: config.MODE = 2 config.MODEL = args.model if args.model is not None else 3 if args.input is not None: config.TEST_INPAINT_IMAGE_FLIST = args.input if args.mask is not None: config.TEST_MASK_FLIST = args.mask if args.landmark is not None: config.TEST_INPAINT_LANDMARK_FLIST = args.landmark if args.output is not None: config.RESULTS = args.output # eval mode elif mode == 3: config.MODE = 3 config.MODEL = args.model if args.model is not None else 3 return config
def load_config(mode=None): r"""loads model config Args: mode (int): 1: train, 2: test, 3: eval, reads from config file if not specified """ parser = argparse.ArgumentParser() parser.add_argument('--path', '--checkpoints', type=str, default='./checkpoints', help='model checkpoints path (default: ./checkpoints)') parser.add_argument('--output', type=str, default='./output', help='path to the output directory') # test mode if mode == 2: parser.add_argument( '--input', type=str, help='path to the input images directory or an input image') parser.add_argument('--mask', type=str, help='path to the masks directory or a mask file') args = parser.parse_args() config_path = os.path.join(args.path, 'config.yml') # create checkpoints path if does't exist create_dir(args.path) # copy config template if does't exist if not os.path.exists(config_path): copyfile('./config.yml.example', config_path) # load config file config = Config(config_path) # train mode if mode == 1: config.MODE = 1 # test mode elif mode == 2: config.MODE = 2 # config.INPUT_SIZE = 0 Set to 0 for one to one mapping if args.input is not None: config.TEST_FLIST = args.input if args.mask is not None: config.TEST_MASK_FLIST = args.mask if args.output is not None: config.RESULTS = args.output # eval mode elif mode == 3: config.MODE = 3 return config
def load_config(mode=None): r"""loads model config Args: mode (int): 1: train, 2: test, 3: eval, reads from config file if not specified """ parser = argparse.ArgumentParser() parser.add_argument('--path', '--checkpoints', type=str, default='./checkpoints', help='model checkpoints path (default: ./checkpoints)') parser.add_argument('--output', type=str, default='./output', help='path to the output directory') # test mode if mode >= 2: parser.add_argument( '--input', type=str, help='path to the input images directory or an input image') parser.add_argument('--mask', type=str, help='path to the masks directory or a mask file') args = parser.parse_args() config_path = os.path.join(args.path, 'config.yml') # create checkpoints path if does't exist create_dir(args.path) # copy config template if does't exist if not os.path.exists(config_path): copyfile('./config.yml.example', config_path) # load config file config = Config(config_path) config.print() # train mode if mode == 1: config.MODE = 1 # test mode elif mode == 2: config.MODE = 2 # config.INPUT_SIZE = 0 Set to 0 for one to one mapping if args.input is not None: config.TEST_FLIST = args.input if args.mask is not None: config.TEST_MASK_FLIST = args.mask if args.output is not None: config.RESULTS = args.output # eval mode elif mode == 3: config.MODE = 3 # set cuda visble devices from config file # Initialization os.environ['CUDA_VISIBLE_DEVICES'] = ','.join(str(e) for e in config.GPU) # os.environ["CUDA_VISIBLE_DEVICES"] = "0" # init device if torch.cuda.is_available(): config.DEVICE = torch.device("cuda") torch.backends.cudnn.benchmark = True # cudnn auto-tuner else: config.DEVICE = torch.device("cpu") # set cv2 running threads to 1 (prevents deadlocks with pytorch dataloader) cv2.setNumThreads(0) # initialize random seed torch.manual_seed(config.SEED) torch.cuda.manual_seed_all(config.SEED) np.random.seed(config.SEED) random.seed(config.SEED) return config
def load_config(mode=None): r"""loads model config Args: mode (int): 1: train, 2: test, 3: eval, reads from config file if not specified """ parser = argparse.ArgumentParser() parser.add_argument('--path', '--checkpoints', type=str, default='./checkpoints', help='model checkpoints path (default: ./checkpoints)') parser.add_argument( '--model', type=int, choices=[1, 2, 3, 4], help= '1: edge model, 2: inpaint model, 3: edge-inpaint model, 4: joint model' ) # test mode if mode == 2: parser.add_argument( '--input', type=str, help='path to the input images directory or an input image') parser.add_argument('--mask', type=str, help='path to the masks directory or a mask file') parser.add_argument('--edge', type=str, help='path to the edges directory or an edge file') parser.add_argument('--output', type=str, help='path to the output directory') args = parser.parse_args() config_path = os.path.join(args.path, 'config.yml') # create checkpoints path if does't exist if not os.path.exists(args.path): os.makedirs(args.path) # copy config template if does't exist if not os.path.exists(config_path): copyfile('./config.yml.example', config_path) # load config file config = Config(config_path) # train mode if mode == 1: config.MODE = 1 if args.model: config.MODEL = args.model if config.SKIP_PHASE2 is None: config.SKIP_PHASE2 = 0 if config.MODEL == 2 and config.SKIP_PHASE2 == 1: raise Exception( "MODEL is 2, cannot skip phase2! trun config.SKIP_PHASE2 off or just use MODEL 3." ) # test mode elif mode == 2: config.MODE = 2 config.MODEL = args.model if args.model is not None else 3 config.INPUT_SIZE = 0 if args.input is not None: config.TEST_FLIST = args.input if args.mask is not None: config.TEST_MASK_FLIST = args.mask if args.edge is not None: config.TEST_EDGE_FLIST = args.edge if args.output is not None: config.RESULTS = args.output # eval mode elif mode == 3: config.MODE = 3 config.MODEL = args.model if args.model is not None else 3 return config
def load_config(mode=None): r"""loads model config Args: mode (int): 1: train, 2: test, 3: eval, reads from config file if not specified """ parser = argparse.ArgumentParser() parser.add_argument( "--path", "--checkpoints", type=str, default="./checkpoints", help="model checkpoints path (default: ./checkpoints)", ) parser.add_argument( "--model", type=int, choices=[1, 2, 3, 4], help="1: edge model, 2: inpaint model, 3: edge-inpaint model, 4: joint model", ) # test mode if mode == 2: parser.add_argument("--input", type=str, help="path to the input images directory or an input image") parser.add_argument("--mask", type=str, help="path to the masks directory or a mask file") parser.add_argument("--edge", type=str, help="path to the edges directory or an edge file") parser.add_argument("--output", type=str, help="path to the output directory") args = parser.parse_args() config_path = os.path.join(args.path, "config.yml") # create checkpoints path if does't exist if not os.path.exists(args.path): os.makedirs(args.path) # copy config template if does't exist if not os.path.exists(config_path): copyfile("./config.yml.example", config_path) # load config file config = Config(config_path) # train mode if mode == 1: config.MODE = 1 if args.model: config.MODEL = args.model # test mode elif mode == 2: config.MODE = 2 config.MODEL = args.model if args.model is not None else 3 config.INPUT_SIZE = 0 if args.input is not None: config.TEST_FLIST = args.input if args.mask is not None: config.TEST_MASK_FLIST = args.mask if args.edge is not None: config.TEST_EDGE_FLIST = args.edge if args.output is not None: config.RESULTS = args.output # eval mode elif mode == 3: config.MODE = 3 config.MODEL = args.model if args.model is not None else 3 return config
def load_config(mode=None): r"""loads model config """ parser = argparse.ArgumentParser() parser.add_argument('--path', '--checkpoints', type=str, default='./checkpoints', help='model checkpoints path (default: ./checkpoints)') parser.add_argument( '--model', type=int, choices=[1, 2, 3, 4], help= '1: edge model, 2: inpaint model, 3: edge-inpaint model, 4: joint model' ) # test mode parser.add_argument( '--input', type=str, help='path to the input images directory or an input image') parser.add_argument('--edge', type=str, help='path to the edges directory or an edge file') parser.add_argument('--output', type=str, help='path to the output directory') parser.add_argument('--remove', nargs='*', type=int, help='objects to remove') parser.add_argument('--cpu', type=str, help='machine to run segmentation model on') args = parser.parse_args() #if path for checkpoint not given if args.path is None: args.path = './checkpoints' config_path = os.path.join(args.path, 'config.yml') # create checkpoints path if does't exist if not os.path.exists(args.path): os.makedirs(args.path) # copy config template if does't exist if not os.path.exists(config_path): copyfile('./config.yml.example', config_path) # load config file config = Config(config_path) # test mode config.MODE = 2 config.MODEL = args.model if args.model is not None else 3 config.OBJECTS = args.remove if args.remove is not None else [3, 15] config.SEG_DEVICE = 'cpu' if args.cpu is not None else 'cuda' config.INPUT_SIZE = 256 if args.input is not None: config.TEST_FLIST = args.input if args.edge is not None: config.TEST_EDGE_FLIST = args.edge if args.output is not None: config.RESULTS = args.output else: if not os.path.exists('./results_images'): os.makedirs('./results_images') config.RESULTS = './results_images' return config
def load_config(mask_roi_path, image_roi_path, results_path, mode=None): r"""loads model config Args: mode (int): 1: train, 2: test, 3: eval, reads from config file if not specified """ parser = argparse.ArgumentParser() parser.add_argument('--path', '--checkpoints', type=str, default='./checkpoints/places2', help='model checkpoints path (default: ./checkpoints)') parser.add_argument( '--model', type=int, choices=[1, 2, 3, 4], help= '1: edge model, 2: inpaint model, 3: edge-inpaint model, 4: joint model' ) # test mode if mode == 2: parser.add_argument( '--input', type=str, default='./datasets/test/image_roi/', help='path to the input images directory or an input image') parser.add_argument('--mask', type=str, default='./datasets/test/mask_roi/', help='path to the masks directory or a mask file') parser.add_argument('--edge', type=str, help='path to the edges directory or an edge file') parser.add_argument('--output', type=str, default='./results/', help='path to the output directory') args = parser.parse_args() config_path = os.path.join(args.path, 'config.yml') args.input = image_roi_path args.mask = mask_roi_path args.output = results_path # create checkpoints path if does't exist if not os.path.exists(args.path): os.makedirs(args.path) # copy config template if does't exist if not os.path.exists(config_path): copyfile('./config.yml.example', config_path) # load config file config = Config(config_path) # train mode if mode == 1: config.MODE = 1 if args.model: config.MODEL = args.model # test mode elif mode == 2: config.MODE = 2 config.MODEL = args.model if args.model is not None else 3 config.INPUT_SIZE = 0 if args.input is not None: config.TEST_FLIST = args.input if args.mask is not None: config.TEST_MASK_FLIST = args.mask if args.edge is not None: config.TEST_EDGE_FLIST = args.edge if args.output is not None: config.RESULTS = args.output # eval mode elif mode == 3: config.MODE = 3 config.MODEL = args.model if args.model is not None else 3 return config
from torchFewShot.utils.avgmeter import AverageMeter from torchFewShot.utils.logger import Logger from torchFewShot.utils.torchtools import one_hot, adjust_learning_rate sys.path.append('/home/lijunjie/edge-connect-master') from shutil import copyfile from src.config import Config from src.edge_connect_few_shot import EdgeConnect #config = load_config(mode) config_path = os.path.join('/home/lijunjie/edge-connect-master/checkpoints/places2_authormodel', 'config.yml') config = Config(config_path) config.TEST_FLIST = '/home/lijunjie/edge-connect-master/examples/test_result/' config.TEST_MASK_FLIST = '/home/lijunjie/edge-connect-master/examples/places2/masks' config.RESULTS = './checkpoints/EC_test' config.MODE = 2 if config.MODE == 2: config.MODEL = 3 config.INPUT_SIZE = 0 config.mask_id=2 #if args.input is not None: #config.TEST_FLIST = args.input #if args.mask is not None: #config.TEST_MASK_FLIST = args.mask #if args.edge is not None: #config.TEST_EDGE_FLIST = args.edge #if args.output is not None: #config.RESULTS = args.output