amosfang commited on
Commit
a2eb125
·
verified ·
1 Parent(s): 66de018

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -14,7 +14,6 @@ import os
14
  import io
15
 
16
  REPO_ID = "amosfang/segmentation_u_net"
17
- image_folder = 'example_images'
18
 
19
  def pil_image_as_numpy_array(pilimg):
20
  img_array = tf.keras.utils.img_to_array(pilimg)
@@ -36,13 +35,14 @@ def load_model_file(filename):
36
  unet_model = load_model(saved_model_filepath)
37
  return unet_model
38
 
39
- def get_sample_images(image_folder):
40
 
41
  # Get a list of all files in the folder
42
  img_file_list = os.listdir(image_folder)
 
43
 
44
- # Filter out only the image files (assuming images have extensions like '.jpg'.)
45
- image_files = [[image_folder +'/' + file] for file in img_file_list if file.lower().endswith(('.jpg', '.jpeg'))]
46
 
47
  return image_files
48
 
@@ -75,6 +75,7 @@ def get_predictions(y_prediction_encoded):
75
  return predicted_label_indices
76
 
77
  def predict_on_train(image):
 
78
  # Steps to get prediction
79
  sample_image_resized = resize_image(image)
80
  y_pred = ensemble_predict(sample_image_resized)
@@ -110,6 +111,7 @@ def predict_on_train(image):
110
  return image_pil, image_pil
111
 
112
  def predict_on_test(image):
 
113
  # Steps to get prediction
114
  sample_image_resized = resize_image(image)
115
  y_pred = ensemble_predict(sample_image_resized)
@@ -146,6 +148,7 @@ def predict_on_test(image):
146
 
147
 
148
  sample_images = get_sample_images('example_images')
 
149
 
150
  description= '''
151
  The DeepGlobe Land Cover Classification Challenge offers the first public dataset containing high resolution
@@ -167,21 +170,22 @@ description= '''
167
  # examples=sample_images
168
  # ).launch(debug=True, share=True)
169
 
 
170
  tab1 = gr.Interface(
171
  fn=predict_on_train,
172
  inputs=gr.Image(),
173
  outputs=[gr.Image(), gr.Image()],
174
  title='Images with Ground Truth',
175
  description=description,
176
- examples=sample_images
177
  )
178
 
179
- # Create the video processing interface
180
  tab2 = gr.Interface(
181
  fn=predict_on_test,
182
  inputs=gr.Image(),
183
  outputs=gr.Image(),
184
- title='Images with Ground Truth',
185
  description=description,
186
  examples=sample_images
187
  )
 
14
  import io
15
 
16
  REPO_ID = "amosfang/segmentation_u_net"
 
17
 
18
  def pil_image_as_numpy_array(pilimg):
19
  img_array = tf.keras.utils.img_to_array(pilimg)
 
35
  unet_model = load_model(saved_model_filepath)
36
  return unet_model
37
 
38
+ def get_sample_images(image_folder, format=('.jpg', '.jpeg')):
39
 
40
  # Get a list of all files in the folder
41
  img_file_list = os.listdir(image_folder)
42
+ img_file_list.sort()
43
 
44
+ # Filter out only the image files (assuming images have extensions like '.jpg' or '.png')
45
+ image_files = [[image_folder +'/' + file] for file in img_file_list if file.lower().endswith(format)]
46
 
47
  return image_files
48
 
 
75
  return predicted_label_indices
76
 
77
  def predict_on_train(image):
78
+
79
  # Steps to get prediction
80
  sample_image_resized = resize_image(image)
81
  y_pred = ensemble_predict(sample_image_resized)
 
111
  return image_pil, image_pil
112
 
113
  def predict_on_test(image):
114
+
115
  # Steps to get prediction
116
  sample_image_resized = resize_image(image)
117
  y_pred = ensemble_predict(sample_image_resized)
 
148
 
149
 
150
  sample_images = get_sample_images('example_images')
151
+ train_images = get_sample_images('train_images')
152
 
153
  description= '''
154
  The DeepGlobe Land Cover Classification Challenge offers the first public dataset containing high resolution
 
170
  # examples=sample_images
171
  # ).launch(debug=True, share=True)
172
 
173
+ # Create the train dataset interface
174
  tab1 = gr.Interface(
175
  fn=predict_on_train,
176
  inputs=gr.Image(),
177
  outputs=[gr.Image(), gr.Image()],
178
  title='Images with Ground Truth',
179
  description=description,
180
+ examples=train_images
181
  )
182
 
183
+ # Create the test dataset interface
184
  tab2 = gr.Interface(
185
  fn=predict_on_test,
186
  inputs=gr.Image(),
187
  outputs=gr.Image(),
188
+ title='Images without Ground Truth',
189
  description=description,
190
  examples=sample_images
191
  )