Update app.py
Browse files
app.py
CHANGED
|
@@ -33,11 +33,26 @@ def process_image(input_img):
|
|
| 33 |
img = img.resize((WIDTH, HEIGHT)) # Adjust size as needed
|
| 34 |
img_array = tf.keras.preprocessing.image.img_to_array(img) / 255.0
|
| 35 |
img_array = img_array[None, ..., 0:1] # Add batch dimension and keep single channel
|
| 36 |
-
print("img_array shape: ", img_array.shape)
|
|
|
|
| 37 |
# Run inference
|
| 38 |
output_array = loaded_autoencoder.predict(img_array)
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
custom_css = """
|
| 43 |
body {background: linear-gradient(135deg, #232526 0%, #414345 100%) !important;}
|
|
|
|
| 33 |
img = img.resize((WIDTH, HEIGHT)) # Adjust size as needed
|
| 34 |
img_array = tf.keras.preprocessing.image.img_to_array(img) / 255.0
|
| 35 |
img_array = img_array[None, ..., 0:1] # Add batch dimension and keep single channel
|
| 36 |
+
# print("img_array shape: ", img_array.shape)
|
| 37 |
+
|
| 38 |
# Run inference
|
| 39 |
output_array = loaded_autoencoder.predict(img_array)
|
| 40 |
+
print("output_array shape: ", output_array.shape)
|
| 41 |
+
|
| 42 |
+
# Assuming output_array has shape (1, 512, 512, 2) for U and V channels
|
| 43 |
+
# Extract Y (grayscale input) and UV (model output)
|
| 44 |
+
y_channel = img_array[0, :, :, 0] # Grayscale input (Y channel)
|
| 45 |
+
uv_channels = output_array[0] # Model output (U and V channels)
|
| 46 |
+
|
| 47 |
+
# Combine Y, U, V into a 3-channel YUV image
|
| 48 |
+
yuv_image = np.stack([y_channel, uv_channels[:, :, 0], uv_channels[:, :, 1]], axis=-1)
|
| 49 |
+
|
| 50 |
+
# Convert YUV to RGB
|
| 51 |
+
yuv_image = yuv_image * 255.0 # Denormalize
|
| 52 |
+
rgb_image = Image.fromarray(yuv_image.astype(np.uint8), mode="YCbCr") # Use YCbCr (alias for YUV in PIL)
|
| 53 |
+
rgb_image = rgb_image.convert("RGB") # Convert to RGB
|
| 54 |
+
|
| 55 |
+
return rgb_image
|
| 56 |
|
| 57 |
custom_css = """
|
| 58 |
body {background: linear-gradient(135deg, #232526 0%, #414345 100%) !important;}
|