未验证 提交 01435d00 编写于 作者: K Kaipeng Deng 提交者: GitHub

fix unicode python3 compatable (#3759)

上级 357c46ee
...@@ -17,6 +17,7 @@ from __future__ import division ...@@ -17,6 +17,7 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
import os import os
import io import io
import six
import time import time
import numpy as np import numpy as np
from eval_helper import * from eval_helper import *
...@@ -118,7 +119,8 @@ def eval(): ...@@ -118,7 +119,8 @@ def eval():
Please use reasonable model and check input data." Please use reasonable model and check input data."
with io.open("detection_bbox_result.json", 'w') as outfile: with io.open("detection_bbox_result.json", 'w') as outfile:
outfile.write(unicode(json.dumps(dts_res))) encode_func = unicode if six.PY2 else str
outfile.write(encode_func(json.dumps(dts_res)))
print("start evaluate bbox using coco api") print("start evaluate bbox using coco api")
cocoDt = cocoGt.loadRes("detection_bbox_result.json") cocoDt = cocoGt.loadRes("detection_bbox_result.json")
cocoEval = COCOeval(cocoGt, cocoDt, 'bbox') cocoEval = COCOeval(cocoGt, cocoDt, 'bbox')
...@@ -128,7 +130,8 @@ def eval(): ...@@ -128,7 +130,8 @@ def eval():
if cfg.MASK_ON: if cfg.MASK_ON:
with io.open("detection_segms_result.json", 'w') as outfile: with io.open("detection_segms_result.json", 'w') as outfile:
outfile.write(unicode(json.dumps(segms_res))) encode_func = unicode if six.PY2 else str
outfile.write(encode_func(json.dumps(segms_res)))
print("start evaluate mask using coco api") print("start evaluate mask using coco api")
cocoDt = cocoGt.loadRes("detection_segms_result.json") cocoDt = cocoGt.loadRes("detection_segms_result.json")
cocoEval = COCOeval(cocoGt, cocoDt, 'segm') cocoEval = COCOeval(cocoGt, cocoDt, 'segm')
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import os import os
import io import io
import six
import time import time
import numpy as np import numpy as np
import argparse import argparse
...@@ -130,7 +131,8 @@ def eval(args, data_args, test_list, batch_size, model_dir=None): ...@@ -130,7 +131,8 @@ def eval(args, data_args, test_list, batch_size, model_dir=None):
dts_res += get_dt_res(nmsed_out_v, data) dts_res += get_dt_res(nmsed_out_v, data)
with io.open("detection_result.json", 'w') as outfile: with io.open("detection_result.json", 'w') as outfile:
outfile.write(unicode(json.dumps(dts_res))) encode_func = unicode if six.PY2 else str
outfile.write(encode_func(json.dumps(dts_res)))
print("start evaluate using coco api") print("start evaluate using coco api")
cocoGt = COCO(os.path.join(data_args.data_dir, test_list)) cocoGt = COCO(os.path.join(data_args.data_dir, test_list))
cocoDt = cocoGt.loadRes("detection_result.json") cocoDt = cocoGt.loadRes("detection_result.json")
......
...@@ -17,6 +17,7 @@ from __future__ import division ...@@ -17,6 +17,7 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
import os import os
import io import io
import six
import time import time
import json import json
import numpy as np import numpy as np
...@@ -115,7 +116,8 @@ def eval(): ...@@ -115,7 +116,8 @@ def eval():
total_time += end_time - start_time total_time += end_time - start_time
with io.open("yolov3_result.json", 'w') as outfile: with io.open("yolov3_result.json", 'w') as outfile:
outfile.write(unicode(json.dumps(dts_res))) encode_func = unicode if six.PY2 else str
outfile.write(encode_func(json.dumps(dts_res)))
print("start evaluate detection result with coco api") print("start evaluate detection result with coco api")
coco = COCO(os.path.join(cfg.data_dir, test_list)) coco = COCO(os.path.join(cfg.data_dir, test_list))
cocoDt = coco.loadRes("yolov3_result.json") cocoDt = coco.loadRes("yolov3_result.json")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册