Spaces:
Runtime error
Runtime error
First model version
Browse files
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import os
|
2 |
os.system('pip install --upgrade --no-cache-dir gdown')
|
3 |
os.system('gdown -O ./output/ctw/model_ctw.pth 1Ajslu_9WisuZ2nJGzE6qbD87aK6_ozzA')
|
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 |
|
@@ -17,12 +17,13 @@ from maskrcnn_benchmark.config import cfg
|
|
17 |
|
18 |
def process_image(filepath):
|
19 |
# rec model
|
|
|
20 |
config = Config('configs/rec/train_abinet.yaml')
|
21 |
config.model_vision_checkpoint = None
|
22 |
model = get_model(config)
|
23 |
model = load(model, 'workdir/train-abinet/best-train-abinet.pth')
|
24 |
charset = CharsetMapper(filename=config.dataset_charset_path, max_length=config.dataset_max_length + 1)
|
25 |
-
|
26 |
# det model
|
27 |
cfg.merge_from_file('./configs/det/r50_baseline.yaml')
|
28 |
cfg.merge_from_list(["MODEL.DEVICE", "cpu"])
|
@@ -38,7 +39,11 @@ def process_image(filepath):
|
|
38 |
result_polygons, result_masks, result_boxes = det_demo.run_on_opencv_image(image)
|
39 |
|
40 |
# cut patch
|
41 |
-
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
|
|
|
|
|
|
|
|
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.stack(patchs, dim=0)
|
@@ -46,6 +51,7 @@ def process_image(filepath):
|
|
46 |
res = model(patchs)
|
47 |
rec_result = postprocess(res, charset, 'alignment')[0]
|
48 |
print(rec_result)
|
|
|
49 |
|
50 |
# visual detect results
|
51 |
visual_image = det_demo.visualization(image.copy(), result_polygons, result_masks, result_boxes)
|
@@ -64,7 +70,7 @@ description = "西北工业大学航海学院张博强毕设,目前识别部
|
|
64 |
|
65 |
iface = gr.Interface(fn=process_image,
|
66 |
inputs=[gr.inputs.Image(label="image", type="filepath")],
|
67 |
-
outputs=[gr.outputs.Image()
|
68 |
title=title,
|
69 |
description=description,
|
70 |
examples=glob.glob('figs/test/*.png'))
|
|
|
1 |
import os
|
2 |
os.system('pip install --upgrade --no-cache-dir gdown')
|
3 |
os.system('gdown -O ./output/ctw/model_ctw.pth 1Ajslu_9WisuZ2nJGzE6qbD87aK6_ozzA')
|
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 |
|
|
|
17 |
|
18 |
def process_image(filepath):
|
19 |
# rec model
|
20 |
+
'''
|
21 |
config = Config('configs/rec/train_abinet.yaml')
|
22 |
config.model_vision_checkpoint = None
|
23 |
model = get_model(config)
|
24 |
model = load(model, 'workdir/train-abinet/best-train-abinet.pth')
|
25 |
charset = CharsetMapper(filename=config.dataset_charset_path, max_length=config.dataset_max_length + 1)
|
26 |
+
'''
|
27 |
# det model
|
28 |
cfg.merge_from_file('./configs/det/r50_baseline.yaml')
|
29 |
cfg.merge_from_list(["MODEL.DEVICE", "cpu"])
|
|
|
39 |
result_polygons, result_masks, result_boxes = det_demo.run_on_opencv_image(image)
|
40 |
|
41 |
# cut patch
|
42 |
+
#image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
43 |
+
patchs = [image[box[1]:box[3], box[0]:box[2], :] for box in result_boxes]
|
44 |
+
patchs = [cv2.resize(patch, (128,32)) for patch in patchs]
|
45 |
+
patchs = np.stack(patchs, axis=0).transpose(0,3,1,2)
|
46 |
+
'''
|
47 |
patchs = [image[box[1]:box[3], box[0]:box[2], :] for box in result_boxes]
|
48 |
patchs = [preprocess(patch, config.dataset_image_width, config.dataset_image_height) for patch in patchs]
|
49 |
patchs = torch.stack(patchs, dim=0)
|
|
|
51 |
res = model(patchs)
|
52 |
rec_result = postprocess(res, charset, 'alignment')[0]
|
53 |
print(rec_result)
|
54 |
+
'''
|
55 |
|
56 |
# visual detect results
|
57 |
visual_image = det_demo.visualization(image.copy(), result_polygons, result_masks, result_boxes)
|
|
|
70 |
|
71 |
iface = gr.Interface(fn=process_image,
|
72 |
inputs=[gr.inputs.Image(label="image", type="filepath")],
|
73 |
+
outputs=[gr.outputs.Image()],#, gr.outputs.Textbox()
|
74 |
title=title,
|
75 |
description=description,
|
76 |
examples=glob.glob('figs/test/*.png'))
|