create_input_config.py 1.31 KB
import os
import json

root = '/root/Documents/GroupLung/Datasets/cls_data/job_data_cls_train/input/input_config.json'
base_path = '/root/Documents/GroupLung/LungClassification3D/NoduleDensityClassifier/config.json'
model_path = '/root/Documents/GroupLung/LungClassification3D/NoduleDensityClassifier/model_parameters.json'

root_json = json.load(open(root, 'r'))
base_json = json.load(open(base_path, 'r'))
model_json = json.load(open(model_path, 'r'))

# 去掉root中的部分无用的参数
use_list = ['train', 'test', 'pred', 'use_amp', 'usr_ckpt', 'check_cancleflag', 'in_channels', 'out_channels', 'split', 'pretrain_msg', 'preprocess_workers', 'working_label', 'crop_size', 'diameter_th', 'annotation_label']
for key in list(root_json.keys()):
    if key not in use_list:
        root_json.pop(key, None)

# 增加新的参数
for key, value in base_json.items():
    if key not in root_json.keys():
        root_json[key] = value
    else:
        print('No.1, already have this key: {}'.format(key))

for key, value in model_json.items():
    if key not in root_json.keys():
        root_json[key] = value
    else:
        print('No.2, already have this key: {}'.format(key))

with open('/root/Documents/GroupLung/Datasets/cls_data/job_data_cls_train/input/new_input_config.json', 'w+') as fp:
    json.dump(root_json, fp, indent=4)