Spaces:
Runtime error
Runtime error
Harveenchadha
commited on
Commit
β’
5464b05
1
Parent(s):
fd6857d
Update app.py
Browse files
app.py
CHANGED
@@ -9,12 +9,32 @@ from huggingface_hub import from_pretrained_keras
|
|
9 |
model = from_pretrained_keras("Harveenchadha/low-light-image-enhancement", compile=False)
|
10 |
#examples = ['examples/179.png', 'examples/493.png', 'examples/780.png']
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def infer(original_image):
|
14 |
image = keras.preprocessing.image.img_to_array(original_image)
|
15 |
image = image.astype("float32") / 255.0
|
16 |
image = np.expand_dims(image, axis=0)
|
17 |
output = model.predict(image)
|
|
|
18 |
output_image = output[0] * 255.0
|
19 |
output_image = output_image.clip(0, 255)
|
20 |
print(output_image)
|
|
|
9 |
model = from_pretrained_keras("Harveenchadha/low-light-image-enhancement", compile=False)
|
10 |
#examples = ['examples/179.png', 'examples/493.png', 'examples/780.png']
|
11 |
|
12 |
+
def get_enhanced_image(data, output):
|
13 |
+
r1 = output[:, :, :, :3]
|
14 |
+
r2 = output[:, :, :, 3:6]
|
15 |
+
r3 = output[:, :, :, 6:9]
|
16 |
+
r4 = output[:, :, :, 9:12]
|
17 |
+
r5 = output[:, :, :, 12:15]
|
18 |
+
r6 = output[:, :, :, 15:18]
|
19 |
+
r7 = output[:, :, :, 18:21]
|
20 |
+
r8 = output[:, :, :, 21:24]
|
21 |
+
x = data + r1 * (tf.square(data) - data)
|
22 |
+
x = x + r2 * (tf.square(x) - x)
|
23 |
+
x = x + r3 * (tf.square(x) - x)
|
24 |
+
enhanced_image = x + r4 * (tf.square(x) - x)
|
25 |
+
x = enhanced_image + r5 * (tf.square(enhanced_image) - enhanced_image)
|
26 |
+
x = x + r6 * (tf.square(x) - x)
|
27 |
+
x = x + r7 * (tf.square(x) - x)
|
28 |
+
enhanced_image = x + r8 * (tf.square(x) - x)
|
29 |
+
return enhanced_image
|
30 |
+
|
31 |
+
|
32 |
def infer(original_image):
|
33 |
image = keras.preprocessing.image.img_to_array(original_image)
|
34 |
image = image.astype("float32") / 255.0
|
35 |
image = np.expand_dims(image, axis=0)
|
36 |
output = model.predict(image)
|
37 |
+
output = get_enhanced_image(image, output)
|
38 |
output_image = output[0] * 255.0
|
39 |
output_image = output_image.clip(0, 255)
|
40 |
print(output_image)
|