File size: 1,021 Bytes
acc157c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e665ab1
acc157c
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import streamlit as st
import tensorflow as tf
import numpy as np
from PIL import Image
import tensorflow_addons as tfa
import tensorflow as tf
from tensorflow.keras.utils import custom_object_scope

# Define a function to create the InstanceNormalization layer
def create_in():
    return tfa.layers.InstanceNormalization()


def model_out(model_path,img):
  with custom_object_scope({'InstanceNormalization': create_in}):
    model = tf.keras.models.load_model(model_path)
  img = (img-127.5)/127.5
  img = np.expand_dims(img, 0)
  pred = model.predict(img)
  pred = np.asarray(pred)
  return pred[0]

day_inp = st.file_uploader("Sketch input")

if day_inp is not None:
  img = Image.open(day_inp)
  img = img.resize((256,256))
  img = np.asarray(img)
  img = np.reshape(img,(256,256,3))
  
  pred = model_out('FaceWithMask.h5', img)
  st.subheader('Input Image')
  st.image(img, caption="Uploaded Image")
  st.subheader('Pix2Pix Output')
  st.image(((pred + 1) * 127.5).astype(np.uint8), caption="Generated Real Face")