Spaces:
Configuration error
Configuration error
Danila-Pechenev
commited on
Commit
·
2bbe009
1
Parent(s):
82751ae
Cosmetics
Browse files- app/model.py +13 -13
app/model.py
CHANGED
@@ -15,19 +15,19 @@ def run_model(image_bytes: io.BytesIO, model: keras.Model) -> Image.Image:
|
|
15 |
height: int
|
16 |
width, height = image.size
|
17 |
image: Image.Image = image.resize((960, 640))
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
output: np.ndarray = model.predict(
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
(np.shape(
|
26 |
)
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
# Uncomment if necessary:
|
32 |
# output_image.save("user_data/output.jpg")
|
33 |
-
return
|
|
|
15 |
height: int
|
16 |
width, height = image.size
|
17 |
image: Image.Image = image.resize((960, 640))
|
18 |
+
image_array1: np.ndarray = keras.utils.img_to_array(image)
|
19 |
+
image_array2: np.ndarray = image_array1.astype("float32") / 255.0
|
20 |
+
image_array3: np.ndarray = np.expand_dims(image_array2, axis=0)
|
21 |
+
output: np.ndarray = model.predict(image_array3)
|
22 |
+
output_image_array1: np.ndarray = output[0] * 255.0
|
23 |
+
output_image_array2: np.ndarray = output_image_array1.clip(0, 255)
|
24 |
+
output_image_array3: np.ndarray = output_image_array2.reshape(
|
25 |
+
(np.shape(output_image_array2)[0], np.shape(output_image_array2)[1], 3)
|
26 |
)
|
27 |
+
output_image_array4: np.ndarray = np.uint32(output_image_array3)
|
28 |
+
output_image_array5: np.ndarray = output_image_array4.astype(np.uint8)
|
29 |
+
output_image1: Image.Image = Image.fromarray(output_image_array5)
|
30 |
+
output_image2: Image.Image = output_image1.resize((width, height))
|
31 |
# Uncomment if necessary:
|
32 |
# output_image.save("user_data/output.jpg")
|
33 |
+
return output_image2
|