Spaces:
Build error
Build error
Commit
·
01d54da
1
Parent(s):
e1b9319
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
import keras
|
3 |
from keras.models import load_model
|
4 |
-
# from keras_contrib.layers.normalization.instancenormalization import InstanceNormalization
|
5 |
from tensorflow_addons.layers import InstanceNormalization
|
6 |
import matplotlib.pyplot as plt
|
7 |
import numpy as np
|
8 |
import tensorflow as tf
|
9 |
|
10 |
-
|
11 |
cust = {'InstanceNormalization': InstanceNormalization}
|
12 |
model=load_model('g-cycleGAN-photo2monet-500images-epoch10_30_30_30_30_30_1000images_30.h5',cust)
|
13 |
|
@@ -21,56 +19,29 @@ IMG_WIDTH = 256
|
|
21 |
IMG_HEIGHT = 256
|
22 |
|
23 |
def resize(image,height,width):
|
24 |
-
'''
|
25 |
-
Resizing the image
|
26 |
-
'''
|
27 |
resized_image = tf.image.resize(image,[height,width],method = tf.image.ResizeMethod.NEAREST_NEIGHBOR)
|
28 |
return resized_image
|
29 |
|
30 |
def normalize(input_image):
|
31 |
-
# def normalize(real_image, input_image)
|
32 |
input_image = (input_image/127.5) - 1
|
33 |
return input_image
|
34 |
-
# real_image = (real_image/127.5) - 1
|
35 |
-
# return real_image,input_image
|
36 |
|
37 |
def load(img_file):
|
38 |
-
'''
|
39 |
-
load the image. Since we need only the target image and a
|
40 |
-
gray scale version of the same, we are going to load one
|
41 |
-
and create the other from it
|
42 |
-
'''
|
43 |
img = tf.io.read_file(img_file)
|
44 |
img = tf.io.decode_jpeg(img)
|
45 |
-
|
46 |
-
# w = tf.shape(img)[1]
|
47 |
-
# w = w//2
|
48 |
-
|
49 |
-
# real_image = img[:,:w,:]
|
50 |
-
|
51 |
real_image = tf.cast(img,tf.float32)
|
52 |
|
53 |
return real_image
|
54 |
|
55 |
def load_image_test(image_file):
|
56 |
-
'''
|
57 |
-
We are not using random jitter here and thus creating
|
58 |
-
a gray scale image after resizing.
|
59 |
-
'''
|
60 |
re = load(image_file)
|
61 |
re = resize(re,IMG_HEIGHT,IMG_WIDTH)
|
62 |
-
# inp = tf.image.rgb_to_grayscale(re)
|
63 |
-
# re,inp = normalize(re,inp)
|
64 |
-
# inp = re
|
65 |
-
# re, inp = normalize(re,inp)
|
66 |
re = normalize(re)
|
67 |
-
# return inp,re
|
68 |
return re
|
69 |
|
70 |
|
71 |
def show_preds_image(image_path):
|
72 |
A = load_image_test(image_path)
|
73 |
-
# A = (A - 127.5) / 127.5
|
74 |
A = np.expand_dims(A,axis=0)
|
75 |
B = model(A)
|
76 |
# B = np.squeeze(B,axis=0)
|
|
|
1 |
import gradio as gr
|
2 |
import keras
|
3 |
from keras.models import load_model
|
|
|
4 |
from tensorflow_addons.layers import InstanceNormalization
|
5 |
import matplotlib.pyplot as plt
|
6 |
import numpy as np
|
7 |
import tensorflow as tf
|
8 |
|
|
|
9 |
cust = {'InstanceNormalization': InstanceNormalization}
|
10 |
model=load_model('g-cycleGAN-photo2monet-500images-epoch10_30_30_30_30_30_1000images_30.h5',cust)
|
11 |
|
|
|
19 |
IMG_HEIGHT = 256
|
20 |
|
21 |
def resize(image,height,width):
|
|
|
|
|
|
|
22 |
resized_image = tf.image.resize(image,[height,width],method = tf.image.ResizeMethod.NEAREST_NEIGHBOR)
|
23 |
return resized_image
|
24 |
|
25 |
def normalize(input_image):
|
|
|
26 |
input_image = (input_image/127.5) - 1
|
27 |
return input_image
|
|
|
|
|
28 |
|
29 |
def load(img_file):
|
|
|
|
|
|
|
|
|
|
|
30 |
img = tf.io.read_file(img_file)
|
31 |
img = tf.io.decode_jpeg(img)
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
real_image = tf.cast(img,tf.float32)
|
33 |
|
34 |
return real_image
|
35 |
|
36 |
def load_image_test(image_file):
|
|
|
|
|
|
|
|
|
37 |
re = load(image_file)
|
38 |
re = resize(re,IMG_HEIGHT,IMG_WIDTH)
|
|
|
|
|
|
|
|
|
39 |
re = normalize(re)
|
|
|
40 |
return re
|
41 |
|
42 |
|
43 |
def show_preds_image(image_path):
|
44 |
A = load_image_test(image_path)
|
|
|
45 |
A = np.expand_dims(A,axis=0)
|
46 |
B = model(A)
|
47 |
# B = np.squeeze(B,axis=0)
|