ayaderaghul commited on
Commit
c771339
1 Parent(s): e9df5bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -6
app.py CHANGED
@@ -5,20 +5,77 @@ from keras.models import load_model
5
  from tensorflow_addons.layers import InstanceNormalization
6
  import matplotlib.pyplot as plt
7
  import numpy as np
 
 
8
 
9
  cust = {'InstanceNormalization': InstanceNormalization}
10
- model=load_model('g_model_AtoB_002160.h5',cust)
11
- # model=load_model('g_model_AtoB_000540.h5',cust)
12
 
13
  path = [['ex1.jpg'], ['ex2.jpg'], ['ex3.jpg'],['ex4.jpg'],['ex5.jpg']]
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def show_preds_image(image_path):
16
- A = plt.imread(image_path)
17
  # A = (A - 127.5) / 127.5
18
  A = np.expand_dims(A,axis=0)
19
- B = model.predict(A)
20
- B = np.squeeze(B,axis=0)
21
- B = (B + 1) / 2.0
 
22
  return B
23
 
24
  inputs_image = [
 
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.h5',cust)
 
13
 
14
  path = [['ex1.jpg'], ['ex2.jpg'], ['ex3.jpg'],['ex4.jpg'],['ex5.jpg']]
15
 
16
+ # preprocess
17
+ AUTOTUNE = tf.data.AUTOTUNE
18
+ BUFFER_SIZE = 400
19
+ BATCH_SIZE = 1
20
+ 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)
77
+ B = B[0]
78
+ B = B * 0.5 + 0.5
79
  return B
80
 
81
  inputs_image = [