Beasto commited on
Commit
acc157c
·
1 Parent(s): fa373fe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import tensorflow as tf
7
+ from tensorflow.keras.utils import custom_object_scope
8
+
9
+ # Define a function to create the InstanceNormalization layer
10
+ def create_in():
11
+ return tfa.layers.InstanceNormalization()
12
+
13
+
14
+ def model_out(model_path,img):
15
+ with custom_object_scope({'InstanceNormalization': create_in}):
16
+ model = tf.keras.models.load_model(model_path)
17
+ img = (img-127.5)/127.5
18
+ img = np.expand_dims(img, 0)
19
+ pred = model.predict(img)
20
+ pred = np.asarray(pred)
21
+ return pred[0]
22
+
23
+ day_inp = st.file_uploader("Sketch input")
24
+
25
+ if day_inp is not None:
26
+ img = Image.open(day_inp)
27
+ img = img.resize((256,256))
28
+ img = np.asarray(img)
29
+ img = np.reshape(img,(1,256,256,3))
30
+
31
+ pred = model_out('FaceWithMask.h5', img)
32
+ st.subheader('Input Image')
33
+ st.image(img, caption="Uploaded Image")
34
+ st.subheader('Pix2Pix Output')
35
+ st.image(((pred + 1) * 127.5).astype(np.uint8), caption="Generated Real Face")