|
|
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 |
|
|
|
|
|
|
|
|
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") |