PaddleOCR
PaddleOCR copied to clipboard
弯曲文字检测报错The requested array has an inhomogeneous shape after 1 dimensions
请提供下述完整信息以便快速定位问题/Please provide the following information to quickly locate the problem
- 系统环境/System Environment:ubuntu 20.04
- 版本号/Version:Paddle: 2.6 PaddleOCR:dygraph 问题相关组件/Related components:ppocr/postprocess/db_postprocess.py
- 运行指令/Command Code:python tools/train.py -c configs/det/det_r50_db++_icdar15.yml
- 完整报错/Complete Error Message:eval model:: 1%|▍ | 11/2000 [00:01<03:01, 10.95it/s]Traceback (most recent call last):
File "/home/suma/llm/train/PaddleOCR/tools/train.py", line 227, in
main(config, device, logger, vdl_writer, seed) File "/home/suma/llm/train/PaddleOCR/tools/train.py", line 198, in main program.train(config, train_dataloader, valid_dataloader, device, model, File "/home/suma/llm/train/PaddleOCR/tools/program.py", line 392, in train cur_metric = eval( File "/home/suma/llm/train/PaddleOCR/tools/program.py", line 570, in eval post_result = post_process_class(preds, batch_numpy[1]) File "/home/suma/llm/train/PaddleOCR/ppocr/postprocess/db_postprocess.py", line 237, in call boxes, scores = self.polygons_from_bitmap(pred[batch_index], File "/home/suma/llm/train/PaddleOCR/ppocr/postprocess/db_postprocess.py", line 84, in polygons_from_bitmap box = self.unclip(points, self.unclip_ratio) File "/home/suma/llm/train/PaddleOCR/ppocr/postprocess/db_postprocess.py", line 156, in unclip expanded = np.array(offset.Execute(distance)) ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
将det_r50_db++_icdar15.yml文件的
# 第57行
det_box_type: 'quad'
# 改为了
box_type: 'poly'
问题同 #11369
调试得到的如下数据
box = array([[ 434, 903],
[ 507, 942],
[ 698, 999],
[ 984, 1037],
[1206, 1019],
[1344, 981],
[ 971, 1012],
[ 688, 971],
[ 647, 948],
[ 652, 938],
[1338, 956],
[1362, 979],
[1419, 959],
[1625, 952],
[1641, 937],
[1628, 921],
[1387, 936],
[ 582, 921],
[ 478, 887],
[ 444, 889]], dtype=int32)
unclip_radio = 1.5
distance = 18.020694170941756
offset.Execute(distance) = [
[[484, 870], [585, 903], [1386, 918], [1627, 903], [1633, 904], [1638, 906], [1642, 910], [1655, 926], [1658, 931], [1659, 937], [1658, 943], [1653, 950], [1637, 965], [1632, 968], [1626, 970], [1422, 977], [1368, 996], [1362, 997], [1356, 996], [1355, 995], [1354, 996], [1349, 998], [1211, 1036], [1207, 1037], [985, 1055], [982, 1055], [696, 1017], [693, 1016], [502, 959], [499, 958], [426, 919], [421, 915], [417, 910], [416, 904], [417, 898], [419, 893], [429, 879], [434, 874], [439, 872], [443, 871], [477, 869]],
[[973, 994], [1241, 971], [725, 958]]
]
尝试了以下数据集
默认的示例数据集可以吗
默认的示例数据集可以吗
好像只提供了标注方法,没有提供示例数据集
可以调整数据传递给 NumPy 数组的所有子列表,使其长度相同,以确保一致性。在ppocr/postprocess/db_postprocess.py的156行调整一下代码:
data_array = offset.Execute(distance)
max_length = max(len(sublist) for sublist in data_array)
for sublist in data_array:
while len(sublist) < max_length:
sublist.append(sublist[-1])
expanded = np.array(data_array)
测试后不再出现上述问题。
可以调整数据传递给 NumPy 数组的所有子列表,使其长度相同,以确保一致性。在ppocr/postprocess/db_postprocess.py的156行调整一下代码:
data_array = offset.Execute(distance) max_length = max(len(sublist) for sublist in data_array) for sublist in data_array: while len(sublist) < max_length: sublist.append(sublist[-1]) expanded = np.array(data_array)
测试后不再出现上述问题。
报错是没有了,但是训练时评估的精度一直下降,不会上升
def unclip(self, box, unclip_ratio):
try:
poly = Polygon(box)
distance = poly.area * unclip_ratio / poly.length
offset = pyclipper.PyclipperOffset()
offset.AddPath(box, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)
offset_polygon = offset.Execute(distance)
expanded = np.array(offset_polygon)
except Exception as e:
print("error:",e)
print("box:",box)
print("distance:",distance)
print("offset_polygon:",offset_polygon)
return np.array(offset_polygon[0])
return expanded
目前建议先改为这样,这是因为db对文本分割区域的异常导致的问题,在执行offset.Execute(distance)后,可能会返回两个长度不一致的numpy数组,导致np.array()报错。
下面是我可视化出来的一个异常box形状: