Esempio n. 1
0
parser.add_argument(
    '--dataset_file',
    default=
    '/data6/users/xuran7/myresearch/dense_videocap/third_party/myfork/densecap/data/anet/anet_annotations_trainval.json',
    type=str)
parser.add_argument('--val_data_folder',
                    default='validation',
                    help='validation data folder')

parser.set_defaults(cuda=False, learn_mask=False, gated_mask=False)

args = parser.parse_args()
#pdb.set_trace()
with open(args.cfgs_file, 'r') as handle:
    options_yaml = yaml.load(handle)
update_values(options_yaml, vars(args))
print(args)


def eval_results(args):

    subprocess.Popen(["python2", args.densecap_eval_file, "-s", \
                      args.densecap_res, \
                      "-v", "-r"] + \
                      args.densecap_references \
                      )

    anet_proposal = ANETproposal(args.dataset_file,
                                 args.prop_res,
                                 tiou_thresholds=np.linspace(0.5, 0.95, 10),
                                 max_avg_nr_proposals=100,
Esempio n. 2
0
def parse_opt(train=True):
    parser = argparse.ArgumentParser()

    # Data input settings
    parser.add_argument('--cfgs_file',
                        default='cfgs/yc2.yml',
                        type=str,
                        help='dataset specific settings. anet | yc2')
    parser.add_argument('--dataset',
                        default='yc2',
                        type=str,
                        help='which dataset to use. two options: anet | yc2')
    parser.add_argument('--dataset_file', default='', type=str)
    parser.add_argument('--feature_root',
                        default='',
                        type=str,
                        help='the feature root')
    parser.add_argument('--dur_file', default='', type=str)
    parser.add_argument(
        '--start_from',
        default='',
        help=
        'path to a model checkpoint to initialize model weights from. Empty = dont'
    )
    if not train:
        parser.set_defaults(start_from='checkpoint/best_model.t7')
    parser.add_argument('--max_sentence_len', default=20, type=int)
    parser.add_argument('--num_workers', default=1, type=int)

    if train:
        parser.add_argument('--train_data_folder',
                            default=['training'],
                            type=str,
                            nargs='+',
                            help='training data folder')
        parser.add_argument('--val_data_folder',
                            default=['validation'],
                            help='validation data folder')
    else:
        parser.add_argument('--test_data_folder',
                            default=['validation'],
                            help='testing data folder')

    # Model settings: General
    # waiting for completion
    parser.add_argument('--temporal_scale',
                        default=200,
                        type=int,
                        help='length of observation window')
    parser.add_argument('--max_duration',
                        default=100,
                        type=int,
                        help='max proposal duration')
    parser.add_argument('--prop_boundary_ratio', type=int, default=0.5)
    parser.add_argument('--num_sample', type=int, default=32)
    parser.add_argument('--num_sample_perbin', type=int, default=3)
    parser.add_argument('--feat_dim', type=int, default=3072)

    # Optimization: General
    parser.add_argument(
        '--batch_size',
        default=8,
        type=int,
        help=
        'what is the batch size in number of images per batch? (there will be x seq_per_img sentences)'
    )
    parser.add_argument('--cuda',
                        dest='cuda',
                        action='store_true',
                        help='use gpu')
    parser.add_argument(
        '--id',
        default='',
        help=
        'an id identifying this run/job. used in cross-val and appended when writing progress files'
    )

    if train:
        # Optimization
        parser.add_argument('--max_epochs',
                            default=10,
                            type=int,
                            help='max number of epochs to run for')
        parser.add_argument(
            '--optim',
            default='sgd',
            help='what update to use? rmsprop|sgd|sgdmom|adagrad|adam')
        parser.add_argument('--learning_rate',
                            default=0.02,
                            type=float,
                            help='learning rate')
        parser.add_argument('--alpha',
                            default=0.95,
                            type=float,
                            help='alpha for adagrad/rmsprop/momentum/adam')
        parser.add_argument('--beta',
                            default=0.999,
                            type=float,
                            help='beta used for adam')
        parser.add_argument(
            '--epsilon',
            default=1e-8,
            help='epsilon that goes into denominator for smoothing')
        parser.add_argument('--loss_alpha_r',
                            default=10,
                            type=int,
                            help='The weight for regression loss')
        parser.add_argument('--patience_epoch',
                            default=1,
                            type=int,
                            help='Epoch to wait to determine a pateau')
        parser.add_argument('--reduce_factor',
                            default=0.5,
                            type=float,
                            help='Factor of learning rate reduction')
        parser.add_argument('--grad_norm',
                            default=1.5,
                            type=float,
                            help='Gradient clipping norm')

        # Evaluation/Checkpointing
        parser.add_argument('--calc_pos_neg',
                            dest='calc_pos_neg',
                            action='store_true')
        parser.add_argument('--save_checkpoint_every',
                            default=1,
                            type=int,
                            help='how many epochs to save a model checkpoint?')
        parser.add_argument(
            '--checkpoint_path',
            default='./checkpoint',
            help='folder to save checkpoints into (empty = this folder)')
        parser.add_argument(
            '--losses_log_every',
            default=1,
            type=int,
            help=
            'How often do we snapshot losses, for inclusion in the progress dump? (0 = disable)'
        )
        parser.add_argument('--seed',
                            default=213,
                            type=int,
                            help='random number generator seed to use')
    else:
        # Model settings: Proposal and mask
        parser.add_argument('--soft_nms_alpha', default=0.4, type=float)
        parser.add_argument('--soft_nms_low_thres', default=0.5, type=float)
        parser.add_argument('--soft_nms_high_thres', default=0.9, type=float)

    parser.set_defaults(cuda=True)
    args = parser.parse_args()
    if train:
        args.learning_rate /= args.batch_size
        args.grad_norm *= args.batch_size
        print('lr=', args.learning_rate)

    import os
    path = os.path.dirname(__file__)
    with open(os.path.join(path, args.cfgs_file), 'r') as handle:
        options_yaml = yaml.load(handle)
    update_values(options_yaml, vars(args))

    return args
Esempio n. 3
0
def parse_args():
    parser = argparse.ArgumentParser()

    # Data input settings
    parser.add_argument('--cfgs_file',
                        default='cfgs/anet.yml',
                        type=str,
                        help='dataset specific settings. anet | yc2')
    parser.add_argument('--dataset',
                        default='',
                        type=str,
                        help='which dataset to use. two options: anet | yc2')
    parser.add_argument('--dataset_file', default='', type=str)
    parser.add_argument('--feature_root',
                        default='',
                        type=str,
                        help='the feature root')
    parser.add_argument('--dur_file', default='', type=str)
    parser.add_argument('--train_data_folder',
                        default=['training'],
                        type=str,
                        nargs='+',
                        help='training data folder')
    parser.add_argument('--val_data_folder',
                        default=['validation'],
                        help='validation data folder')
    parser.add_argument('--save_train_samplelist', action='store_true')
    parser.add_argument('--load_train_samplelist', action='store_true')
    parser.add_argument(
        '--train_samplelist_path',
        type=str,
        default='/z/home/luozhou/subsystem/densecap_vid/train_samplelist.pkl')
    parser.add_argument('--save_valid_samplelist', action='store_true')
    parser.add_argument('--load_valid_samplelist', action='store_true')
    parser.add_argument(
        '--valid_samplelist_path',
        type=str,
        default='/z/home/luozhou/subsystem/densecap_vid/valid_samplelist.pkl')
    parser.add_argument(
        '--start_from',
        default='',
        help=
        'path to a model checkpoint to initialize model weights from. Empty = dont'
    )
    parser.add_argument('--max_sentence_len', default=20, type=int)
    parser.add_argument('--num_workers', default=1, type=int)

    # Model settings: General
    parser.add_argument(
        '--d_model',
        default=1024,
        type=int,
        help='size of the rnn in number of hidden nodes in each layer')
    parser.add_argument('--d_hidden', default=2048, type=int)
    parser.add_argument('--n_heads', default=8, type=int)
    parser.add_argument('--in_emb_dropout', default=0.1, type=float)
    parser.add_argument('--attn_dropout', default=0.2, type=float)
    parser.add_argument('--vis_emb_dropout', default=0.1, type=float)
    parser.add_argument('--cap_dropout', default=0.2, type=float)
    parser.add_argument('--image_feat_size',
                        default=3072,
                        type=int,
                        help='the encoding size of the image feature')
    parser.add_argument('--n_layers',
                        default=2,
                        type=int,
                        help='number of layers in the sequence model')
    parser.add_argument(
        '--train_sample',
        default=20,
        type=int,
        help='total number of positive+negative training samples (2*U)')
    parser.add_argument(
        '--sample_prob',
        default=0,
        type=float,
        help='probability for use model samples during training')

    # Model settings: Proposal and mask
    parser.add_argument('--slide_window_size',
                        default=480,
                        type=int,
                        help='the (temporal) size of the sliding window')
    parser.add_argument('--slide_window_stride',
                        default=20,
                        type=int,
                        help='the step size of the sliding window')
    parser.add_argument(
        '--sampling_sec',
        default=0.5,
        help='sample frame (RGB and optical flow) with which time interval')
    parser.add_argument('--kernel_list',
                        default=[
                            1, 2, 3, 4, 5, 7, 9, 11, 15, 21, 29, 41, 57, 71,
                            111, 161, 211, 251
                        ],
                        type=int,
                        nargs='+')
    parser.add_argument('--pos_thresh', default=0.7, type=float)
    parser.add_argument('--neg_thresh', default=0.3, type=float)
    parser.add_argument(
        '--stride_factor',
        default=50,
        type=int,
        help=
        'the proposal temporal conv kernel stride is determined by math.ceil(kernel_len/stride_factor)'
    )

    # Optimization: General
    parser.add_argument('--max_epochs',
                        default=20,
                        type=int,
                        help='max number of epochs to run for')
    parser.add_argument(
        '--batch_size',
        default=32,
        type=int,
        help=
        'what is the batch size in number of images per batch? (there will be x seq_per_img sentences)'
    )
    parser.add_argument('--valid_batch_size', default=64, type=int)
    parser.add_argument('--cls_weight', default=1.0, type=float)
    parser.add_argument('--reg_weight', default=10, type=float)
    parser.add_argument('--sent_weight', default=0.25, type=float)
    parser.add_argument('--scst_weight', default=0.0, type=float)
    parser.add_argument('--mask_weight', default=0.0, type=float)
    parser.add_argument('--gated_mask', action='store_true', dest='gated_mask')

    # Optimization
    parser.add_argument(
        '--optim',
        default='sgd',
        help='what update to use? rmsprop|sgd|sgdmom|adagrad|adam')
    parser.add_argument('--learning_rate',
                        default=0.1,
                        type=float,
                        help='learning rate')
    parser.add_argument('--alpha',
                        default=0.95,
                        type=float,
                        help='alpha for adagrad/rmsprop/momentum/adam')
    parser.add_argument('--beta',
                        default=0.999,
                        type=float,
                        help='beta used for adam')
    parser.add_argument(
        '--epsilon',
        default=1e-8,
        help='epsilon that goes into denominator for smoothing')
    parser.add_argument('--loss_alpha_r',
                        default=2,
                        type=int,
                        help='The weight for regression loss')
    parser.add_argument('--patience_epoch',
                        default=1,
                        type=int,
                        help='Epoch to wait to determine a pateau')
    parser.add_argument('--reduce_factor',
                        default=0.5,
                        type=float,
                        help='Factor of learning rate reduction')
    parser.add_argument('--grad_norm',
                        default=1,
                        type=float,
                        help='Gradient clipping norm')

    # Data parallel
    parser.add_argument('--dist_url',
                        default='file:///home/luozhou/nonexistent_file',
                        type=str,
                        help='url used to set up distributed training')
    parser.add_argument('--dist_backend',
                        default='gloo',
                        type=str,
                        help='distributed backend')
    parser.add_argument('--world_size',
                        default=1,
                        type=int,
                        help='number of distributed processes')
    ################### add ################
    parser.add_argument('--rank',
                        default=0,
                        type=int,
                        help='rank of distributefd process')
    #########################################

    # Evaluation/Checkpointing
    parser.add_argument('--save_checkpoint_every',
                        default=1,
                        type=int,
                        help='how many epochs to save a model checkpoint?')
    parser.add_argument(
        '--checkpoint_path',
        default='./checkpoint',
        help='folder to save checkpoints into (empty = this folder)')
    parser.add_argument(
        '--losses_log_every',
        default=1,
        type=int,
        help=
        'How often do we snapshot losses, for inclusion in the progress dump? (0 = disable)'
    )
    parser.add_argument('--seed',
                        default=213,
                        type=int,
                        help='random number generator seed to use')
    parser.add_argument('--cuda',
                        dest='cuda',
                        action='store_true',
                        help='use gpu')
    parser.add_argument('--enable_visdom',
                        action='store_true',
                        dest='enable_visdom')

    parser.set_defaults(cuda=False,
                        save_train_samplelist=False,
                        load_train_samplelist=False,
                        save_valid_samplelist=False,
                        load_valid_samplelist=False,
                        gated_mask=False,
                        enable_visdom=False)

    args = parser.parse_args()

    with open(args.cfgs_file, 'r') as handle:
        options_yaml = yaml.load(handle)
    update_values(options_yaml, vars(args))
    print(args)

    # arguments inspection
    assert (args.slide_window_size >= args.slide_window_stride)
    assert (args.sampling_sec == 0.5
            )  # attention! sampling_sec is hard coded as 0.5

    torch.manual_seed(args.seed)
    np.random.seed(args.seed)
    random.seed(args.seed)

    if args.cuda:
        torch.cuda.manual_seed_all(args.seed)

    return args
Esempio n. 4
0
def parse_opt_rnn():
    parser = argparse.ArgumentParser()

    # Data input settings
    parser.add_argument('--cfgs_file',
                        default='cfgs/yc2.yml',
                        type=str,
                        help='dataset specific settings. anet | yc2')
    parser.add_argument('--dataset',
                        default='yc2',
                        type=str,
                        help='which dataset to use. two options: anet | yc2')
    parser.add_argument('--dataset_file', default='', type=str)
    parser.add_argument('--feature_root',
                        default='',
                        type=str,
                        help='the feature root')
    parser.add_argument('--dur_file', default='', type=str)
    parser.add_argument('--bmn_model',
                        default='checkpoint/best_model.t7',
                        help='path to a pretrained bmn model')
    parser.add_argument('--ptr_model',
                        default='checkpoint_rnn/best_model.t7',
                        help='path to a pretrained bmn model')
    parser.add_argument('--max_sentence_len', default=20, type=int)
    parser.add_argument('--num_workers', default=3, type=int)

    parser.add_argument('--train_data_folder',
                        default=['training'],
                        type=str,
                        nargs='+',
                        help='training data folder')
    parser.add_argument('--val_data_folder',
                        default=['validation'],
                        help='validation data folder')
    parser.add_argument('--test_data_folder',
                        default=['validation'],
                        help='testing data folder')

    # Model settings: General
    parser.add_argument('--temporal_scale',
                        default=200,
                        type=int,
                        help='length of observation window')
    parser.add_argument('--max_duration',
                        default=100,
                        type=int,
                        help='max proposal duration')
    parser.add_argument('--prop_boundary_ratio', type=int, default=0.5)
    parser.add_argument('--prop_num', type=int, default=100)
    parser.add_argument('--max_seq_len', type=int, default=20)
    parser.add_argument('--num_sample', type=int, default=32)
    parser.add_argument('--num_sample_perbin', type=int, default=3)
    parser.add_argument('--feat_dim', type=int, default=3072)

    # Model settings: rnn_ptr
    parser.add_argument('--hidden_size', type=int, default=256)
    parser.add_argument('--prop_feat',
                        type=list,
                        default=['score', 'loc', 'vis'])

    # Model settings: Proposal and mask
    parser.add_argument('--soft_nms_alpha', default=0.4, type=float)
    parser.add_argument('--soft_nms_low_thres', default=0.5, type=float)
    parser.add_argument('--soft_nms_high_thres', default=0.9, type=float)

    # Optimization: General
    parser.add_argument('--batch_size', default=8, type=int, help='batch size')
    parser.add_argument('--cuda',
                        dest='cuda',
                        action='store_true',
                        help='use gpu')

    # Optimization
    parser.add_argument('--max_epochs',
                        default=5,
                        type=int,
                        help='max number of epochs to run for')
    parser.add_argument(
        '--optim',
        default='adam',
        help='what update to use? rmsprop|sgd|sgdmom|adagrad|adam')
    parser.add_argument('--learning_rate',
                        default=1e-3,
                        type=float,
                        help='learning rate')
    parser.add_argument('--alpha',
                        default=0.95,
                        type=float,
                        help='alpha for adagrad/rmsprop/momentum/adam')
    parser.add_argument('--beta',
                        default=0.999,
                        type=float,
                        help='beta used for adam')
    parser.add_argument(
        '--epsilon',
        default=1e-8,
        help='epsilon that goes into denominator for smoothing')
    parser.add_argument('--patience_epoch',
                        default=1,
                        type=int,
                        help='Epoch to wait to determine a pateau')
    parser.add_argument('--reduce_factor',
                        default=0.5,
                        type=float,
                        help='Factor of learning rate reduction')
    parser.add_argument('--grad_norm',
                        default=1,
                        type=float,
                        help='Gradient clipping norm')

    # Evaluation/Checkpointing
    parser.add_argument('--save_checkpoint_every',
                        default=1,
                        type=int,
                        help='how many epochs to save a model checkpoint?')
    parser.add_argument(
        '--checkpoint_path',
        default='./checkpoint_rnn',
        help='folder to save checkpoints into (empty = this folder)')
    parser.add_argument(
        '--losses_log_every',
        default=1,
        type=int,
        help=
        'How often do we snapshot losses, for inclusion in the progress dump? (0 = disable)'
    )
    parser.add_argument('--seed',
                        default=213,
                        type=int,
                        help='random number generator seed to use')
    parser.set_defaults(cuda=True)

    parser.set_defaults(cuda=True)
    args = parser.parse_args()

    import os
    path = os.path.dirname(__file__)
    with open(os.path.join(path, args.cfgs_file), 'r') as handle:
        options_yaml = yaml.load(handle)
    update_values(options_yaml, vars(args))

    return args