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

fix detect use io.open (#3725)

use io.open instead open in rcnn/yolo/ssd
上级 5d35f15a
......@@ -16,6 +16,7 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import io
import time
import numpy as np
from eval_helper import *
......@@ -116,8 +117,8 @@ def eval():
segms_res) > 0, "The number of valid mask detected is zero.\n \
Please use reasonable model and check input data."
with open("detection_bbox_result.json", 'w') as outfile:
json.dump(dts_res, outfile)
with io.open("detection_bbox_result.json", 'w') as outfile:
outfile.write(unicode(json.dumps(dts_res)))
print("start evaluate bbox using coco api")
cocoDt = cocoGt.loadRes("detection_bbox_result.json")
cocoEval = COCOeval(cocoGt, cocoDt, 'bbox')
......@@ -126,8 +127,8 @@ def eval():
cocoEval.summarize()
if cfg.MASK_ON:
with open("detection_segms_result.json", 'w') as outfile:
json.dump(segms_res, outfile)
with io.open("detection_segms_result.json", 'w') as outfile:
outfile.write(unicode(json.dumps(segms_res)))
print("start evaluate mask using coco api")
cocoDt = cocoGt.loadRes("detection_segms_result.json")
cocoEval = COCOeval(cocoGt, cocoDt, 'segm')
......
......@@ -15,6 +15,7 @@
import os
import os.path as osp
import sys
import io
import re
import random
import tarfile
......@@ -63,7 +64,7 @@ def walk_dir(devkit_dir, year):
else:
continue
fpath = osp.join(filelist_dir, fname)
for line in open(fpath):
for line in io.open(fpath):
name_prefix = line.strip().split()[0]
if name_prefix in added:
continue
......@@ -85,11 +86,11 @@ def prepare_filelist(devkit_dir, years, output_dir):
trainval_list.extend(trainval)
test_list.extend(test)
random.shuffle(trainval_list)
with open(osp.join(output_dir, 'trainval.txt'), 'w') as ftrainval:
with io.open(osp.join(output_dir, 'trainval.txt'), 'w') as ftrainval:
for item in trainval_list:
ftrainval.write(item[0] + ' ' + item[1] + '\n')
with open(osp.join(output_dir, 'test.txt'), 'w') as ftest:
with io.open(osp.join(output_dir, 'test.txt'), 'w') as ftest:
for item in test_list:
ftest.write(item[0] + ' ' + item[1] + '\n')
......
......@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import io
import time
import numpy as np
import argparse
......@@ -128,8 +129,8 @@ def eval(args, data_args, test_list, batch_size, model_dir=None):
print("Batch {0}".format(batch_id))
dts_res += get_dt_res(nmsed_out_v, data)
with open("detection_result.json", 'w') as outfile:
json.dump(dts_res, outfile)
with io.open("detection_result.json", 'w') as outfile:
outfile.write(unicode(json.dumps(dts_res)))
print("start evaluate using coco api")
cocoGt = COCO(os.path.join(data_args.data_dir, test_list))
cocoDt = cocoGt.loadRes("detection_result.json")
......
......@@ -16,6 +16,7 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import io
import time
import json
import numpy as np
......@@ -113,8 +114,8 @@ def eval():
print("batch id: {}, time: {}".format(batch_id, end_time - start_time))
total_time += end_time - start_time
with open("yolov3_result.json", 'w') as outfile:
json.dump(dts_res, outfile)
with io.open("yolov3_result.json", 'w') as outfile:
outfile.write(unicode(json.dumps(dts_res)))
print("start evaluate detection result with coco api")
coco = COCO(os.path.join(cfg.data_dir, test_list))
cocoDt = coco.loadRes("yolov3_result.json")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册