RobotJelly commited on
Commit
6369381
1 Parent(s): c31705d
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -8,16 +8,10 @@ import gradio as gr
8
  from huggingface_hub import from_pretrained_keras
9
 
10
  model = from_pretrained_keras("RobotJelly/GauGAN-Image-generation")
11
-
12
- def predict(image_file, segmentation_png, bitmap_img):
13
- image_list = [segmentation_png, image_file, bitmap_img]
14
 
15
- #segmentation_map = image_file.replace("images", "segmentation_map").replace("jpg", "png")
16
-
17
- #labels = image_file.replace("images", "segmentation_labels").replace("jpg", "bmp")
18
- #print("labels", labels)
19
 
20
- #image_list = [segmentation_map, image_file, labels]
21
 
22
  image = tf.image.decode_png(tf.io.read_file(image_list[1]), channels=3)
23
  image = tf.cast(image, tf.float32) / 127.5 - 1
@@ -26,6 +20,8 @@ def predict(image_file, segmentation_png, bitmap_img):
26
  segmentation_file = tf.cast(segmentation_file, tf.float32)/127.5 - 1
27
 
28
  label_file = tf.image.decode_bmp(tf.io.read_file(image_list[2]), channels=0)
 
 
29
  label_file = tf.squeeze(label_file)
30
 
31
  image_list = [segmentation_file, image, label_file]
@@ -54,18 +50,15 @@ def predict(image_file, segmentation_png, bitmap_img):
54
  latent_vector = tf.random.normal(shape=(1, 256), mean=0.0, stddev=2.0)
55
 
56
  # Generate fake images
57
- # fake_image = tf.squeeze(model.predict([latent_vector, final_img_list[2]]), axis=0)
58
  fake_image = model.predict([latent_vector, final_img_list[2]])
 
59
 
60
- #real_images = final_img_list
61
- fake = Image.fromarray((fake_image[0]+1)/2)
62
- # return tf.squeeze(real_images[1], axis=0), fake_image
63
- return fake
64
 
65
  # input
66
  input = [gr.inputs.Image(type="filepath", label="Ground Truth - Real Image (jpg)"),
67
  gr.inputs.Image(type="filepath", label="Segementated image (png)"),
68
- gr.inputs.Image(type="filepath", label="corresponding bitmap image (bmp)")]
69
 
70
  examples = [["facades_data/cmp_b0010.jpg", "facades_data/cmp_b0010.png", "facades_data/cmp_b0010.bmp"],
71
  ["facades_data/cmp_b0020.jpg", "facades_data/cmp_b0020.png", "facades_data/cmp_b0020.bmp"],
@@ -74,7 +67,7 @@ examples = [["facades_data/cmp_b0010.jpg", "facades_data/cmp_b0010.png", "facade
74
  ["facades_data/cmp_b0050.jpg", "facades_data/cmp_b0050.png", "facades_data/cmp_b0050.bmp"]]
75
 
76
  # output
77
- output = [gr.outputs.Image(type="pil", label="Generated - Conditioned Images")]
78
 
79
  title = "GauGAN For Conditional Image Generation"
80
  description = "Upload an Image or take one from examples to generate realistic images that are conditioned on cue images and segmentation maps"
 
8
  from huggingface_hub import from_pretrained_keras
9
 
10
  model = from_pretrained_keras("RobotJelly/GauGAN-Image-generation")
 
 
 
11
 
12
+ def predict(image_file, segmentation_png, bitmap_img):
 
 
 
13
 
14
+ image_list = [segmentation_png, image_file, bitmap_img]
15
 
16
  image = tf.image.decode_png(tf.io.read_file(image_list[1]), channels=3)
17
  image = tf.cast(image, tf.float32) / 127.5 - 1
 
20
  segmentation_file = tf.cast(segmentation_file, tf.float32)/127.5 - 1
21
 
22
  label_file = tf.image.decode_bmp(tf.io.read_file(image_list[2]), channels=0)
23
+ # label_file = tf.image.rgb_to_grayscale(tf.image.decode_bmp(tf.io.read_file(image_list[2]), channels=3))
24
+ #print("after decode_bmp --> ", label_file.shape, type(label_file))
25
  label_file = tf.squeeze(label_file)
26
 
27
  image_list = [segmentation_file, image, label_file]
 
50
  latent_vector = tf.random.normal(shape=(1, 256), mean=0.0, stddev=2.0)
51
 
52
  # Generate fake images
 
53
  fake_image = model.predict([latent_vector, final_img_list[2]])
54
+ fake_img = tf.squeeze(fake_image, axis=0)
55
 
56
+ return np.array(fake_img)
 
 
 
57
 
58
  # input
59
  input = [gr.inputs.Image(type="filepath", label="Ground Truth - Real Image (jpg)"),
60
  gr.inputs.Image(type="filepath", label="Segementated image (png)"),
61
+ gr.inputs.Image(type="filepath", label="corresponding bitmap image (bmp)", image_mode="L)]
62
 
63
  examples = [["facades_data/cmp_b0010.jpg", "facades_data/cmp_b0010.png", "facades_data/cmp_b0010.bmp"],
64
  ["facades_data/cmp_b0020.jpg", "facades_data/cmp_b0020.png", "facades_data/cmp_b0020.bmp"],
 
67
  ["facades_data/cmp_b0050.jpg", "facades_data/cmp_b0050.png", "facades_data/cmp_b0050.bmp"]]
68
 
69
  # output
70
+ output = [gr.outputs.Image(type="numpy", label="Generated - Conditioned Images")]
71
 
72
  title = "GauGAN For Conditional Image Generation"
73
  description = "Upload an Image or take one from examples to generate realistic images that are conditioned on cue images and segmentation maps"