PytorchCNN project construction 5--- mmcv_config

PytorchCNN project construction 5--- mmcv_config

The overall code can be viewed on my github


MMCV brief description

mmcv is a basic library function of python, including:

  • File IO (provides two general interfaces for loading and dumping different forms of files)
  • Image (implemented in opencv, you need to ensure that OpenCV has been installed during use)
  • Video (including video reading and conversion interfaces, some methods of video editing, and optical flow reading/writing/bending)
  • Here I mainly use the Config module in Utils (this module supports loading configuration from a variety of file formats, and provides dict-like api to get and set values), so I will introduce this part in detail. If you have other requirements, you can download it from Refer to the official website documents in the literature for learning.

The Config class is used to process config and config files. It supports loading configuration from multiple file formats (including python, json and yaml). It provides dict-like api to get and set values.


Suppose we put the corresponding parameters in the config.py file, and then call this file to call the parameters

from mmcv import Config
cfg = Config.fromfile('./config/config.py')
cfg
Config (path: ./config/config.py): {'a': 1, 'b': {'b1': [0, 1, 2], 'b2': None}, 'c': (1, 2), 'd': 'string'}
cfg.a
1
cfg.b
{'b1': [0, 1, 2], 'b2': None}
cfg.d
'string'

Description:

The usage of this is relatively simple. It is automatically saved in the form of a dictionary. We can also call each parameter separately. The advantage of this is that all the parameters in the project can be written to this file for easy modification.


Finally, paste the parameter code you set

PARA = dict(
    train=dict(
        epochs = 100,
        batch_size = 64,
        lr = 0.001,
        momentum=0.9,
        wd = 5e-4,
        num_workers = 2,
        divice_ids = [1],
        gpu_id = 0,
        num_classes=10,
    ),
    test=dict(
        batch_size=100
    ),
    cifar10_paths = dict( #这些路径函数需要替换成自己的,最好写成相对路径,而不是绝对路径
        validation_rate = 0.05,

        root = '../../DATASET/cifar10/',

        original_trainset_path = '../../../DATASET/cifar10/cifar-10-python/',#train_batch_path
        original_testset_path = '../../../DATASET/cifar10/cifar-10-python/',

        after_trainset_path = '../../../DATASET/cifar10/trainset/',
        after_testset_path = '../../../DATASET/cifar10/testset/',
        after_validset_path = '../../../DATASET/cifar10/validset/',

        train_data_txt = '../../../DATASET/cifar10/train.txt',
        test_data_txt = '../../../DATASET/cifar10/test.txt',
        valid_data_txt = '../../../DATASET/cifar10/valid.txt',
    ),
    utils_paths = dict(
        checkpoint_path = './cache/checkpoint/',
        log_path = './cache/log/',
        visual_path = './cache/visual/',
        params_path = './cache/params/',
    ),
)

references

1. mmcv official documentation

2. Common functions and function descriptions of mmcv

Finally, I would like to thank my brother, who taught me to build the entire project, and the little friends who studied together in the laboratory~ I hope they will succeed in everything, and they will have a great future!

Guess you like

Origin blog.csdn.net/qq_44783177/article/details/113774870