Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
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
Ejemplo n.º 5
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
#exit(0)
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
def load_config(mode=None):
    parser = argparse.ArgumentParser()
    parser.add_argument("--path",
                        "--checkpoints",
                        type=str,
                        default="./checkpoints",
                        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 == "test":
        #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
        if args.model:
            config.MODEL = args.model

    #test mode
    elif mode == 2:
        config.MODE = 2
        config.HR_SIZE = 0
        if args.model:
            config.MODEL = args.model
        else:
            config.MODEL = 3

    #eval mode
    elif mode == 3:
        config.MODE = 3
        if args.model:
            config.MODEL = args.model
        else:
            config.MODEL = 3

    return config