提交 5dcb0be6 编写于 作者: L liuhui29

使用logger打印日志

上级 c12c8276
...@@ -27,6 +27,11 @@ import xml.etree.ElementTree as ET ...@@ -27,6 +27,11 @@ import xml.etree.ElementTree as ET
from tqdm import tqdm from tqdm import tqdm
import re import re
import logging
FORMAT = '%(asctime)s-%(levelname)s: %(message)s'
logging.basicConfig(level=logging.INFO, format=FORMAT)
logger = logging.getLogger(__name__)
def main(): def main():
""" """
...@@ -49,13 +54,16 @@ def main(): ...@@ -49,13 +54,16 @@ def main():
default='output/label_list.txt') default='output/label_list.txt')
args = parser.parse_args() args = parser.parse_args()
args.dataset_type = args.dataset_type.lower()
assert args.dataset_type in ['coco', 'voc']
if args.dataset_type == 'coco' or args.dataset_type == 'COCO': if args.dataset_type == 'coco':
assert args.dataset_type and args.json_path assert args.dataset_type and args.json_path
try: try:
assert os.path.exists(args.json_path) assert os.path.exists(args.json_path)
except AssertionError as e: except AssertionError as e:
print('The json file: {} does not exist!'.format(args.json_path)) logger.error('The json file: {} does not exist!'.format(
args.json_path))
os._exit(0) os._exit(0)
anno = json.load(open(args.json_path)) anno = json.load(open(args.json_path))
...@@ -66,12 +74,12 @@ def main(): ...@@ -66,12 +74,12 @@ def main():
f.write(cat + '\n') f.write(cat + '\n')
print('lable_list file: {} create done!'.format(args.outfile_path)) print('lable_list file: {} create done!'.format(args.outfile_path))
if args.dataset_type == 'voc' or args.dataset_type == 'VOC': if args.dataset_type == 'voc':
assert args.dataset_type and args.xml_dir assert args.dataset_type and args.xml_dir
try: try:
assert os.path.exists(args.xml_dir) assert os.path.exists(args.xml_dir)
except AssertionError as e: except AssertionError as e:
print('The xml_dir: {} does not exist!'.format(args.xml_dir)) logger.error('The xml_dir: {} does not exist!'.format(args.xml_dir))
os._exit(0) os._exit(0)
categories_list = set() categories_list = set()
...@@ -89,7 +97,8 @@ def main(): ...@@ -89,7 +97,8 @@ def main():
with open(args.outfile_path, 'w') as f: with open(args.outfile_path, 'w') as f:
for cat in categories_list: for cat in categories_list:
f.write(cat + '\n') f.write(cat + '\n')
print('lable_list file: {} create done!'.format(args.outfile_path)) logger.info('lable_list file: {} create done!'.format(
args.outfile_path))
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册