MCPcopy
hub / github.com/alibaba/EasyCV / main

Function main

tools/quantize.py:108–253  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

106
107
108def main():
109 args = parse_args()
110
111 if args.model_type is not None and args.config is None:
112 assert args.model_type in CONFIG_TEMPLATE_ZOO, 'model_type must be in [%s]' % (
113 ', '.join(CONFIG_TEMPLATE_ZOO.keys()))
114 print('model_type=%s, config file will be replaced by %s' %
115 (args.model_type, CONFIG_TEMPLATE_ZOO[args.model_type]))
116 args.config = CONFIG_TEMPLATE_ZOO[args.model_type]
117
118 if args.config.startswith('http'):
119
120 r = requests.get(args.config)
121 # download config in current dir
122 tpath = args.config.split('/')[-1]
123 while not osp.exists(tpath):
124 try:
125 with open(tpath, 'wb') as code:
126 code.write(r.content)
127 except:
128 pass
129
130 args.config = tpath
131
132 cfg = mmcv_config_fromfile(args.config)
133
134 if args.user_config_params is not None:
135 assert args.model_type is not None, 'model_type must be setted'
136 # rebuild config by user config params
137 cfg = rebuild_config(cfg, args.user_config_params)
138
139 # check oss_config and init oss io
140 if cfg.get('oss_io_config', None) is not None:
141 io.access_oss(**cfg.oss_io_config)
142
143 # set cudnn_benchmark
144 if cfg.get('cudnn_benchmark', False):
145 torch.backends.cudnn.benchmark = True
146
147 # update configs according to CLI args
148 if args.work_dir is not None:
149 cfg.work_dir = args.work_dir
150
151 # if `work_dir` is oss path, redirect `work_dir` to local path, add `oss_work_dir` point to oss path,
152 # and use osssync hook to upload log and ckpt in work_dir to oss_work_dir
153 if cfg.work_dir.startswith('oss://'):
154 cfg.oss_work_dir = cfg.work_dir
155 cfg.work_dir = osp.join('work_dirs',
156 cfg.work_dir.replace('oss://', ''))
157 else:
158 cfg.oss_work_dir = None
159
160 # create work_dir
161 if not io.exists(cfg.work_dir):
162 io.makedirs(cfg.work_dir)
163
164 timestamp = time.strftime('%Y%m%d_%H%M%S', time.localtime())
165 log_file = osp.join(cfg.work_dir, '{}.log'.format(timestamp))

Callers 1

quantize.pyFile · 0.70

Calls 15

mmcv_config_fromfileFunction · 0.90
rebuild_configFunction · 0.90
get_root_loggerFunction · 0.90
build_modelFunction · 0.90
load_checkpointFunction · 0.90
get_model_infoFunction · 0.90
quantize_config_checkFunction · 0.90
build_datasetFunction · 0.90
build_dataloaderFunction · 0.90
calibFunction · 0.90
quantize_evalFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected