Danila-Pechenev commited on
Commit
2bbe009
·
1 Parent(s): 82751ae
Files changed (1) hide show
  1. 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
- image_array: np.ndarray = keras.utils.img_to_array(image)
19
- image_array: np.ndarray = image_array.astype("float32") / 255.0
20
- image_array: np.ndarray = np.expand_dims(image_array, axis=0)
21
- output: np.ndarray = model.predict(image_array)
22
- output_image_array: np.ndarray = output[0] * 255.0
23
- output_image_array: np.ndarray = output_image_array.clip(0, 255)
24
- output_image_array: np.ndarray = output_image_array.reshape(
25
- (np.shape(output_image_array)[0], np.shape(output_image_array)[1], 3)
26
  )
27
- output_image_array: np.ndarray = np.uint32(output_image_array)
28
- output_image_array: np.ndarray = output_image_array.astype(np.uint8)
29
- output_image: Image.Image = Image.fromarray(output_image_array)
30
- output_image: Image.Image = output_image.resize((width, height))
31
  # Uncomment if necessary:
32
  # output_image.save("user_data/output.jpg")
33
- return output_image
 
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