Spaces:
Sleeping
Sleeping
ignaziogallo
commited on
Commit
•
3c2c5b7
1
Parent(s):
a563c94
resolved bug of zip uploading
Browse files- .gitignore +1 -0
- app.py +35 -20
- demo_data/1509.zip +3 -0
- utils.py +2 -3
.gitignore
CHANGED
@@ -3,3 +3,4 @@ __pycache__
|
|
3 |
uploaded_samples
|
4 |
demo_data/results
|
5 |
.idea
|
|
|
|
3 |
uploaded_samples
|
4 |
demo_data/results
|
5 |
.idea
|
6 |
+
results
|
app.py
CHANGED
@@ -113,7 +113,7 @@ st.markdown(""" Demo App for the model presented in the [paper](https://www.scie
|
|
113 |
""")
|
114 |
|
115 |
file_uploaded = st.file_uploader(
|
116 |
-
"Upload",
|
117 |
type=["zip"],
|
118 |
accept_multiple_files=False,
|
119 |
)
|
@@ -121,21 +121,29 @@ sample_path = None
|
|
121 |
tileids = None
|
122 |
if file_uploaded is not None:
|
123 |
with zipfile.ZipFile(file_uploaded, "r") as z:
|
124 |
-
z.extractall("uploaded_samples")
|
125 |
-
|
|
|
|
|
|
|
126 |
st.markdown('or use a demo sample')
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
if st.button('sample
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
paths = None
|
141 |
if sample_path is not None:
|
@@ -229,7 +237,7 @@ if sample_path is not None:
|
|
229 |
st.markdown('End prediction')
|
230 |
|
231 |
# folder_out = "demo_data/results/seg_maps/example-lombardia/2"
|
232 |
-
folder_out = os.path.join("demo_data/results/seg_maps/"+opt.years[0]+"-lombardia/", tileids[0])
|
233 |
st.paths = os.listdir(folder_out)
|
234 |
st.paths.sort()
|
235 |
|
@@ -264,7 +272,7 @@ if st.paths is not None:
|
|
264 |
st.markdown("**Legend**")
|
265 |
st.markdown(markdown_legend, unsafe_allow_html=True)
|
266 |
|
267 |
-
st.markdown("**Short-term (daily)
|
268 |
img_full_paths = [os.path.join(folder_out, path) for path in st.paths if 'daily-pred' in path]
|
269 |
pred_dates = [path[:8] for path in st.paths if 'daily-pred' in path]
|
270 |
anim = load_daily_preds_as_animations(img_full_paths, pred_dates)
|
@@ -283,6 +291,13 @@ st.markdown("""
|
|
283 |
You can download other patches from the original dataset created and published on
|
284 |
[Kaggle](https://www.kaggle.com/datasets/ignazio/sentinel2-crop-mapping) and used in our paper.
|
285 |
|
286 |
-
## How to build an input file for the Demo
|
287 |
-
|
288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
""")
|
114 |
|
115 |
file_uploaded = st.file_uploader(
|
116 |
+
"Upload a zip file containing a sample",
|
117 |
type=["zip"],
|
118 |
accept_multiple_files=False,
|
119 |
)
|
|
|
121 |
tileids = None
|
122 |
if file_uploaded is not None:
|
123 |
with zipfile.ZipFile(file_uploaded, "r") as z:
|
124 |
+
z.extractall(os.path.join("uploaded_samples", opt.years[0]))
|
125 |
+
tileids = [file_uploaded.name[:-4]]
|
126 |
+
# sample_path = os.path.join("uploaded_samples", opt.years[0], tileids[0])
|
127 |
+
sample_path = "uploaded_samples"
|
128 |
+
|
129 |
st.markdown('or use a demo sample')
|
130 |
+
col1, col2, col3, col4 = st.columns([1, 1, 1, 1])
|
131 |
+
with col1:
|
132 |
+
if st.button('sample 1'):
|
133 |
+
sample_path = 'demo_data/lombardia'
|
134 |
+
tileids = ['24']
|
135 |
+
with col2:
|
136 |
+
if st.button('sample 2'):
|
137 |
+
sample_path = 'demo_data/lombardia'
|
138 |
+
tileids = ['712']
|
139 |
+
with col3:
|
140 |
+
if st.button('sample 3'):
|
141 |
+
sample_path = 'demo_data/lombardia'
|
142 |
+
tileids = ['814']
|
143 |
+
with col4:
|
144 |
+
if st.button('sample 4'):
|
145 |
+
sample_path = 'demo_data/lombardia'
|
146 |
+
tileids = ['1509']
|
147 |
|
148 |
paths = None
|
149 |
if sample_path is not None:
|
|
|
237 |
st.markdown('End prediction')
|
238 |
|
239 |
# folder_out = "demo_data/results/seg_maps/example-lombardia/2"
|
240 |
+
folder_out = full_pth_patch # os.path.join("demo_data/results/seg_maps/"+opt.years[0]+"-lombardia/", tileids[0])
|
241 |
st.paths = os.listdir(folder_out)
|
242 |
st.paths.sort()
|
243 |
|
|
|
272 |
st.markdown("**Legend**")
|
273 |
st.markdown(markdown_legend, unsafe_allow_html=True)
|
274 |
|
275 |
+
st.markdown("**Short-term (daily) predictions**")
|
276 |
img_full_paths = [os.path.join(folder_out, path) for path in st.paths if 'daily-pred' in path]
|
277 |
pred_dates = [path[:8] for path in st.paths if 'daily-pred' in path]
|
278 |
anim = load_daily_preds_as_animations(img_full_paths, pred_dates)
|
|
|
291 |
You can download other patches from the original dataset created and published on
|
292 |
[Kaggle](https://www.kaggle.com/datasets/ignazio/sentinel2-crop-mapping) and used in our paper.
|
293 |
|
294 |
+
## How to build an input file for the Demo
|
295 |
+
You can download this [example zip](demo_data/1509.zip) to understand
|
296 |
+
how to create a new sample to feed as input to the model. A sample is a time series of sentinel-2 images,
|
297 |
+
i.e. all images acquired by the satellite during a year.
|
298 |
+
A zip file must contain
|
299 |
+
- a geoTiff image of size _9 x 48 x 48_ for each date of the time series;
|
300 |
+
- the name of each geoTif must show the date like this example "20221225.tif" which represents the date 25 December 2022;
|
301 |
+
- each image must contain all sentinel-2 bands as reported in the [paper](https://www.sciencedirect.com/science/article/pii/S0924271622003203);
|
302 |
+
- all the images inside the zip file must be placed inside a directory (see [example zip](demo_data/1509.zip)) where the name represents the name of the patch (for example "24"). )
|
303 |
+
""")
|
demo_data/1509.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4623b7598ad937e4de855e3dc0774323649b021bc4b451c39aaae577b04fbcbf
|
3 |
+
size 2462400
|
utils.py
CHANGED
@@ -32,7 +32,7 @@ def get_dates(path, n=None):
|
|
32 |
files = os.listdir(path)
|
33 |
dates = list()
|
34 |
for f in files:
|
35 |
-
f = f.split("
|
36 |
if len(f) == 8: # 20160101
|
37 |
dates.append(f)
|
38 |
|
@@ -166,7 +166,6 @@ class SentinelDailyAnnualDatasetNoLabel(torch.utils.data.Dataset):
|
|
166 |
for root_dir in self.root_dirs:
|
167 |
print("Reading dataset info:", root_dir)
|
168 |
self.name += os.path.basename(root_dir) + '_'
|
169 |
-
|
170 |
for d in self.data_dirs:
|
171 |
if not os.path.isdir(os.path.join(root_dir, d)):
|
172 |
sys.exit('The directory ' + os.path.join(root_dir, d) + " does not exist!")
|
@@ -719,7 +718,7 @@ opt.resnet_shortcut = 'B'
|
|
719 |
# opt.optimizer = 'sgd'
|
720 |
# opt.export_only
|
721 |
# opt.test_tile = 'test_small.tileids'
|
722 |
-
opt.result_path = '
|
723 |
input_data_folder = 'demo_data/lombardia' #@param {type:"string"}
|
724 |
opt.root_path = [input_data_folder]
|
725 |
opt.years = ['2019']
|
|
|
32 |
files = os.listdir(path)
|
33 |
dates = list()
|
34 |
for f in files:
|
35 |
+
f = f.split(".")[0]
|
36 |
if len(f) == 8: # 20160101
|
37 |
dates.append(f)
|
38 |
|
|
|
166 |
for root_dir in self.root_dirs:
|
167 |
print("Reading dataset info:", root_dir)
|
168 |
self.name += os.path.basename(root_dir) + '_'
|
|
|
169 |
for d in self.data_dirs:
|
170 |
if not os.path.isdir(os.path.join(root_dir, d)):
|
171 |
sys.exit('The directory ' + os.path.join(root_dir, d) + " does not exist!")
|
|
|
718 |
# opt.optimizer = 'sgd'
|
719 |
# opt.export_only
|
720 |
# opt.test_tile = 'test_small.tileids'
|
721 |
+
opt.result_path = 'results'
|
722 |
input_data_folder = 'demo_data/lombardia' #@param {type:"string"}
|
723 |
opt.root_path = [input_data_folder]
|
724 |
opt.years = ['2019']
|