Beasto commited on
Commit
550384e
·
1 Parent(s): 9141a6d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+ import tensorflow_addons as tfa
6
+
7
+ import tensorflow as tf
8
+ from tensorflow.keras.utils import custom_object_scope
9
+
10
+ # Define a function to create the InstanceNormalization layer
11
+ def create_in():
12
+ return tfa.layers.InstanceNormalization()
13
+
14
+
15
+ def model_out(model_path,img):
16
+ with custom_object_scope({'InstanceNormalization': create_in}):
17
+ model = tf.keras.models.load_model(model_path)
18
+ img = (img-127.5)/127.5
19
+ img = np.expand_dims(img, 0)
20
+ pred = model.predict(img)
21
+ pred = np.asarray(pred)
22
+ return pred[0]
23
+
24
+ st.title("GrayScale to Colorized Image Pix2Pix")
25
+ day_inp = st.file_uploader("Grayscale image input")
26
+
27
+ if day_inp is not None:
28
+ img = cv2.imread(day_inp)
29
+ img = cv2.resize(img, (256, 256))
30
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
31
+ img = np.array(img)
32
+ pred = model_out('colorizer.h5', img)
33
+ st.image(img, caption="Uploaded Image")
34
+ st.image(((pred + 1) * 127.5).astype(np.uint8), caption="Generated Colorized Painting")