Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import tensorflow_addons as tfa
|
| 7 |
+
|
| 8 |
+
import tensorflow as tf
|
| 9 |
+
from tensorflow.keras.utils import custom_object_scope
|
| 10 |
+
|
| 11 |
+
# Define a function to create the InstanceNormalization layer
|
| 12 |
+
def create_in():
|
| 13 |
+
return tfa.layers.InstanceNormalization()
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def model_out(model_path,img):
|
| 17 |
+
with custom_object_scope({'InstanceNormalization': create_in}):
|
| 18 |
+
model = tf.keras.models.load_model(model_path)
|
| 19 |
+
img = (img-127.5)/127.5
|
| 20 |
+
img = np.expand_dims(img, 0)
|
| 21 |
+
pred = model.predict(img)
|
| 22 |
+
pred = np.asarray(pred)
|
| 23 |
+
return pred[0]
|
| 24 |
+
|
| 25 |
+
st.title("Night to Day painting cyclegan")
|
| 26 |
+
day_inp = st.file_uploader("Night-time image input")
|
| 27 |
+
|
| 28 |
+
if day_inp is not None:
|
| 29 |
+
img = Image.open(day_inp)
|
| 30 |
+
img = img.resize((256, 256))
|
| 31 |
+
img = np.array(img)
|
| 32 |
+
pred = model_out('nighttoday2.h5', img)
|
| 33 |
+
st.image(img, caption="Uploaded Image")
|
| 34 |
+
st.image(((pred + 1) * 127.5).astype(np.uint8), caption="Generated Day-time Painting")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
st.header('Which architecture did I use architecture, Resnet-Blocks or Unet architecture?')
|
| 38 |
+
st.write('I have tried both Resnet and unet architecture')
|
| 39 |
+
st.write('But when using the Unet architecture, it produce more clear and understandable images')
|
| 40 |
+
st.write('I use the pix2pix generator from tensorflow examples module and same for the discriminator')
|
| 41 |
+
st.header('What datasets did you use to train your CycleGAN model?')
|
| 42 |
+
st.write('For the dataset, I used Unpaired Day to Night dataset available on kaggle')
|
| 43 |
+
st.header('What hardware I trained it on?')
|
| 44 |
+
st.write('I trained the model on Kaggle notebook on P100 gpu with 13 gigs of ram cuz my pc wouldnt be in a good state if I trained the cyclegan model on Intel HD')
|
| 45 |
+
st.header('How much time did it take')
|
| 46 |
+
st.write('It took aboul 70 epochs each of 20 seconds, DO THE MATH')
|
| 47 |
+
st.header('Why did I make this model?')
|
| 48 |
+
st.subheader('I made this model to extend my experience but mostly for FUNN!!!!')
|
| 49 |
+
st.write("-------------------------------------------------")
|