config 设置的两种方式
1. easydict 模块来设置config
config.py (双下划线会重写属性名称,会在该属性的前面加上_class__attribute,直接调用class.__attribute 会报错,以下代码的双下划线应该也是为了避免命名冲突吧!)
from easydict import EasyDict as edict __C = edict() # Consumers can get config by: from config import cfg cfg = __C # YOLO options __C.YOLO = edict() __C.YOLO.CLASSES = "./data/classes/coco.names" __C.YOLO.ANCHORS = "./data/anchors/basline_anchors.txt" __C.YOLO.MOVING_AVE_DECAY = 0.9995 __C.YOLO.STRIDES = [8, 16, 32] __C.YOLO.ANCHOR_PER_SCALE = 3 __C.YOLO.IOU_LOSS_THRESH = 0.5 __C.YOLO.UPSAMPLE_METHOD = "resize" __C.YOLO.ORIGINAL_WEIGHT = "./checkpoint/yolov3_coco.ckpt" __C.YOLO.DEMO_WEIGHT = "./checkpoint/yolov3_coco_demo.ckpt" # Train options __C.TRAIN = edict() __C.TRAIN.ANNOT_PATH = "./data/dataset/voc_train.txt" __C.TRAIN.BATCH_SIZE = 6 __C.TRAIN.INPUT_SIZE = [320, 352, 384, 416, 448, 480, 512, 544, 576, 608] __C.TRAIN.DATA_AUG = True __C.TRAIN.LEARN_RATE_INIT = 1e-4 __C.TRAIN.LEARN_RATE_END = 1e-6 __C.TRAIN.WARMUP_EPOCHS = 2 __C.TRAIN.FISRT_STAGE_EPOCHS = 20 __C.TRAIN.SECOND_STAGE_EPOCHS = 30 __C.TRAIN.INITIAL_WEIGHT = "./checkpoint/yolov3_coco_demo.ckpt" # TEST options __C.TEST = edict() __C.TEST.ANNOT_PATH = "./data/dataset/voc_test.txt" __C.TEST.BATCH_SIZE = 2 __C.TEST.INPUT_SIZE = 544 __C.TEST.DATA_AUG = False __C.TEST.WRITE_IMAGE = True __C.TEST.WRITE_IMAGE_PATH = "./data/detection/" __C.TEST.WRITE_IMAGE_SHOW_LABEL = True __C.TEST.WEIGHT_FILE = "./checkpoint/yolov3_test_loss=9.2099.ckpt-5" __C.TEST.SHOW_LABEL = True __C.TEST.SCORE_THRESHOLD = 0.3 __C.TEST.IOU_THRESHOLD = 0.45
train.py
from config import cfg class YoloTrain(object): def __init__(self): self.anchor_per_scale = cfg.YOLO.ANCHOR_PER_SCALE self.classes = utils.read_class_names(cfg.YOLO.CLASSES) self.num_classes = len(self.classes) self.learn_rate_init = cfg.TRAIN.LEARN_RATE_INIT self.learn_rate_end = cfg.TRAIN.LEARN_RATE_END self.first_stage_epochs = cfg.TRAIN.FISRT_STAGE_EPOCHS self.second_stage_epochs = cfg.TRAIN.SECOND_STAGE_EPOCHS self.warmup_periods = cfg.TRAIN.WARMUP_EPOCHS self.initial_weight = cfg.TRAIN.INITIAL_WEIGHT self.time = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) self.moving_ave_decay = cfg.YOLO.MOVING_AVE_DECAY
2. 通过configobj 来设置config
config
[param] # coco dataset json file datasetFile= "D:\\coco\\person_keypoints_val2014.json" new_datasetFile="D:\\coco\\new_person_keypoints_val2014.json" new_val2014="D:\\coco\\new_val2014\\" val2014="D:\\coco\\val2014\\" image_height=552 blank=2 crop_ratio = 1 bbox_ratio = 1 num_keypoints=4 area=32*32
config_reader.py
from configobj import ConfigObj def config_reader(): config = ConfigObj('config') param = config['param'] datasetFile = param['datasetFile'] new_datasetFile = param['new_datasetFile'] area=param['area'] num_keypoints=param['num_keypoints'] new_val2014 = param['new_val2014'] val2014=param['val2014'] image_height=param['image_height'] blank=param['blank'] return param if __name__ == "__main__": config_reader()