Spaces:
Runtime error
Runtime error
First model version
Browse files- README.md +4 -4
- app.py +50 -59
- configs/det/r50_baseline.yaml +1 -1
- det_demo.py +3 -2
- {output/ctw → det_model}/last_checkpoint +0 -0
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
-
title: ContourNet
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.0.10
|
| 8 |
app_file: app.py
|
|
|
|
| 1 |
---
|
| 2 |
+
title: ContourNet
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.0.10
|
| 8 |
app_file: app.py
|
app.py
CHANGED
|
@@ -1,71 +1,62 @@
|
|
| 1 |
import os
|
| 2 |
os.system('pip install --upgrade --no-cache-dir gdown')
|
| 3 |
-
os.system('gdown -O ./output/ctw/model_ctw.pth
|
| 4 |
-
|
| 5 |
-
|
| 6 |
os.system('pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"')
|
| 7 |
os.system('python setup.py build develop --user')
|
| 8 |
|
| 9 |
-
import glob
|
| 10 |
-
import gradio as gr
|
| 11 |
-
#from demo import get_model, preprocess, postprocess, load
|
| 12 |
-
#from utils import Config, Logger, CharsetMapper
|
| 13 |
import cv2
|
| 14 |
import pandas as pd
|
|
|
|
|
|
|
| 15 |
from det_demo import DetDemo
|
| 16 |
from maskrcnn_benchmark.config import cfg
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
'''
|
| 55 |
-
|
| 56 |
-
# visual detect results
|
| 57 |
-
visual_image = det_demo.visualization(image.copy(), result_polygons, result_masks, result_boxes)
|
| 58 |
-
cv2.imwrite('result.jpg', visual_image)
|
| 59 |
-
return 'result.jpg'#, pd.DataFrame(result_words)
|
| 60 |
|
| 61 |
-
title = "张博强毕设中期展示(文本识别部分)"
|
| 62 |
-
description = "西北工业大学航海学院张博强毕设,目前识别部分进度为复现abinet,本网页为abinet复现的可视化web端展示"
|
| 63 |
-
#article = "<p style='text-align: center'><a href='https://arxiv.org/pdf/2103.06495.pdf'>Read Like Humans: Autonomous, Bidirectional and Iterative Language Modeling for Scene Text Recognition</a> | <a href='https://github.com/FangShancheng/ABINet'>Github Repo</a></p>"
|
| 64 |
|
| 65 |
-
iface = gr.Interface(
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
os.system('pip install --upgrade --no-cache-dir gdown')
|
| 3 |
+
os.system('gdown -O ./output/ctw/model_ctw.pth 1ydYjuxJglLAJRVWjj6sKXM3aBL2pXRpG')
|
| 4 |
+
os.system('gdown -O ./workdir.zip 1mYM_26qHUom_5NU7iutHneB_KHlLjL5y')
|
| 5 |
+
os.system('unzip workdir.zip')
|
| 6 |
os.system('pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"')
|
| 7 |
os.system('python setup.py build develop --user')
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
import cv2
|
| 10 |
import pandas as pd
|
| 11 |
+
import gradio as gr
|
| 12 |
+
|
| 13 |
from det_demo import DetDemo
|
| 14 |
from maskrcnn_benchmark.config import cfg
|
| 15 |
|
| 16 |
+
from demo import get_model, preprocess, postprocess, load
|
| 17 |
+
from utils import Config, Logger, CharsetMapper
|
| 18 |
+
import torch
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def infer(filepath):
|
| 22 |
+
config = Config('configs/rec/train_abinet.yaml')
|
| 23 |
+
config.model_vision_checkpoint = None
|
| 24 |
+
model = get_model(config)
|
| 25 |
+
model = load(model, 'workdir/train-abinet/best-train-abinet.pth')
|
| 26 |
+
charset = CharsetMapper(filename=config.dataset_charset_path, max_length=config.dataset_max_length + 1)
|
| 27 |
+
|
| 28 |
+
cfg.merge_from_file('./configs/det/r50_baseline.yaml')
|
| 29 |
+
# manual override some options
|
| 30 |
+
cfg.merge_from_list(["MODEL.DEVICE", "cpu"])
|
| 31 |
+
|
| 32 |
+
det_demo = DetDemo(
|
| 33 |
+
cfg,
|
| 34 |
+
min_image_size=800,
|
| 35 |
+
confidence_threshold=0.7,
|
| 36 |
+
output_polygon=True
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
image = cv2.imread(filepath)
|
| 40 |
+
result_polygons, result_masks, result_boxes = det_demo.run_on_opencv_image(image)
|
| 41 |
+
|
| 42 |
+
patchs = [image[box[1]:box[3], box[0]:box[2], :] for box in result_boxes]
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
iface = gr.Interface(
|
| 55 |
+
fn=infer,
|
| 56 |
+
title="张博强毕设展示",
|
| 57 |
+
description="毕设题目:自然场景中任意形状文字的检测与识别\n目前进度:检测",
|
| 58 |
+
inputs=[gr.inputs.Image(label="image", type="filepath")],
|
| 59 |
+
outputs=[gr.outputs.Image(), gr.outputs.Dataframe(headers=['word'])],
|
| 60 |
+
#examples=['example1.jpg', 'example2.jpg', 'example3.jpg'],
|
| 61 |
+
#article="<a href=\"https://github.com/MhLiao/MaskTextSpotterV3\">GitHub Repo</a>",
|
| 62 |
+
).launch(enable_queue=True)
|
configs/det/r50_baseline.yaml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
OUTPUT_DIR: "./
|
| 2 |
MODEL:
|
| 3 |
META_ARCHITECTURE: "GeneralizedRCNN"
|
| 4 |
WEIGHT: "catalog://ImageNetPretrained/MSRA/R-50"
|
|
|
|
| 1 |
+
OUTPUT_DIR: "./det_model/"
|
| 2 |
MODEL:
|
| 3 |
META_ARCHITECTURE: "GeneralizedRCNN"
|
| 4 |
WEIGHT: "catalog://ImageNetPretrained/MSRA/R-50"
|
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, 0.4, (0,0,255), 1)
|
| 584 |
'''
|
| 585 |
for box in boxes:
|
| 586 |
cv2.rectangle(image,(box[0], box[1]), (box[2], box[3]), (0,0,255), 2)
|
{output/ctw → det_model}/last_checkpoint
RENAMED
|
File without changes
|