Update main.py
Browse files
main.py
CHANGED
@@ -1,9 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import io
|
2 |
from flask import Flask, request, jsonify
|
3 |
import base64
|
4 |
import pytesseract
|
5 |
import numpy as np
|
6 |
-
import tensorflow as tf
|
7 |
from pickle import load
|
8 |
from PIL import Image
|
9 |
from keras.applications.xception import Xception # to get pre-trained model Xception
|
@@ -14,17 +21,6 @@ app = Flask(__name__)
|
|
14 |
|
15 |
MAX_LENGTH = 38
|
16 |
|
17 |
-
# Set up GPU memory growth
|
18 |
-
physical_devices = tf.config.list_physical_devices('GPU')
|
19 |
-
if physical_devices:
|
20 |
-
try:
|
21 |
-
# Allow memory growth for all GPUs
|
22 |
-
for gpu in physical_devices:
|
23 |
-
tf.config.experimental.set_memory_growth(gpu, True)
|
24 |
-
print("GPU(s) memory growth set to True")
|
25 |
-
except RuntimeError as e:
|
26 |
-
print(e)
|
27 |
-
|
28 |
def format_tesseract_output(output_text):
|
29 |
formatted_text = ""
|
30 |
lines = output_text.strip().split("\n")
|
@@ -39,8 +35,6 @@ def extract_features(image_data, model):
|
|
39 |
try:
|
40 |
image = Image.open(io.BytesIO(image_data))
|
41 |
except Exception as e:
|
42 |
-
print("ERROR: Can't open image! Ensure that image data is correct and in the expected format")
|
43 |
-
print(str(e))
|
44 |
return None
|
45 |
|
46 |
image = image.resize((299,299))
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
|
3 |
+
# Detect and init the GPU
|
4 |
+
physical_devices = tf.config.list_physical_devices('GPU')
|
5 |
+
if len(physical_devices) > 0:
|
6 |
+
tf.config.set_visible_devices(physical_devices[0], 'GPU')
|
7 |
+
tf.config.experimental.set_memory_growth(physical_devices[0], True)
|
8 |
+
|
9 |
import io
|
10 |
from flask import Flask, request, jsonify
|
11 |
import base64
|
12 |
import pytesseract
|
13 |
import numpy as np
|
|
|
14 |
from pickle import load
|
15 |
from PIL import Image
|
16 |
from keras.applications.xception import Xception # to get pre-trained model Xception
|
|
|
21 |
|
22 |
MAX_LENGTH = 38
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def format_tesseract_output(output_text):
|
25 |
formatted_text = ""
|
26 |
lines = output_text.strip().split("\n")
|
|
|
35 |
try:
|
36 |
image = Image.open(io.BytesIO(image_data))
|
37 |
except Exception as e:
|
|
|
|
|
38 |
return None
|
39 |
|
40 |
image = image.resize((299,299))
|