Skip to content

Commit

Permalink
adapt to Numpy deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
bertsky committed Aug 17, 2023
1 parent 1204516 commit 12353bc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ocrd_segment/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def get(arg):

coco_eval.accumulate()
coco_eval.summarize()
statInds = np.ones(12, np.bool)
statInds = np.ones(12, bool)
statInds[7] = False # AR maxDet[1]
statInds[8] = False # AR maxDet[2]
coco_eval.stats = coco_eval.stats[statInds]
Expand Down
8 changes: 4 additions & 4 deletions ocrd_segment/extract_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def process(self):
self.parameter['plot_overlay'])
if not poly:
continue
polygon = np.array(poly.exterior.coords, np.int)[:-1].tolist()
polygon = np.array(poly.exterior.coords, int)[:-1].tolist()
xywh = xywh_from_polygon(polygon)
area = poly.area
description.setdefault('regions', []).append(
Expand All @@ -330,7 +330,7 @@ def process(self):
{'id': i, 'image_id': num_page_id,
'category_id': next((cat['id'] for cat in categories if cat['name'] == subrtype),
next((cat['id'] for cat in categories if cat['name'] == rtype))),
'segmentation': np.array(poly.exterior.coords, np.int)[:-1].reshape(1, -1).tolist(),
'segmentation': np.array(poly.exterior.coords, int)[:-1].reshape(1, -1).tolist(),
'area': area,
'bbox': [xywh['x'], xywh['y'], xywh['w'], xywh['h']],
'iscrowd': 0})
Expand Down Expand Up @@ -430,7 +430,7 @@ def get_points(rogroup, level):
poly = regiondict.get(regionref.get_regionRef(), None)
if poly:
# we have seen this region
morepoints.append((level, tuple(np.array(poly.centroid, np.int))))
morepoints.append((level, tuple(np.array(poly.centroid, int))))
if not isinstance(regionref, (RegionRefType, RegionRefIndexedType)):
# try to get subgroup regions instead
morepoints = get_points(regionref, level + 1) or morepoints
Expand All @@ -445,7 +445,7 @@ def get_points(rogroup, level):
points.extend(get_points(readingorder, 0))
else:
# use XML ordering
points.extend([(0, tuple(np.array(region.poly.centroid, np.int))) for region in regions])
points.extend([(0, tuple(np.array(region.poly.centroid, int))) for region in regions])
for p1, p2 in zip(points[:-1], points[1:]):
color = 'ReadingOrderLevel%s' % (str(p1[0]) if p1[0] < 2 else 'N')
if color not in classes:
Expand Down
4 changes: 2 additions & 2 deletions ocrd_segment/extract_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def process(self):
poly = segment_poly(page_id, subregion, region_coords)
if not poly:
continue
polygon = np.array(poly.exterior.coords, np.int)[:-1].tolist()
polygon = np.array(poly.exterior.coords, int)[:-1].tolist()
xywh = xywh_from_polygon(polygon)
area = poly.area
if subrtype in ['TextRegion', 'ChartRegion', 'GraphicRegion']:
Expand All @@ -229,7 +229,7 @@ def process(self):
{'id': i, 'image_id': j,
'category_id': next((cat['id'] for cat in categories if cat['name'] == subsubrtype),
next((cat['id'] for cat in categories if cat['name'] == subrtype))),
'segmentation': np.array(poly.exterior.coords, np.int)[:-1].reshape(1, -1).tolist(),
'segmentation': np.array(poly.exterior.coords, int)[:-1].reshape(1, -1).tolist(),
'area': area,
'bbox': [xywh['x'], xywh['y'], xywh['w'], xywh['h']],
'iscrowd': 0})
Expand Down
4 changes: 2 additions & 2 deletions ocrd_segment/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def shrink_regions(page_image, page_coords, page, page_id, padding=0):
scale = 43
for region in page.get_AllRegions():
#LOG.info('Shrinking region "%s"', region.id)
region_mask = np.zeros_like(page_array, dtype=np.bool)
region_mask = np.zeros_like(page_array, dtype=bool)
region_polygon = coordinates_of_segment(region, page_image, page_coords)
region_mask[draw.polygon(region_polygon[:, 1],
region_polygon[:, 0],
Expand Down Expand Up @@ -701,7 +701,7 @@ def ensure_valid(element):
coords = element.get_Coords()
points = coords.points
polygon = polygon_from_points(points)
array = np.array(polygon, np.int)
array = np.array(polygon, int)
if array.min() < 0:
array = np.maximum(0, array)
changed = True
Expand Down

0 comments on commit 12353bc

Please sign in to comment.