Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,8 @@ TEST_FOLDER = 'example_images'
|
|
| 19 |
NUM_CLASSES = 7
|
| 20 |
|
| 21 |
def pil_image_as_numpy_array(pilimg):
|
|
|
|
|
|
|
| 22 |
img_array = tf.keras.utils.img_to_array(pilimg)
|
| 23 |
return img_array
|
| 24 |
|
|
@@ -77,17 +79,6 @@ def get_predictions(y_prediction_encoded):
|
|
| 77 |
return predicted_label_indices
|
| 78 |
|
| 79 |
def predict_on_train(image):
|
| 80 |
-
|
| 81 |
-
# Extract filename from Gradio input
|
| 82 |
-
image_filename = gr.get_data()[0].name
|
| 83 |
-
# Construct the filename for the ground truth mask
|
| 84 |
-
mask_filename = image_filename.replace('_sat.jpg', '_mask.png')
|
| 85 |
-
|
| 86 |
-
# Load the ground truth mask
|
| 87 |
-
mask_path = os.path.join(TRAIN_FOLDER, mask_filename)
|
| 88 |
-
ground_truth_mask = Image.open(mask_path)
|
| 89 |
-
# Resize the mask image
|
| 90 |
-
ground_truth_mask_pil = resize_image(ground_truth_mask)
|
| 91 |
|
| 92 |
# Steps to get prediction of the satellite image
|
| 93 |
sample_image_resized = resize_image(image)
|
|
@@ -121,7 +112,7 @@ def predict_on_train(image):
|
|
| 121 |
# Close the figure to release resources
|
| 122 |
plt.close(fig)
|
| 123 |
|
| 124 |
-
return
|
| 125 |
|
| 126 |
def predict_on_test(image):
|
| 127 |
|
|
@@ -174,15 +165,6 @@ description= '''
|
|
| 174 |
validation accuracy of about 75% and dice score of about 0.6.
|
| 175 |
'''
|
| 176 |
|
| 177 |
-
# Launch Gradio Interface (Single Tab interface)
|
| 178 |
-
# gr.Interface(
|
| 179 |
-
# predict,
|
| 180 |
-
# title='Land Cover Segmentation',
|
| 181 |
-
# inputs=[gr.Image()],
|
| 182 |
-
# outputs=[gr.Image()],
|
| 183 |
-
# examples=sample_images
|
| 184 |
-
# ).launch(debug=True, share=True)
|
| 185 |
-
|
| 186 |
# Create the train dataset interface
|
| 187 |
tab1 = gr.Interface(
|
| 188 |
fn=predict_on_train,
|
|
|
|
| 19 |
NUM_CLASSES = 7
|
| 20 |
|
| 21 |
def pil_image_as_numpy_array(pilimg):
|
| 22 |
+
|
| 23 |
+
# Convert PIL image to numpy array with Tensorflow utils function
|
| 24 |
img_array = tf.keras.utils.img_to_array(pilimg)
|
| 25 |
return img_array
|
| 26 |
|
|
|
|
| 79 |
return predicted_label_indices
|
| 80 |
|
| 81 |
def predict_on_train(image):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
# Steps to get prediction of the satellite image
|
| 84 |
sample_image_resized = resize_image(image)
|
|
|
|
| 112 |
# Close the figure to release resources
|
| 113 |
plt.close(fig)
|
| 114 |
|
| 115 |
+
return image_pil, image_pil
|
| 116 |
|
| 117 |
def predict_on_test(image):
|
| 118 |
|
|
|
|
| 165 |
validation accuracy of about 75% and dice score of about 0.6.
|
| 166 |
'''
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
# Create the train dataset interface
|
| 169 |
tab1 = gr.Interface(
|
| 170 |
fn=predict_on_train,
|