Update app.py
Browse files
app.py
CHANGED
|
@@ -45,17 +45,15 @@ def initialize_model(model_file):
|
|
| 45 |
|
| 46 |
def get_text(img_org):
|
| 47 |
try:
|
| 48 |
-
|
|
|
|
| 49 |
x = transform(img_org.convert('RGB')).unsqueeze(0)
|
| 50 |
-
|
|
|
|
| 51 |
ort_inputs = {ort_session.get_inputs()[0].name: to_numpy(x)}
|
| 52 |
-
print("debugger3")
|
| 53 |
logits = ort_session.run(None, ort_inputs)[0]
|
| 54 |
-
print("debugger4")
|
| 55 |
probs = torch.tensor(logits).softmax(-1)
|
| 56 |
-
|
| 57 |
-
preds, _ = tokenizer_base.decode(probs)
|
| 58 |
-
print("debugger6")
|
| 59 |
preds = preds[0]
|
| 60 |
print(preds)
|
| 61 |
return preds
|
|
|
|
| 45 |
|
| 46 |
def get_text(img_org):
|
| 47 |
try:
|
| 48 |
+
# img_org = Image.open(image_path)
|
| 49 |
+
# Preprocess. Model expects a batch of images with shape: (B, C, H, W)
|
| 50 |
x = transform(img_org.convert('RGB')).unsqueeze(0)
|
| 51 |
+
|
| 52 |
+
# compute ONNX Runtime output prediction
|
| 53 |
ort_inputs = {ort_session.get_inputs()[0].name: to_numpy(x)}
|
|
|
|
| 54 |
logits = ort_session.run(None, ort_inputs)[0]
|
|
|
|
| 55 |
probs = torch.tensor(logits).softmax(-1)
|
| 56 |
+
preds, probs = tokenizer_base.decode(probs)
|
|
|
|
|
|
|
| 57 |
preds = preds[0]
|
| 58 |
print(preds)
|
| 59 |
return preds
|