Spaces:
Running
on
Zero
Running
on
Zero
mikonvergence
commited on
Commit
·
a1c8d5a
1
Parent(s):
de3da2a
Interface cleaning + sanity check for 4 conditions
Browse files- app.py +14 -11
- src/backend.py +5 -0
app.py
CHANGED
@@ -10,16 +10,18 @@ with gr.Blocks(theme=theme) as demo:
|
|
10 |
gr.HTML('<img src="https://huggingface.co/spaces/mikonvergence/COP-GEN-Beta/resolve/main/logos/COP-GEN-logo.png" style="max-width: 300px;">')
|
11 |
gr.Markdown("# 🔵 COP-GEN-Beta: Unified Generative Modelling of COPernicus Imagery Thumbnails")
|
12 |
gr.Markdown("### Miguel Espinosa, Valerio Marsocci, Yuru Jia, Elliot J. Crowley, Mikolaj Czerkawski")
|
13 |
-
gr.
|
14 |
-
gr.Markdown('
|
|
|
15 |
|
16 |
with gr.Column(elem_classes="Main app"):
|
17 |
|
18 |
with gr.Accordion("Instructions", open=False) as abstract:
|
19 |
-
gr.Markdown("1. **Generate**: Click the `🏭 Generate` button to synthesize the output
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
|
24 |
with gr.Column():
|
25 |
generate_button = gr.Button("🏭 Generate", variant="primary")
|
@@ -32,14 +34,14 @@ with gr.Blocks(theme=theme) as demo:
|
|
32 |
dem_output = gr.Image(label="DEM (Elevation)", interactive=False)
|
33 |
|
34 |
with gr.Row():
|
35 |
-
s2l1c_reuse_button = gr.Button("Reuse S2 L1C as input ⤵️", variant="primary")
|
36 |
-
s2l2a_reuse_button = gr.Button("Reuse S2 L2A as input ⤵️", variant="primary")
|
37 |
-
s1rtc_reuse_button = gr.Button("Reuse S1 RTC as input ⤵️", variant="primary")
|
38 |
-
dem_reuse_button = gr.Button("Reuse DEM as input ⤵️", variant="primary")
|
39 |
|
40 |
gr.Markdown("---")
|
41 |
with gr.Row():
|
42 |
-
gr.Markdown("## Input Conditions
|
43 |
load_button = gr.Button("🔄 Load a random sample from Major TOM 🗺", variant="secondary")
|
44 |
with gr.Row():
|
45 |
s2l1c_input = gr.Image(label="S2 L1C (Optical - Top of Atmosphere)", interactive=True)
|
@@ -55,6 +57,7 @@ with gr.Blocks(theme=theme) as demo:
|
|
55 |
seed_checkbox = gr.Checkbox(value=True, label="Random")
|
56 |
|
57 |
with gr.Accordion("Abstract", open=False) as abstract:
|
|
|
58 |
gr.Markdown("In remote sensing, multi-modal data from various sensors capturing the same scene offers rich opportunities, but learning a unified representation across these modalities remains a significant challenge. Traditional methods have often been limited to single or dual-modality approaches. In this paper, we introduce COP-GEN-Beta, a generative diffusion model trained on optical, radar, and elevation data from the Major TOM dataset. What sets COP-GEN-Beta apart is its ability to map any subset of modalities to any other, enabling zero-shot modality translation after training. This is achieved through a sequence-based diffusion transformer, where each modality is controlled by its own timestep embedding. We extensively evaluate COP-GEN-Beta on thumbnail images from the Major TOM dataset, demonstrating its effectiveness in generating high-quality samples. Qualitative and quantitative evaluations validate the model's performance, highlighting its potential as a powerful pre-trained model for future remote sensing tasks.")
|
59 |
|
60 |
load_button.click(
|
|
|
10 |
gr.HTML('<img src="https://huggingface.co/spaces/mikonvergence/COP-GEN-Beta/resolve/main/logos/COP-GEN-logo.png" style="max-width: 300px;">')
|
11 |
gr.Markdown("# 🔵 COP-GEN-Beta: Unified Generative Modelling of COPernicus Imagery Thumbnails")
|
12 |
gr.Markdown("### Miguel Espinosa, Valerio Marsocci, Yuru Jia, Elliot J. Crowley, Mikolaj Czerkawski")
|
13 |
+
gr.HTML('<a href="https://github.com/miquel-espinosa/COP-GEN-Beta" class="text-decoration-none site-link"><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/miquel-espinosa/COP-GEN-Beta"></a>')
|
14 |
+
#gr.Markdown('[[Website](https://miquel-espinosa.github.io/cop-gen-beta/)] [GitHub](https://github.com/miquel-espinosa/COP-GEN-Beta)] [[Model](https://huggingface.co/mespinosami/COP-GEN-Beta) [[Dataset](https://huggingface.co/Major-TOM)]')
|
15 |
+
gr.Markdown('> ## ⚠️ NOTE: This is a prototype Beta model of COP-GEN. It is based on image thumbnails of [Major TOM](https://huggingface.co/Major-TOM) and does not yet support raw source data. The hillshade visualisation is used for elevation. The full model COP-GEN is coming soon.')
|
16 |
|
17 |
with gr.Column(elem_classes="Main app"):
|
18 |
|
19 |
with gr.Accordion("Instructions", open=False) as abstract:
|
20 |
+
gr.Markdown("1. **Generate**: Click the `🏭 Generate` button to synthesize the output **without any conditions**. The outputs will be shown below - and that's it, you've generated your first sample! 🧑🎨️"+
|
21 |
+
"<br/>2. **Optionally, define input**: If you want to condition your generation, you can upload your thumbnails manually or you can `🔄 Load` a random sample from Major TOM by clicking the button."+
|
22 |
+
"<br/>3. **Select conditions**: Each input image can be used as a **conditioning** when it's loaded into the inputs panel. The modalities you wish to generate should have no content in the input panel (you can empty each element by clicking `x` in the top right corner of the image)."+
|
23 |
+
"<br/>4. **Additional Options**: You can control the number of generation steps (higher number might produce better quality, but will take more time), or set a fixed seed (for reproducible results)."+
|
24 |
+
"<br/>5. You can also reuse any of the generated samples as input to the model by clicking `♻️ Reuse`")
|
25 |
|
26 |
with gr.Column():
|
27 |
generate_button = gr.Button("🏭 Generate", variant="primary")
|
|
|
34 |
dem_output = gr.Image(label="DEM (Elevation)", interactive=False)
|
35 |
|
36 |
with gr.Row():
|
37 |
+
s2l1c_reuse_button = gr.Button("♻️ Reuse S2 L1C as input ⤵️", variant="primary")
|
38 |
+
s2l2a_reuse_button = gr.Button("♻️ Reuse S2 L2A as input ⤵️", variant="primary")
|
39 |
+
s1rtc_reuse_button = gr.Button("♻️ Reuse S1 RTC as input ⤵️", variant="primary")
|
40 |
+
dem_reuse_button = gr.Button("♻️ Reuse DEM as input ⤵️", variant="primary")
|
41 |
|
42 |
gr.Markdown("---")
|
43 |
with gr.Row():
|
44 |
+
gr.Markdown("## (Optional) Input Conditions")
|
45 |
load_button = gr.Button("🔄 Load a random sample from Major TOM 🗺", variant="secondary")
|
46 |
with gr.Row():
|
47 |
s2l1c_input = gr.Image(label="S2 L1C (Optical - Top of Atmosphere)", interactive=True)
|
|
|
57 |
seed_checkbox = gr.Checkbox(value=True, label="Random")
|
58 |
|
59 |
with gr.Accordion("Abstract", open=False) as abstract:
|
60 |
+
gr.HTML('<a href="https://arxiv.org/abs/2504.08548/" class="text-decoration-none site-link"><img alt="Arxiv Link" src="https://img.shields.io/badge/Open_Access-arxiv:2504.08548-b31b1b"></a>')
|
61 |
gr.Markdown("In remote sensing, multi-modal data from various sensors capturing the same scene offers rich opportunities, but learning a unified representation across these modalities remains a significant challenge. Traditional methods have often been limited to single or dual-modality approaches. In this paper, we introduce COP-GEN-Beta, a generative diffusion model trained on optical, radar, and elevation data from the Major TOM dataset. What sets COP-GEN-Beta apart is its ability to map any subset of modalities to any other, enabling zero-shot modality translation after training. This is achieved through a sequence-based diffusion transformer, where each modality is controlled by its own timestep embedding. We extensively evaluate COP-GEN-Beta on thumbnail images from the Major TOM dataset, demonstrating its effectiveness in generating high-quality samples. Qualitative and quantitative evaluations validate the model's performance, highlighting its potential as a powerful pre-trained model for future remote sensing tasks.")
|
62 |
|
63 |
load_button.click(
|
src/backend.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
import torch
|
3 |
import spaces
|
|
|
4 |
import numpy as np
|
5 |
from PIL import Image
|
6 |
import ml_collections
|
@@ -237,6 +238,10 @@ def generate_output(s2l1c_input, s2l2a_input, s1rtc_input, dem_input, num_infere
|
|
237 |
s1rtc_active = s1rtc_input is not None
|
238 |
dem_active = dem_input is not None
|
239 |
|
|
|
|
|
|
|
|
|
240 |
images=[]
|
241 |
condition_modalities=[]
|
242 |
if s2l2a_active:
|
|
|
1 |
import os
|
2 |
import torch
|
3 |
import spaces
|
4 |
+
import gradio as gr
|
5 |
import numpy as np
|
6 |
from PIL import Image
|
7 |
import ml_collections
|
|
|
238 |
s1rtc_active = s1rtc_input is not None
|
239 |
dem_active = dem_input is not None
|
240 |
|
241 |
+
if s2l2a_active and s2l1c_active and s1rtc_active and dem_active:
|
242 |
+
gr.Warning("You need to remove some of the inputs that you would like to generate. If all modalities are known, there is nothing to generate.")
|
243 |
+
return s2l2a_input, s2l1c_input, s1rtc_input, dem_input
|
244 |
+
|
245 |
images=[]
|
246 |
condition_modalities=[]
|
247 |
if s2l2a_active:
|