Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,23 @@ def ctc_lambda_func(args):
|
|
10 |
# Load the model, providing the custom loss function in the custom_objects dictionary
|
11 |
loaded_model = load_model('Text_recognizer_Using_CRNN_model.keras', custom_objects={'ctc': ctc_lambda_func},safe_mode=False)
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def greet(name):
|
14 |
-
return "Hello " +
|
15 |
|
16 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
17 |
demo.launch()
|
|
|
10 |
# Load the model, providing the custom loss function in the custom_objects dictionary
|
11 |
loaded_model = load_model('Text_recognizer_Using_CRNN_model.keras', custom_objects={'ctc': ctc_lambda_func},safe_mode=False)
|
12 |
|
13 |
+
filepath="test_img.png"
|
14 |
+
img = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
|
15 |
+
img = process_image(img)
|
16 |
+
prediction =loaded_model.predict(np.asarray([img]))
|
17 |
+
decoded = K.ctc_decode(prediction,
|
18 |
+
input_length=np.ones(prediction.shape[0]) * prediction.shape[1],
|
19 |
+
greedy=True)[0][0]
|
20 |
+
out = K.get_value(decoded)
|
21 |
+
# see the results
|
22 |
+
temp_str=""
|
23 |
+
for i, x in enumerate(out):
|
24 |
+
for p in x:
|
25 |
+
if int(p) != -1:
|
26 |
+
temp_str+=char_list[int(p)]
|
27 |
+
|
28 |
def greet(name):
|
29 |
+
return "Hello " + temp_str + "!!"
|
30 |
|
31 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
32 |
demo.launch()
|