解决训练文本检测模型DBNet时遇到的一个BUG,供参考。
问题:
[2023/06/13 08:00:31] ppocr ERROR: When parsing line COCO_Text/COCO_train2014_000000391537.jpg [{"transcription": "PUBLIC", "points": [[288, 131], [288, 142], [261, 147], [261, 137]]}, {"transcription": "TOILETS", "points": [[290, 130], [290, 140], [323, 135], [322, 124]]}, {"transcription": "WC", "points": [[288, 163], [287, 172], [301, 171], [301, 161]]}, {"transcription": "WESTMINSTER", "points": [[316, 221], [317, 231], [263, 239], [263, 230]]}, {"transcription": "HOUSES", "points": [[266, 205], [265, 216], [298, 220], [298, 210]]}, {"transcription": "PARK", "points": [[182, 351], [181, 364], [209, 366], [209, 353]]}, {"transcription": "JAMES"S", "points": [[134, 348], [134, 359], [177, 363], [177, 350]]}, {"transcription": "ST.", "points": [[117, 346], [116, 357], [130, 359], [131, 347]]}, {"transcription": "PALACE", "points": [[182, 287], [183, 299], [221, 303], [220, 291]]}, {"transcription": "BUCKINGHAM", "points": [[106, 279], [105, 290], [176, 298], [176, 286]]}, {"transcription": "WESTMINSTER", "points": [[283, 333], [286, 343], [354, 352], [353, 342]]}, {"transcription": "WHITEHALL", "points": [[291, 271], [293, 281], [347, 289], [345, 279]]}, {"transcription": "ABBEY", "points": [[322, 219], [321, 230], [344, 227], [347, 214]]}]
, error happened with msg: Traceback (most recent call last):
File "/hy_ppocr/ppocr/data/simple_dataset.py", line 137, in __getitem__
outs = transform(data, self.ops)
File "/hy_ppocr/ppocr/data/imaug/__init__.py", line 56, in transform
data = op(data)
File "/hy_ppocr/ppocr/data/imaug/label_ops.py", line 51, in __call__
label = json.loads(label)
File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 561 (char 560)
问题描述:在使用json包里的load函数解析DBNet训练集中的一行数据时报错
出现原因:百度PaddleOCR框架中,dataloader解析数据时是以双引号作为分割符,若文字内容中存在双引号,则会出现上述分隔错误
解决问题:遍历所有训练数据,将文字内容(即transcription)中的双引号改成单引号或者其他符合字典要求的符号,即可解决