Spaces:
Build error
Build error
First model version
Browse files- app.py +2 -3
- det_demo.py +3 -2
app.py
CHANGED
@@ -43,10 +43,9 @@ def infer(filepath):
|
|
43 |
patchs = [preprocess(patch, config.dataset_image_width, config.dataset_image_height) for patch in patchs]
|
44 |
patchs = torch.cat(patchs, dim=0)
|
45 |
res = model(patchs)
|
46 |
-
|
47 |
-
print(rec_result)
|
48 |
|
49 |
-
visual_image = det_demo.visualization(image.copy(), result_polygons, result_masks, result_boxes)
|
50 |
|
51 |
cv2.imwrite('result.jpg', visual_image)
|
52 |
return 'result.jpg'#, pd.DataFrame(result_words)
|
|
|
43 |
patchs = [preprocess(patch, config.dataset_image_width, config.dataset_image_height) for patch in patchs]
|
44 |
patchs = torch.cat(patchs, dim=0)
|
45 |
res = model(patchs)
|
46 |
+
result_words = postprocess(res, charset, 'alignment')[0]
|
|
|
47 |
|
48 |
+
visual_image = det_demo.visualization(image.copy(), result_polygons, result_masks, result_boxes, result_words)
|
49 |
|
50 |
cv2.imwrite('result.jpg', visual_image)
|
51 |
return 'result.jpg'#, pd.DataFrame(result_words)
|
det_demo.py
CHANGED
@@ -573,13 +573,14 @@ class DetDemo(object):
|
|
573 |
polygon = list(map(int, polygon))
|
574 |
return polygon
|
575 |
|
576 |
-
def visualization(self, image, polygons, masks, boxes):
|
577 |
green = np.ones(image.shape).astype(np.uint8)
|
578 |
green[...,0] = 0
|
579 |
green[...,1] = 255
|
580 |
green[...,2] = 0
|
581 |
-
for mask in masks:
|
582 |
image[mask] = image[mask] * 0.5 + green[mask] * 0.5
|
|
|
583 |
'''
|
584 |
for box in boxes:
|
585 |
cv2.rectangle(image,(box[0], box[1]), (box[2], box[3]), (0,0,255), 2)
|
|
|
573 |
polygon = list(map(int, polygon))
|
574 |
return polygon
|
575 |
|
576 |
+
def visualization(self, image, polygons, masks, boxes, words):
|
577 |
green = np.ones(image.shape).astype(np.uint8)
|
578 |
green[...,0] = 0
|
579 |
green[...,1] = 255
|
580 |
green[...,2] = 0
|
581 |
+
for mask, word, box in zip(masks, words, boxes):
|
582 |
image[mask] = image[mask] * 0.5 + green[mask] * 0.5
|
583 |
+
cv2.putText(image, word, (box[0], box[1]), cv2.FONT_HERSHEY_COMPLEX, 1, (0,0,255), 2)
|
584 |
'''
|
585 |
for box in boxes:
|
586 |
cv2.rectangle(image,(box[0], box[1]), (box[2], box[3]), (0,0,255), 2)
|