コード例 #1
0
ファイル: fcn_xs.py プロジェクト: zhaw/wine_private
def main():
    fcnxs = symbol_fcnxs.get_fcn32s_symbol(numclass=2, workspace_default=1536)
    fcnxs_model_prefix = "model_pascal/FCN32s_VGG16"
    num_epoch = 1
    learning_rate = 1e-3
    if args.model == "fcn16s":
        fcnxs = symbol_fcnxs.get_fcn16s_symbol(numclass=2, workspace_default=1536)
        fcnxs_model_prefix = "model_pascal/FCN16s_VGG16"
        learning_rate = 1e-5
    elif args.model == "fcn8s":
        fcnxs = symbol_fcnxs.get_fcn8s_symbol(numclass=2, workspace_default=1536)
        fcnxs_model_prefix = "model_pascal/FCN8s_VGG16"
        num_epoch = 30
        learning_rate = 1e-7
    arg_names = fcnxs.list_arguments()
    _, fcnxs_args, fcnxs_auxs = mx.model.load_checkpoint(args.prefix, args.epoch)
    if not args.retrain:
        if args.init_type == "vgg16":
            fcnxs_args, fcnxs_auxs = init_fcnxs.init_from_vgg16(ctx, fcnxs, fcnxs_args, fcnxs_auxs)
        elif args.init_type == "fcnxs":
            fcnxs_args, fcnxs_auxs = init_fcnxs.init_from_fcnxs(ctx, fcnxs, fcnxs_args, fcnxs_auxs)
    train_dataiter = FileIter(
        root_dir             = ".",
        flist_name           = "train.lst",
        # cut_off_size         = 400,
        rgb_mean             = (123.68, 116.779, 103.939),
        )
#     val_dataiter = FileIter(
#         root_dir             = "/home/zw/dataset/VOC2012Segmentation/VOC2012",
#         flist_name           = "val.lst",
#         rgb_mean             = (123.68, 116.779, 103.939),
#         )
    model = Solver(
        ctx                 = ctx,
        symbol              = fcnxs,
        begin_epoch         = 0,
        num_epoch           = num_epoch,
        arg_params          = fcnxs_args,
        aux_params          = fcnxs_auxs,
        learning_rate       = learning_rate,
        momentum            = 0.9,
        wd                  = 0.0001)
    model.fit(
        train_data          = train_dataiter,
#         eval_data           = val_dataiter,
        batch_end_callback  = mx.callback.Speedometer(1, 10),
        epoch_end_callback  = mx.callback.do_checkpoint(fcnxs_model_prefix))
コード例 #2
0
def main():
    
    fcnxs = symbol_fcnxs.get_fcn32s_symbol(numclass=21, workspace_default=1536)
    
    fcnxs_model_prefix = "model_pascal/FCN32s_VGG16"
    if args.model == "fcn16s":
        fcnxs = symbol_fcnxs.get_fcn16s_symbol(numclass=21, workspace_default=1536)
        fcnxs_model_prefix = "model_pascal/FCN16s_VGG16"
    elif args.model == "fcn8s":
        fcnxs = symbol_fcnxs.get_fcn8s_symbol(numclass=21, workspace_default=1536)
        fcnxs_model_prefix = "model_pascal/FCN8s_VGG16"
    arg_names = fcnxs.list_arguments()
    _, fcnxs_args, fcnxs_auxs = mx.model.load_checkpoint(args.prefix, args.epoch)
    # print arg_names
    
    if not args.retrain:
        if args.init_type == "vgg16":
            
            fcnxs_args, fcnxs_auxs = init_fcnxs.init_from_vgg16(ctx, fcnxs, fcnxs_args, fcnxs_auxs)
        elif args.init_type == "fcnxs":
            fcnxs_args, fcnxs_auxs = init_fcnxs.init_from_fcnxs(ctx, fcnxs, fcnxs_args, fcnxs_auxs)
    train_dataiter = FileIter(
        root_dir             = "./VOC2012",
        flist_name           = "train.lst",
        # cut_off_size         = 400,
        rgb_mean             = (123.68, 116.779, 103.939),
        )
    val_dataiter = FileIter(
        root_dir             = "./VOC2012",
        flist_name           = "val.lst",
        rgb_mean             = (123.68, 116.779, 103.939),
        )
    model = Solver(
        ctx                 = ctx,
        symbol              = fcnxs,
        begin_epoch         = 0,
        num_epoch           = 50,
        arg_params          = fcnxs_args,
        aux_params          = fcnxs_auxs,
        learning_rate       = 1e-10,
        momentum            = 0.99,
        wd                  = 0.0005)
    model.fit(
        train_data          = train_dataiter,
        eval_data           = val_dataiter,
        batch_end_callback  = mx.callback.Speedometer(1, 10),
        epoch_end_callback  = mx.callback.do_checkpoint(fcnxs_model_prefix))
コード例 #3
0
def main():
    ctx = mx.cpu() if not args.gpu else mx.gpu(args.gpu)
    fcnxs = symbol_fcnxs.get_fcn32s_symbol(numclass=21, workspace_default=1536)
    fcnxs_model_prefix = "model_pascal/FCN32s_VGG16"
    if args.model == "fcn16s":
        fcnxs = symbol_fcnxs.get_fcn16s_symbol(numclass=21, workspace_default=1536)
        fcnxs_model_prefix = "model_pascal/FCN16s_VGG16"
    elif args.model == "fcn8s":
        fcnxs = symbol_fcnxs.get_fcn8s_symbol(numclass=21, workspace_default=1536)
        fcnxs_model_prefix = "model_pascal/FCN8s_VGG16"
    arg_names = fcnxs.list_arguments()
    _, fcnxs_args, fcnxs_auxs = mx.model.load_checkpoint(args.prefix, args.epoch)
    if not args.retrain:
        if args.init_type == "vgg16":
            fcnxs_args, fcnxs_auxs = init_fcnxs.init_from_vgg16(ctx, fcnxs, fcnxs_args, fcnxs_auxs)
        elif args.init_type == "fcnxs":
            fcnxs_args, fcnxs_auxs = init_fcnxs.init_from_fcnxs(ctx, fcnxs, fcnxs_args, fcnxs_auxs)
    train_dataiter = FileIter(
        root_dir             = "./VOC2012",
        flist_name           = "train.lst",
        # cut_off_size         = 400,
        rgb_mean             = (123.68, 116.779, 103.939),
        )
    val_dataiter = FileIter(
        root_dir             = "./VOC2012",
        flist_name           = "val.lst",
        rgb_mean             = (123.68, 116.779, 103.939),
        )
    model = Solver(
        ctx                 = ctx,
        symbol              = fcnxs,
        begin_epoch         = 0,
        num_epoch           = 50,
        arg_params          = fcnxs_args,
        aux_params          = fcnxs_auxs,
        learning_rate       = 1e-10,
        momentum            = 0.99,
        wd                  = 0.0005)
    model.fit(
        train_data          = train_dataiter,
        eval_data           = val_dataiter,
        batch_end_callback  = mx.callback.Speedometer(1, 10),
        epoch_end_callback  = mx.callback.do_checkpoint(fcnxs_model_prefix))
コード例 #4
0
ファイル: fcn.py プロジェクト: wywywy01/Deformable-ConvNets
def main():
    devs = mx.cpu() if args.gpus is None or args.gpus is '' else [
        mx.gpu(int(i)) for i in args.gpus.split(',')
    ]
    carvn_root = ''
    num_classes = 2
    cutoff = None if args.cutoff == 0 else args.cutoff
    epochs = [74, 2, 1, 1]
    if not os.path.exists(args.model_dir):
        os.mkdir(args.model_dir)
    model_prefixes = [
        'VGG_FC_ILSVRC_16_layers', args.model_dir + "/FCN32s_VGG16",
        args.model_dir + "/FCN16s_VGG16", args.model_dir + "/FCN8s_VGG16"
    ]
    if args.model == "fcn16s":
        fcnxs = symbol_fcnxs.get_fcn16s_symbol(numclass=num_classes,
                                               workspace_default=1536)
        fcnxs_model_prefix = model_prefixes[2]
        load_prefix = model_prefixes[1]
        lr = 1e-5
        run_epochs = epochs[2]
        load_epoch = epochs[1]
    elif args.model == "fcn8s":
        fcnxs = symbol_fcnxs.get_fcn8s_symbol(numclass=num_classes,
                                              workspace_default=1536)
        fcnxs_model_prefix = model_prefixes[3]
        load_prefix = model_prefixes[2]
        lr = 1e-6
        run_epochs = epochs[3]
        load_epoch = epochs[2]
    else:
        fcnxs = symbol_fcnxs.get_fcn32s_symbol(numclass=num_classes,
                                               workspace_default=1536)
        fcnxs_model_prefix = model_prefixes[1]
        load_prefix = model_prefixes[0]
        lr = 1e-4
        run_epochs = epochs[1]
        load_epoch = epochs[0]
    arg_names = fcnxs.list_arguments()
    print('loading', load_prefix, load_epoch)
    print('lr', lr)
    print('model_prefix', fcnxs_model_prefix)
    print('running epochs', run_epochs)
    print('cutoff size', cutoff)
    args.batch_size = len(devs)
    _, fcnxs_args, fcnxs_auxs = mx.model.load_checkpoint(
        load_prefix, load_epoch)
    ctx = mx.cpu()
    if not args.retrain:
        if args.model == "fcn16s" or args.model == "fcn8s":
            fcnxs_args, fcnxs_auxs = init_fcnxs.init_from_fcnxs(
                ctx, fcnxs, fcnxs_args, fcnxs_auxs)
        else:
            fcnxs_args, fcnxs_auxs = init_fcnxs.init_from_vgg16(
                ctx, fcnxs, fcnxs_args, fcnxs_auxs)
    train_dataiter = BatchFileIter(
        path_imglist="../data/train.lst",
        cut_off_size=cutoff,
        rgb_mean=(123.68, 116.779, 103.939),
        batch_size=args.batch_size,
    )
    val_dataiter = BatchFileIter(
        path_imglist="../data/val.lst",
        cut_off_size=cutoff,
        rgb_mean=(123.68, 116.779, 103.939),
        batch_size=args.batch_size,
    )

    # learning rate
    kv = mx.kvstore.create('local')

    # create model
    model = mx.mod.Module(
        context=devs,
        symbol=fcnxs,
        #label_names   = ['softmax_label', 'softmax2_label']
    )
    optimizer_params = {'learning_rate': lr, 'momentum': 0.99, 'wd': 0.0005}
    _dice = DiceMetric()
    _acc = AccMetric()
    eval_metrics = [mx.metric.create(_dice), mx.metric.create(_acc)]
    initializer = mx.init.Xavier(rnd_type='gaussian',
                                 factor_type="in",
                                 magnitude=2)
    model.fit(
        train_dataiter,
        begin_epoch=0,
        num_epoch=run_epochs,
        #eval_data          = val_dataiter,
        eval_metric=eval_metrics,
        kvstore=kv,
        optimizer='sgd',
        optimizer_params=optimizer_params,
        initializer=initializer,
        arg_params=fcnxs_args,
        aux_params=fcnxs_auxs,
        batch_end_callback=mx.callback.Speedometer(args.batch_size, 10),
        epoch_end_callback=mx.callback.do_checkpoint(fcnxs_model_prefix),
        allow_missing=True)
コード例 #5
0
def main():
    gpu_list = []
    _gpus = args.gpu.split(',')
    for _gpu in _gpus:
      _gpu = _gpu.strip()
      if len(_gpu)==0:
        continue
      gpu_list.append(int(_gpu))
    assert len(gpu_list)>0
    ctx = mx.gpu(gpu_list[0])
    carvn_root = ''
    num_classes = 2
    cutoff = None if args.cutoff==0 else args.cutoff
    epochs = [74,31,27,19]
    model_prefixes = ['VGG_FC_ILSVRC_16_layers', args.model_dir+"/FCN32s_VGG16", args.model_dir+"/FCN16s_VGG16", args.model_dir+"/FCN8s_VGG16"]
    if args.model == "fcn16s":
      fcnxs = symbol_fcnxs.get_fcn16s_symbol(numclass=num_classes, workspace_default=1536)
      fcnxs_model_prefix = model_prefixes[2]
      load_prefix = model_prefixes[1]
      lr = 1e-5
      run_epochs = epochs[2]
      load_epoch = epochs[1]
    elif args.model == "fcn8s":
      fcnxs = symbol_fcnxs.get_fcn8s_symbol(numclass=num_classes, workspace_default=1536)
      fcnxs_model_prefix = model_prefixes[3]
      load_prefix = model_prefixes[2]
      lr = 1e-6
      run_epochs = epochs[3]
      load_epoch = epochs[2]
    else:
      fcnxs = symbol_fcnxs.get_fcn32s_symbol(numclass=num_classes, workspace_default=1536)
      fcnxs_model_prefix = model_prefixes[1]
      load_prefix = model_prefixes[0]
      lr = 1e-4
      run_epochs = epochs[1]
      load_epoch = epochs[0]
    arg_names = fcnxs.list_arguments()
    print('loading', load_prefix, load_epoch)
    print('lr', lr)
    print('model_prefix', fcnxs_model_prefix)
    print('running epochs', run_epochs)
    _, fcnxs_args, fcnxs_auxs = mx.model.load_checkpoint(load_prefix, load_epoch)
    if not args.retrain:
      if args.model == "fcn16s" or args.model == "fcn8s":
        fcnxs_args, fcnxs_auxs = init_fcnxs.init_from_fcnxs(ctx, fcnxs, fcnxs_args, fcnxs_auxs)
      else:
        fcnxs_args, fcnxs_auxs = init_fcnxs.init_from_vgg16(ctx, fcnxs, fcnxs_args, fcnxs_auxs)
    train_dataiter = FileIter(
        root_dir             = carvn_root,
        flist_name           = "../data/train.lst",
        cut_off_size         = cutoff,
        rgb_mean             = (123.68, 116.779, 103.939),
        )
    val_dataiter = FileIter(
        root_dir             = carvn_root,
        flist_name           = "../data/val.lst",
        cut_off_size         = cutoff,
        rgb_mean             = (123.68, 116.779, 103.939),
        )
    model = Solver(
        ctx                 = ctx,
        symbol              = fcnxs,
        begin_epoch         = 0,
        num_epoch           = run_epochs,
        arg_params          = fcnxs_args,
        aux_params          = fcnxs_auxs,
        learning_rate       = lr,
        momentum            = 0.99,
        wd                  = 0.0005)
    _metric = DiceMetric()
    model.fit(
        train_data          = train_dataiter,
        eval_data           = val_dataiter,
        eval_metric         = _metric,
        batch_end_callback  = mx.callback.Speedometer(1, 10),
        epoch_end_callback  = mx.callback.do_checkpoint(fcnxs_model_prefix))