diff --git a/ppstructure/vqa/eval_ser.py b/ppstructure/vqa/eval_ser.py index e56aa27c81862be16268694a6d3f0da43a103fef..e0612219504aecc01aa4ccae3e3a499ff3d0c639 100644 --- a/ppstructure/vqa/eval_ser.py +++ b/ppstructure/vqa/eval_ser.py @@ -128,12 +128,16 @@ def evaluate(args, "f1": f1_score(out_label_list, preds_list), } - with open(os.path.join(args.output_dir, "test_gt.txt"), "w") as fout: + with open( + os.path.join(args.output_dir, "test_gt.txt"), "w", + encoding='utf-8') as fout: for lbl in out_label_list: for l in lbl: fout.write(l + "\t") fout.write("\n") - with open(os.path.join(args.output_dir, "test_pred.txt"), "w") as fout: + with open( + os.path.join(args.output_dir, "test_pred.txt"), "w", + encoding='utf-8') as fout: for lbl in preds_list: for l in lbl: fout.write(l + "\t") diff --git a/ppstructure/vqa/helper/eval_with_label_end2end.py b/ppstructure/vqa/helper/eval_with_label_end2end.py index a983b080161fbc349cbb199cbe2cb9d5b4537b2f..3aa439acb269d74165543fac7e0042cfc213f08d 100644 --- a/ppstructure/vqa/helper/eval_with_label_end2end.py +++ b/ppstructure/vqa/helper/eval_with_label_end2end.py @@ -37,7 +37,7 @@ def parse_ser_results_fp(fp, fp_type="gt", ignore_background=True): assert fp_type in ["gt", "pred"] key = "label" if fp_type == "gt" else "pred" res_dict = dict() - with open(fp, "r") as fin: + with open(fp, "r", encoding='utf-8') as fin: lines = fin.readlines() for _, line in enumerate(lines): diff --git a/ppstructure/vqa/helper/trans_xfun_data.py b/ppstructure/vqa/helper/trans_xfun_data.py index b5ebd5dfbd8addda0701a7cfd2387133f7a8776b..25b3963d8362d28ea1df4c62d1491095b8c49253 100644 --- a/ppstructure/vqa/helper/trans_xfun_data.py +++ b/ppstructure/vqa/helper/trans_xfun_data.py @@ -16,13 +16,13 @@ import json def transfer_xfun_data(json_path=None, output_file=None): - with open(json_path, "r") as fin: + with open(json_path, "r", encoding='utf-8') as fin: lines = fin.readlines() json_info = json.loads(lines[0]) documents = json_info["documents"] label_info = {} - with open(output_file, "w") as fout: + with open(output_file, "w", encoding='utf-8') as fout: for idx, document in enumerate(documents): img_info = document["img"] document = document["document"] diff --git a/ppstructure/vqa/infer_re.py b/ppstructure/vqa/infer_re.py index ae2f52550294b072179c3bdba28c3572369e11a3..139ade9aae3a430eb7f9c9b5cb0ec30da465ca6e 100644 --- a/ppstructure/vqa/infer_re.py +++ b/ppstructure/vqa/infer_re.py @@ -92,7 +92,7 @@ def infer(args): def load_ocr(img_folder, json_path): import json d = [] - with open(json_path, "r") as fin: + with open(json_path, "r", encoding='utf-8') as fin: lines = fin.readlines() for line in lines: image_name, info_str = line.split("\t") diff --git a/ppstructure/vqa/infer_ser.py b/ppstructure/vqa/infer_ser.py index 4ad220094a26b330555fbe9122a46fb56e64fe1e..3c7ad03aa362971ab80aa63e92404942b136ca31 100644 --- a/ppstructure/vqa/infer_ser.py +++ b/ppstructure/vqa/infer_ser.py @@ -59,7 +59,8 @@ def pad_sentences(tokenizer, encoded_inputs["bbox"] = encoded_inputs["bbox"] + [[0, 0, 0, 0] ] * difference else: - assert False, f"padding_side of tokenizer just supports [\"right\"] but got {tokenizer.padding_side}" + assert False, "padding_side of tokenizer just supports [\"right\"] but got {}".format( + tokenizer.padding_side) else: if return_attention_mask: encoded_inputs["attention_mask"] = [1] * len(encoded_inputs[ @@ -224,7 +225,7 @@ def infer(args): # load ocr results json ocr_results = dict() - with open(args.ocr_json_path, "r") as fin: + with open(args.ocr_json_path, "r", encoding='utf-8') as fin: lines = fin.readlines() for line in lines: img_name, json_info = line.split("\t") @@ -234,7 +235,10 @@ def infer(args): infer_imgs = get_image_file_list(args.infer_imgs) # loop for infer - with open(os.path.join(args.output_dir, "infer_results.txt"), "w") as fout: + with open( + os.path.join(args.output_dir, "infer_results.txt"), + "w", + encoding='utf-8') as fout: for idx, img_path in enumerate(infer_imgs): print("process: [{}/{}]".format(idx, len(infer_imgs), img_path)) diff --git a/ppstructure/vqa/infer_ser_e2e.py b/ppstructure/vqa/infer_ser_e2e.py index 7cd9907dfbf1f964b0423364c87ae39de7a69932..a93a98ff6d0c2bf35a6bb85a16faacf82ebec1ce 100644 --- a/ppstructure/vqa/infer_ser_e2e.py +++ b/ppstructure/vqa/infer_ser_e2e.py @@ -113,7 +113,10 @@ if __name__ == "__main__": # loop for infer ser_engine = SerPredictor(args) - with open(os.path.join(args.output_dir, "infer_results.txt"), "w") as fout: + with open( + os.path.join(args.output_dir, "infer_results.txt"), + "w", + encoding='utf-8') as fout: for idx, img_path in enumerate(infer_imgs): print("process: [{}/{}], {}".format(idx, len(infer_imgs), img_path)) diff --git a/ppstructure/vqa/infer_ser_re_e2e.py b/ppstructure/vqa/infer_ser_re_e2e.py index a1d0f52eeecbc6c2ceba5964355008f638f371dd..23737406d1d2f31f79df9ddb1a9a6bcc5976aabe 100644 --- a/ppstructure/vqa/infer_ser_re_e2e.py +++ b/ppstructure/vqa/infer_ser_re_e2e.py @@ -112,7 +112,10 @@ if __name__ == "__main__": # loop for infer ser_re_engine = SerReSystem(args) - with open(os.path.join(args.output_dir, "infer_results.txt"), "w") as fout: + with open( + os.path.join(args.output_dir, "infer_results.txt"), + "w", + encoding='utf-8') as fout: for idx, img_path in enumerate(infer_imgs): print("process: [{}/{}], {}".format(idx, len(infer_imgs), img_path)) diff --git a/ppstructure/vqa/utils.py b/ppstructure/vqa/utils.py index 7e862e976f4aee91e81eb00284a20734ea93854e..44a6298080a456b514a719edf82ff1f1b60fd077 100644 --- a/ppstructure/vqa/utils.py +++ b/ppstructure/vqa/utils.py @@ -32,7 +32,7 @@ def set_seed(seed): def get_bio_label_maps(label_map_path): - with open(label_map_path, "r") as fin: + with open(label_map_path, "r", encoding='utf-8') as fin: lines = fin.readlines() lines = [line.strip() for line in lines] if "O" not in lines: diff --git a/ppstructure/vqa/xfun.py b/ppstructure/vqa/xfun.py index d62cdb5da5514280b62687d80d345ede9484ee90..eb9750dd205e3838fb30cbd5fe3ff419955d19f8 100644 --- a/ppstructure/vqa/xfun.py +++ b/ppstructure/vqa/xfun.py @@ -162,7 +162,7 @@ class XFUNDataset(Dataset): return encoded_inputs def read_all_lines(self, ): - with open(self.label_path, "r") as fin: + with open(self.label_path, "r", encoding='utf-8') as fin: lines = fin.readlines() return lines