Spaces:
Runtime error
Runtime error
Commit ·
e3652cf
1
Parent(s): 8470d99
attempt tuples
Browse files
app.py
CHANGED
|
@@ -46,9 +46,6 @@ model = load_model('unet_contrails_model.keras', custom_objects={'dice_loss_plus
|
|
| 46 |
model.compile(metrics=metrics)
|
| 47 |
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
# def greet(name):
|
| 53 |
# return "Hello " + name + "!!"
|
| 54 |
|
|
@@ -58,7 +55,7 @@ model.compile(metrics=metrics)
|
|
| 58 |
def predict(ash_image, model=model):
|
| 59 |
#label = np.load(label_image)
|
| 60 |
# ash_image = np.load('images/552609781892851211.npy')
|
| 61 |
-
ash_image = ash_image
|
| 62 |
y_pred = model.predict(ash_image.reshape(1,256, 256, 3))
|
| 63 |
prediction = np.argmax(y_pred[0], axis=2).reshape(256,256)
|
| 64 |
#intersection = label & prediction
|
|
@@ -69,8 +66,6 @@ def predict(ash_image, model=model):
|
|
| 69 |
return(ash_image, seg_info)
|
| 70 |
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
if __name__ == "__main__":
|
| 75 |
class2hexcolor = {"contrails": "#FF0000"}
|
| 76 |
|
|
@@ -78,41 +73,16 @@ if __name__ == "__main__":
|
|
| 78 |
gr.Markdown("""<h1><center>Predict Contrails in Satellite Images</center></h1>""")
|
| 79 |
with gr.Row():
|
| 80 |
img_input = gr.Image(type="numpy", height=256, width=256, label="Input image")
|
|
|
|
| 81 |
img_output = gr.AnnotatedImage(label="Predictions", height=256, width=256, color_map=class2hexcolor)
|
| 82 |
|
| 83 |
section_btn = gr.Button("Generate Predictions")
|
| 84 |
-
section_btn.click(partial(predict, model=model), img_input, img_output)
|
| 85 |
|
| 86 |
images_dir = glob(os.path.join(os.getcwd(), "images") + os.sep + "*.png")
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
demo.launch()
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
# first we need to load the model from somewhere - probably by using model.load on a keras file (which could be saved in our huggingface space repo)
|
| 95 |
-
# once we have a model, we use tensorflow to run inference and create a visualization of the output mask
|
| 96 |
-
# just like we did in our main code like such:
|
| 97 |
-
# model_name = "something.keras" (which should be saved in our HF repo)
|
| 98 |
-
# model = load_model(model_name)
|
| 99 |
-
# model.compile(?)
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
# then we save that inference + viz task in a function called "make mask" which takes an input image, processes it, runs the model on it, and returns a mask image
|
| 103 |
-
# within this function we can use functions like display_image_and_label (and the functions that that function calls to make predictions)
|
| 104 |
-
# instead of just printing the visualization, we have the function return the image output
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
#description = "<p style='text-align: center'>Gradio demo for identifying contrails in satellite images. </p>"
|
| 108 |
-
#css = "#0 {object-fit: contain;} #1 {object-fit: contain;}"
|
| 109 |
-
#demo = gr.Interface(fn=make_mask,
|
| 110 |
-
# title=title,
|
| 111 |
-
# description=description,
|
| 112 |
-
# inputs= # either the use input or one we save as a file,
|
| 113 |
-
# outputs=gr.Image(elem_id=1, show_label=False),
|
| 114 |
-
# css=css,
|
| 115 |
-
# examples=examples,
|
| 116 |
-
# cache_examples=True,
|
| 117 |
-
# allow_flagging='never')
|
| 118 |
-
#demo.launch()
|
|
|
|
| 46 |
model.compile(metrics=metrics)
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
| 49 |
# def greet(name):
|
| 50 |
# return "Hello " + name + "!!"
|
| 51 |
|
|
|
|
| 55 |
def predict(ash_image, model=model):
|
| 56 |
#label = np.load(label_image)
|
| 57 |
# ash_image = np.load('images/552609781892851211.npy')
|
| 58 |
+
ash_image = np.load(ash_image)
|
| 59 |
y_pred = model.predict(ash_image.reshape(1,256, 256, 3))
|
| 60 |
prediction = np.argmax(y_pred[0], axis=2).reshape(256,256)
|
| 61 |
#intersection = label & prediction
|
|
|
|
| 66 |
return(ash_image, seg_info)
|
| 67 |
|
| 68 |
|
|
|
|
|
|
|
| 69 |
if __name__ == "__main__":
|
| 70 |
class2hexcolor = {"contrails": "#FF0000"}
|
| 71 |
|
|
|
|
| 73 |
gr.Markdown("""<h1><center>Predict Contrails in Satellite Images</center></h1>""")
|
| 74 |
with gr.Row():
|
| 75 |
img_input = gr.Image(type="numpy", height=256, width=256, label="Input image")
|
| 76 |
+
file_input = gr.File()
|
| 77 |
img_output = gr.AnnotatedImage(label="Predictions", height=256, width=256, color_map=class2hexcolor)
|
| 78 |
|
| 79 |
section_btn = gr.Button("Generate Predictions")
|
| 80 |
+
section_btn.click(partial(predict, model=model), img_input[1], img_output)
|
| 81 |
|
| 82 |
images_dir = glob(os.path.join(os.getcwd(), "images") + os.sep + "*.png")
|
| 83 |
+
files_dir = glob(os.path.join(os.getcwd(), "numpy_files") + os.sep + "*.npy")
|
| 84 |
+
# x = (images_dir,files_dir)
|
| 85 |
+
examples = [[i for i in images_dir],[f for f in files_dir]]
|
| 86 |
+
gr.Examples(examples=examples, inputs=[img_input,file_input], outputs=img_output)
|
| 87 |
|
| 88 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|