Flags parser

实现类似gflage功能,能够定义flage,并通过main参数传入flage

待实现:cmdparser.h,解析main入参为kv形式;

parser.h
#pragma once
#include <map>
#include <iostream>
#include <string>
#include "cmdparser.h"

int RegisterKey(const std::string& key_str, int* var_ptr, int default_value);
std::string RegisterKey(const std::string& key_str, std::string* var_ptr, const std::string& default_value);

#define DEFINE_i32(key, default_value) int flage_##key = RegisterKey(#key, &flage_##key, default_value)
#define DEFINE_str(key, default_value) std::string flage_##key = RegisterKey(#key, &flage_##key, default_value)

void ParseCmdFlags(CLP cmd);
parser.cpp
#include "parser.h"

class Flags {
public:
    static Flags& Instance();
private:
    Flags() = default;
    ~Flags() = default;
public:
    std::map<std::string, int*> sflage_keys_i32;
    std::map<std::string, std::string*> sflage_keys_str;
};

Flags& Flags::Instance() {
    static Flags ins;
    return ins;
}

void ParseCmdFlags(CLP cmd) {
#define Cout(key, value) std::cout << key << ":" << value << std::endl;
    for (auto& item : Flags::Instance().sflage_keys_i32) {
        if (cmd.hasValue(item.first)) {
            *(item.second) = cmd.get<int>(item.first);
        }
        Cout(item.first, *item.second);
    }
    for (auto& item : Flags::Instance().sflage_keys_str) {
        if (cmd.hasValue(item.first)) {
            *(item.second) = cmd.get<std::string>(item.first);
        }
        Cout(item.first, *item.second);
    }
}

int RegisterKey(const std::string& key_str, int* var_ptr, int default_value) {
    Flags::Instance().sflage_keys_i32.emplace(key_str, var_ptr);
    return default_value;
}

std::string RegisterKey(const std::string& key_str, std::string* var_ptr,
                        const std::string& default_value) {
    Flags::Instance().sflage_keys_str.emplace(key_str, var_ptr);
    return default_value;
}
def get_parser(): parser = argparse.ArgumentParser(description='Face detection and classification for politicians in Japanese TV.') # Important configuration variables parser.add_argument('--dataset', type=str, default='mot17', help='Mode name for saving files.') parser.add_argument('--mode', default='train', type=str, help='train or test.') parser.add_argument('--detector', type=str, default='YOLOX', help='Detector to be used. FRCNN, SDP, Bresee, SGT, YOLOX, GT.') parser.add_argument('--reid', type=str, default=None, help='Reidentification model to be used. SBS, MGN.') parser.add_argument('--mod', type=str, default=None, help='Tracker name modifier to do testing of features.') # Paths parser.add_argument('--datapath', type=str, default='datasets/MOT17Det', help='Dataset path with frames inside.') parser.add_argument('--feat', type=str, default='feats', help='Features files path.') # Tracking-specific configuration variables parser.add_argument('--max_iou_th', type=float, default=0.15, help='Max value to multiply the distance of two close objects.') parser.add_argument('--w_tracklet', type=int, default=10, help='Window size per tracklet') parser.add_argument('--w_fuse', type=int, default=3, help='Window size per fusion in hierarchy') parser.add_argument('--max_prop', type=int, default=10000, help='Difficult the fusion when the frame difference is larger than this value.') parser.add_argument('--fps_ratio', type=int, default=1, help='Use lower fps dataset if lower than 1.') # Flags parser.add_argument('--save_feats', action='store_true', help='Save tracking + feature vectors as pkl file for analysis.') parser.add_argument('--iou', action='store_true', help='Add IoU distance to further improve the tracker.') parser.add_argument('--temp', action='store_true', help='Use temporal distance to further improve the tracker.') parser.add_argument('--spatial', action='store_true', help='Use spatial distance to further improve the tracker.') parser.add_argument('--motion', action='store_true', help='Add motion estimation to further improve the tracker.') parser.add_argument('--randorder', action='store_true', help='Random order of lifted frames for testing.') parser.add_argument('--noncont', action='store_true', help='Do not enforce continuous clustering. Allow all tracklets to cluster with whoever they want.') return parser
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值