Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update config to add argument:ser_class_dict_path #786

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tools/infer/text/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ def create_parser():
type=str,
help="directory containing the ser model checkpoint best.ckpt, or path to a specific checkpoint file.",
)
parser.add_argument(
"--ser_class_dict_path",
type=str,
default="./mindocr/utils/dict/class_list_xfun.txt",
help="path to class dictionary for structure recognition. ",
)
parser.add_argument(
"--kie_batch_mode",
type=str2bool,
Expand Down
2 changes: 1 addition & 1 deletion tools/infer/text/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, task="det", algo="DB", rec_char_dict_path=None, **kwargs):
else:
raise ValueError(f"No postprocess config defined for {algo}. Please check the algorithm name.")
elif task == "ser":
class_path = "mindocr/utils/dict/class_list_xfun.txt"
class_path = kwargs.get("ser_class_dict_path", "mindocr/utils/dict/class_list_xfun.txt")
postproc_cfg = dict(name="VQASerTokenLayoutLMPostProcess", class_path=class_path)
elif task == "layout":
if algo == "LAYOUTLMV3":
Expand Down
6 changes: 2 additions & 4 deletions tools/infer/text/predict_ser.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ def __init__(self, args):
)
self.model.set_train(False)

self.preprocess = Preprocessor(
task="ser",
)
self.preprocess = Preprocessor(task="ser", ser_class_dict_path=args.ser_class_dict_path)

self.postprocess = Postprocessor(task="ser")
self.postprocess = Postprocessor(task="ser", ser_class_dict_path=args.ser_class_dict_path)

self.batch_mode = args.kie_batch_mode
self.batch_num = args.kie_batch_num
Expand Down
3 changes: 2 additions & 1 deletion tools/infer/text/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,15 @@ def __init__(self, task="det", algo="DB", **kwargs):
{"ToCHWImage": None},
]
elif task == "ser":
class_path = kwargs.get("ser_class_dict_path", "mindocr/utils/dict/class_list_xfun.txt")
pipeline = [
{"DecodeImage": {"img_mode": "RGB", "infer_mode": True, "to_float32": False}},
{
"VQATokenLabelEncode": {
"contains_re": False,
"infer_mode": True,
"algorithm": "LayoutXLM",
"class_path": "mindocr/utils/dict/class_list_xfun.txt",
"class_path": class_path,
"order_method": "tb-yx",
}
},
Expand Down
Loading