Spaces:
Runtime error
Runtime error
First model version
Browse files
app.py
CHANGED
@@ -1,25 +1,29 @@
|
|
1 |
import os
|
2 |
-
os.system('pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"')
|
3 |
-
os.system('python setup.py build develop --user')
|
4 |
os.system('pip install --upgrade --no-cache-dir gdown')
|
5 |
os.system('gdown -O ./output/ctw/model_ctw.pth 1nhT7yuqJ8V8vfoJdI0Qn6notmoLFRrmm')
|
6 |
os.system('gdown -O ./workdir.zip 1mYM_26qHUom_5NU7iutHneB_KHlLjL5y')
|
7 |
os.system('unzip workdir.zip')
|
|
|
|
|
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 |
|
14 |
def process_image(image):
|
15 |
config = Config('configs/rec/train_abinet.yaml')
|
16 |
config.model_vision_checkpoint = None
|
17 |
model = get_model(config)
|
18 |
-
model = load(model, 'workdir/train-abinet/best-train-abinet.pth')
|
19 |
charset = CharsetMapper(filename=config.dataset_charset_path, max_length=config.dataset_max_length + 1)
|
20 |
|
21 |
img = image.convert('RGB')
|
22 |
-
img = preprocess(img, config.dataset_image_width, config.dataset_image_height)
|
23 |
res = model(img)
|
24 |
return postprocess(res, charset, 'alignment')[0][0]
|
25 |
|
|
|
1 |
import os
|
|
|
|
|
2 |
os.system('pip install --upgrade --no-cache-dir gdown')
|
3 |
os.system('gdown -O ./output/ctw/model_ctw.pth 1nhT7yuqJ8V8vfoJdI0Qn6notmoLFRrmm')
|
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 glob
|
10 |
import gradio as gr
|
11 |
from demo import get_model, preprocess, postprocess, load
|
12 |
from utils import Config, Logger, CharsetMapper
|
13 |
+
from accelerate import Accelerator
|
14 |
+
|
15 |
+
accelerator = Accelerator()
|
16 |
+
device = accelerator.device
|
17 |
|
18 |
def process_image(image):
|
19 |
config = Config('configs/rec/train_abinet.yaml')
|
20 |
config.model_vision_checkpoint = None
|
21 |
model = get_model(config)
|
22 |
+
model = load(model, 'workdir/train-abinet/best-train-abinet.pth').to(device)
|
23 |
charset = CharsetMapper(filename=config.dataset_charset_path, max_length=config.dataset_max_length + 1)
|
24 |
|
25 |
img = image.convert('RGB')
|
26 |
+
img = preprocess(img, config.dataset_image_width, config.dataset_image_height).to(device)
|
27 |
res = model(img)
|
28 |
return postprocess(res, charset, 'alignment')[0][0]
|
29 |
|