예제 #1
0
                        type=str,
                        help="Dataset name",
                        choices=dbac_data.DB_NAMES)
    parser.add_argument('db_path', type=str, help="Dataset directory path")
    parser.add_argument('feat_type',
                        type=str,
                        help='Feature type',
                        choices=dbac_feature_ext.FEAT_TYPE)
    parser.add_argument('output_path',
                        type=str,
                        help="Path to output feature cache dictionary .npz")
    parser.add_argument(
        '-kwargs',
        type=str,
        default=None,
        help="Kwargs for the feature extractor k1=v1; k2=v2; ...")
    parser.add_argument('-gpu_str',
                        default='0',
                        type=str,
                        help='CUDA_VISIBLE_DEVICES')
    args = parser.parse_args()

    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_str
    dbac_util.init_logging('_'.join([
        os.path.splitext(args.output_path)[0],
        '{}.log'.format(datetime.now().strftime("%Y%m%d-%H%M%S"))
    ]))
    logger.info(args)
    _extract_features(args.db_name, args.db_path, args.feat_type,
                      args.output_path, args.kwargs)
예제 #2
0
        type=str,
        help='Path to split file to compute split distributions.')
    parser_plot.add_argument(
        '-comb_file',
        type=str,
        help='Path to compositions file to compute distributions.')
    parser_plot.add_argument('-plot',
                             default=False,
                             action='store_true',
                             help='Generate plot.')
    args = parser.parse_args()

    if args.cmd_name == 'split':
        # set up log system
        dbac_util.init_logging('_'.join([
            os.path.splitext(args.output_path)[0],
            '{}.split.log'.format(datetime.now().strftime("%Y%m%d-%H%M%S"))
        ]))
        logger.info(args)
        # Compute dataset splits
        logger.info("Computing split for db {} ...".format(args.db_name))
        time.sleep(10)
        _compute_splits(args.db_name, args.db_path, args.ops, args.output_path,
                        args.min_per_prim, args.min_per_exp, args.num_exps,
                        args.min_pos_exp_test, args.nogroup)
    elif args.cmd_name == 'comb':
        # set up log system
        dbac_util.init_logging('_'.join([
            os.path.splitext(args.split_file)[0],
            '{}.comb.log'.format(datetime.now().strftime("%Y%m%d-%H%M%S"))
        ]))
        logger.info(args)
    result_file = os.path.join(output_dir, 'results.npy')
    np.save(result_file, report_dic)
    logger.info("Results file saved to {}.".format(result_file))


if __name__ == '__main__':
    import argparse
    from datetime import datetime
    import os

    parser = argparse.ArgumentParser(description="Script for test Neural Algebra of Classifiers models.", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('db_name', type=str, choices=dbac_data.DB_NAMES, help='Name of the Dataset.')
    parser.add_argument('db_dir', type=str, help='Path to the dataset main directory.')
    parser.add_argument('split_file', type=str, help='Path to the split json file.')
    parser.add_argument('-comb_file', default=None, type=str, help='Path to the compositions json file.')
    parser.add_argument('primitives_file', type=str, help='Path to the primitives collection file.')
    parser.add_argument('model_name', type=str, choices=dbac_model._MODEL_NAMES, help='Model name.')
    parser.add_argument('output_dir', type=str, help='Output directory path.')
    parser.add_argument('-model_file', type=str, default=None, help='Path to model file.')
    parser.add_argument('-gpu_str', default='0', type=str, help='CUDA_VISIBLE_DEVICES')
    parser.add_argument('-kwargs', type=str, default=None, help="Kwargs for the feature extractor k1=v1; k2=v2; ...")
    args = parser.parse_args()
    print(args)

    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_str
    log_file = os.path.join(args.output_dir, "test_{}.log".format(datetime.now().strftime("%Y%m%d-%H%M%S")))
    dbac_util.init_logging(log_file)
    logger.info(args)
    _test(args.db_name, args.db_dir, args.split_file, args.comb_file, args.primitives_file, args.model_name, args.model_file,
          args.output_dir, args.kwargs)