Update utils.py
Browse files
utils.py
CHANGED
|
@@ -7,17 +7,18 @@ model = core.read_model(model='models/horizontal-text-detection-0001.xml')
|
|
| 7 |
compiled_model = core.compile_model(model = model, device_name="CPU")
|
| 8 |
input_layer = compiled_model.input(0)
|
| 9 |
output_layer = compiled_model.output(0)
|
| 10 |
-
#output_layer = compiled_model.output("boxes")
|
| 11 |
|
| 12 |
-
def
|
| 13 |
N, C, H, W = input_layer.shape
|
| 14 |
resized_image = cv2.resize(image, (W, H))
|
| 15 |
input_image = np.expand_dims(resized_image.transpose(2, 0, 1), 0)
|
| 16 |
return input_image, resized_image
|
| 17 |
|
| 18 |
def predict_image(image, conf_threshold):
|
| 19 |
-
input_image, resized_image =
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
boxes = boxes[~np.all(boxes == 0, axis=1)]
|
| 22 |
return boxes, resized_image
|
| 23 |
|
|
|
|
| 7 |
compiled_model = core.compile_model(model = model, device_name="CPU")
|
| 8 |
input_layer = compiled_model.input(0)
|
| 9 |
output_layer = compiled_model.output(0)
|
|
|
|
| 10 |
|
| 11 |
+
def preprocess_data(image, input_layer):
|
| 12 |
N, C, H, W = input_layer.shape
|
| 13 |
resized_image = cv2.resize(image, (W, H))
|
| 14 |
input_image = np.expand_dims(resized_image.transpose(2, 0, 1), 0)
|
| 15 |
return input_image, resized_image
|
| 16 |
|
| 17 |
def predict_image(image, conf_threshold):
|
| 18 |
+
input_image, resized_image = preprocess_data(image, input_layer)
|
| 19 |
+
output_key = compiled_model.output("boxes")
|
| 20 |
+
boxes = compiled_model([input_image])[output_key]
|
| 21 |
+
# Remove zero only boxes.
|
| 22 |
boxes = boxes[~np.all(boxes == 0, axis=1)]
|
| 23 |
return boxes, resized_image
|
| 24 |
|