# every utils that don't use torch import hashlib import json import logging import multiprocessing as mp import os def get_hash(s): m = hashlib.md5() m.update(s.encode('utf8')) return m.hexdigest() def read_config(path): with open(path, 'r') as fin: return json.load(fin) def init_logger(app_name): os.makedirs('logs', exist_ok=True) logger = mp.get_logger() logger.setLevel(logging.INFO) handler = logging.FileHandler('logs/%s.log' % app_name, encoding="utf8") handler.setFormatter(logging.Formatter('[%(asctime)s] [%(processName)s/%(levelname)s] %(message)s')) logger.addHandler(handler)