Spaces:
Paused
Paused
Upload folder using huggingface_hub (part 3)
Browse files- .gitattributes +3 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/LICENSE +201 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/README.md +575 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/configs/train/config_task.yaml +58 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/csv/FLAIR-HUB_FULL.zip +3 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/csv/FLAIR-HUB_TOY.zip +3 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/flair-hub-HF-dl.py +849 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/imgs/flair_bandeau.jpg +3 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/setup.py +55 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/__init__.py +0 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/data/dataloader.py +258 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/data/datamodule.py +125 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/main.py +60 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/tasks/stages.py +101 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/tasks/trainers.py +130 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/utils/config_io.py +77 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/utils/messaging.py +114 -0
- models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_zonal_detection/main.py +14 -0
- models/satquery_water_bundle/MODEL_CARD.md +11 -0
- models/satquery_water_bundle/satquery_model_health.json +27 -0
- models/satquery_water_bundle/satquery_water_config.json +68 -0
- models/satquery_water_bundle/satquery_water_metrics.json +40 -0
- models/satquery_water_bundle/satquery_water_state_dict.pt +3 -0
- models/satquery_water_bundle/thresholds.json +5 -0
- models/water/s2-water-unetplusplus-efficientnet-b4/config.json +9 -0
- models/water/s2-water-unetplusplus-efficientnet-b4/model.pth +3 -0
.gitattributes
CHANGED
|
@@ -7,3 +7,6 @@ models/finetuned/landcover/satquery_landcover_v1/confusion_matrix.png filter=lfs
|
|
| 7 |
models/finetuned/landcover/satquery_landcover_v1/qualitative_overlays.png filter=lfs diff=lfs merge=lfs -text
|
| 8 |
models/land_cover/flair-rgb-15cl-deeplabv3/confmat.npy filter=lfs diff=lfs merge=lfs -text
|
| 9 |
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/model_utils/AerialROI.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
models/finetuned/landcover/satquery_landcover_v1/qualitative_overlays.png filter=lfs diff=lfs merge=lfs -text
|
| 8 |
models/land_cover/flair-rgb-15cl-deeplabv3/confmat.npy filter=lfs diff=lfs merge=lfs -text
|
| 9 |
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/model_utils/AerialROI.png filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/csv/FLAIR-HUB_FULL.zip filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/csv/FLAIR-HUB_TOY.zip filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/imgs/flair_bandeau.jpg filter=lfs diff=lfs merge=lfs -text
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/README.md
ADDED
|
@@ -0,0 +1,575 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div align="center">
|
| 2 |
+
|
| 3 |
+
# FLAIR-HUB
|
| 4 |
+
# Multimodal & multitask semantic segmentation of Earth Observation imagery
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
 [](https://github.com/IGNF/FLAIR-HUB/blob/master/LICENSE) <a href="https://pytorch.org/get-started/locally/"><img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-ee4c2c?logo=pytorch&logoColor=white"></a>
|
| 8 |
+
<a href="https://pytorchlightning.ai/"><img alt="Lightning" src="https://img.shields.io/badge/-Lightning-792ee5?logo=pytorchlightning&logoColor=white"></a>    [](https://github.com/etalab/licence-ouverte/blob/master/open-licence.md)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Participate in obtaining more accurate maps for a more comprehensive description and a better understanding of our environment! Come push the limits of state-of-the-art semantic segmentation approaches on a large and challenging dataset. <br> Get in touch at :email: flair@ign.fr
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+

|
| 18 |
+
|
| 19 |
+
</div>
|
| 20 |
+
|
| 21 |
+
<div style="border-width:1px; border-style:solid; border-color:#d2db8c; padding-left: 1em; padding-right: 1em; ">
|
| 22 |
+
|
| 23 |
+
<h2 style="margin-top:5px;">:mag_right:Quicklinks</h2>
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
- **Entry page :** [Overall FLAIR-HUB page](https://ignf.github.io/FLAIR/FLAIR-HUB/flairhub.html) <br>
|
| 27 |
+
|
| 28 |
+
- **Datapaper :** [ISPRS Journal](https://www.sciencedirect.com/science/article/pii/S0924271626001899) / [arXiv Preprint](https://arxiv.org/abs/2506.07080)
|
| 29 |
+
|
| 30 |
+
- **Dataset links :** [Dataset link](https://huggingface.co/datasets/IGNF/FLAIR-HUB)
|
| 31 |
+
|
| 32 |
+
- **Pre-trained models :** [Pretrained models](https://huggingface.co/collections/IGNF/flair-models-684035e78bd5bff99199ff87)
|
| 33 |
+
|
| 34 |
+
- **Toy Datatset direct downlaod** [Dataset link](https://storage.gra.cloud.ovh.net/v1/AUTH_366279ce616242ebb14161b7991a8461/defi-ia/flair_hub/FLAIR-HUB_TOY_DATASET.zip)
|
| 35 |
+
|
| 36 |
+
</div>
|
| 37 |
+
<hr>
|
| 38 |
+
|
| 39 |
+
## Context and data
|
| 40 |
+
|
| 41 |
+
This repository is built on top of the **FLAIR-HUB** dataset, the largest multi-sensor land cover dataset with very-high-resolution (20\:cm) annotations, covering 2528\:km² of France. It combines six aligned modalities: aerial imagery, Sentinel-1/2 time series, SPOT imagery, topographic data, and historical aerial images. Extensive benchmarks evaluate multimodal fusion and deep learning models (CNNs, transformers) for land cover or crop mapping and also explore multi-task learning. Key figures of the dataset are : <br>
|
| 42 |
+
|
| 43 |
+
<center>
|
| 44 |
+
<table style="width:95%;max-width:600px;">
|
| 45 |
+
|
| 46 |
+
<tbody>
|
| 47 |
+
<tr><td>🗺️</td><td>ROI / Area Covered</td><td style="text-align: center">2,822 ROIs / 2,528 km²</td></tr>
|
| 48 |
+
<tr><td>🏛️</td><td>Departments (France)</td><td style="text-align: center">74</td></tr>
|
| 49 |
+
<tr><td>🧩</td><td>AI Patches (512×512 px)</td><td style="text-align: center">241,100</td></tr>
|
| 50 |
+
<tr><td>🖼️</td><td>Annotated Pixels</td><td style="text-align: center">63.2 billion</td></tr>
|
| 51 |
+
<tr><td>🛰️</td><td>Sentinel-2 Acquisitions</td><td style="text-align: center">256,221</td></tr>
|
| 52 |
+
<tr><td>📡</td><td>Sentinel-1 Acquisitions</td><td style="text-align: center">532,696</td></tr>
|
| 53 |
+
<tr><td>📁</td><td>Total Files</td><td style="text-align: center">~2.5 million</td></tr>
|
| 54 |
+
<tr><td>💾</td><td>Total Dataset Size</td><td style="text-align: center">~750 GB</td></tr>
|
| 55 |
+
</tbody>
|
| 56 |
+
</table>
|
| 57 |
+
</center>
|
| 58 |
+
|
| 59 |
+
<hr>
|
| 60 |
+
<br><br>
|
| 61 |
+
|
| 62 |
+
## Installation
|
| 63 |
+
|
| 64 |
+
1. Conda env
|
| 65 |
+
```
|
| 66 |
+
$ conda create -n FLAIRHUB python=3.11 pip -y
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
2. Force torch with GPU support
|
| 70 |
+
```
|
| 71 |
+
$ conda activate FLAIRHUB
|
| 72 |
+
$ pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --extra-index-url https://download.pytorch.org/whl/cu126
|
| 73 |
+
```
|
| 74 |
+
3. Install flair-hub
|
| 75 |
+
```
|
| 76 |
+
$ pip install -e .
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
<hr>
|
| 80 |
+
<br><br>
|
| 81 |
+
|
| 82 |
+
## Entry points :mag_right:
|
| 83 |
+
|
| 84 |
+
flair-hub has two entry points:
|
| 85 |
+
|
| 86 |
+
#### :file_folder: src/flair_hub --> used to train, infer models, calculate metrics, at the patch level. <br>
|
| 87 |
+
```
|
| 88 |
+
$ flairhub --config /path/configs/train/
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
#### :file_folder: src/flair_zonal_detection --> used to infer a pretrained model over larger areas. <br>
|
| 92 |
+
```
|
| 93 |
+
$ flairhub_zonal --config /path/configs/config_zonal_detection.yaml
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
<hr>
|
| 98 |
+
<br><br>
|
| 99 |
+
|
| 100 |
+
## Configuration for flair-hub :page_facing_up:
|
| 101 |
+
|
| 102 |
+
The pipeline takes as input a folder with 4 configuration YAML files or a single YAML file contaning all arguments. The configuration file includes sections for data paths, tasks, supervision, model configuration, hyperparameters and computational resources.
|
| 103 |
+
|
| 104 |
+
#### config_task.yaml : <br>
|
| 105 |
+
```yaml
|
| 106 |
+
paths:
|
| 107 |
+
out_folder: Directory to store all output results (models, logs, predictions).
|
| 108 |
+
out_model_name: Name identifier for the saved model.
|
| 109 |
+
train_csv: CSV files containing paths and labels for training datasets.
|
| 110 |
+
val_csv: CSV files containing paths and labels for validation datasets.
|
| 111 |
+
test_csv: CSV files containing paths and labels for test datasets.
|
| 112 |
+
global_mtd_folder: Path to folder with global metadata required for processing.
|
| 113 |
+
ckpt_model_path: Path to a pretrained model checkpoint to initialize weights.
|
| 114 |
+
|
| 115 |
+
tasks:
|
| 116 |
+
train: Enable or disable training phase.
|
| 117 |
+
train_tasks:
|
| 118 |
+
init_weights_only_from_ckpt: Use checkpoint weights for initialization only (no training resume).
|
| 119 |
+
resume_training_from_ckpt: Resume training from the provided checkpoint.
|
| 120 |
+
predict: Run model inference on test set.
|
| 121 |
+
write_files: Save predictions and outputs to disk.
|
| 122 |
+
georeferencing_output: Apply georeferencing to output files.
|
| 123 |
+
metrics_only: Compute and report metrics without running training or prediction.
|
| 124 |
+
|
| 125 |
+
hyperparams:
|
| 126 |
+
num_epochs: Total number of training epochs.
|
| 127 |
+
batch_size: Number of samples per training batch.
|
| 128 |
+
seed: Random seed for reproducibility.
|
| 129 |
+
learning_rate: Initial learning rate for optimizer.
|
| 130 |
+
optimizer: Choice of optimizer (adamw, adam, or sgd).
|
| 131 |
+
optim_weight_decay: Weight decay regularization.
|
| 132 |
+
optim_betas: Beta coefficients for Adam-based optimizers.
|
| 133 |
+
scheduler: Learning rate scheduler strategy.
|
| 134 |
+
warmup_fraction: Warm-up fraction for one_cycle_lr.
|
| 135 |
+
plateau_patience: Patience for reduce_on_plateau scheduler.
|
| 136 |
+
|
| 137 |
+
hardware:
|
| 138 |
+
accelerator: Type of hardware to use (gpu, cpu).
|
| 139 |
+
num_nodes: Number of nodes for distributed training.
|
| 140 |
+
gpus_per_node: GPUs used per node.
|
| 141 |
+
strategy: Distributed training strategy (e.g., auto, ddp).
|
| 142 |
+
num_workers: Number of data loading workers.
|
| 143 |
+
|
| 144 |
+
saving:
|
| 145 |
+
ckpt_save_also_last: Save the final model checkpoint at the end of training.
|
| 146 |
+
ckpt_weights_only: Save only the model weights (not optimizer or scheduler).
|
| 147 |
+
ckpt_monitor: Metric used to determine the best checkpoint.
|
| 148 |
+
ckpt_monitor_mode: Direction to optimize the monitored metric (max or min).
|
| 149 |
+
ckpt_earlystopping_patience: Epochs to wait for improvement before stopping.
|
| 150 |
+
cp_csv_and_conf_to_output: Copy configuration and CSV files to output directory.
|
| 151 |
+
enable_progress_bar: Show training progress bar.
|
| 152 |
+
progress_rate: Update frequency of progress bar (in steps).
|
| 153 |
+
ckpt_verbose: Print detailed checkpoint saving information.
|
| 154 |
+
verbose_config: Print full config details to console.
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
#### config_modalities.yaml : <br>
|
| 158 |
+
```yaml
|
| 159 |
+
modalities:
|
| 160 |
+
|
| 161 |
+
inputs:
|
| 162 |
+
AERIAL_RGBI : Enable/disable AERIAL_RGBI modality. [True/False]
|
| 163 |
+
AERIAL-RLT_PAN : [True/False]
|
| 164 |
+
DEM_ELEV : [True/False]
|
| 165 |
+
SPOT_RGBI : [True/False]
|
| 166 |
+
SENTINEL2_TS : [True/False].
|
| 167 |
+
SENTINEL1-ASC_TS : [True/False]
|
| 168 |
+
SENTINEL1-DESC_TS : [True/False]
|
| 169 |
+
|
| 170 |
+
inputs_channels:
|
| 171 |
+
AERIAL_RGBI : Selected channels for AERIAL_RGBI input. Starts at 1.
|
| 172 |
+
SPOT_RGBI : Selected channels for SPOT_RGBI input. Starts at 1.
|
| 173 |
+
SENTINEL2_TS : Selected channels for Sentinel-2 time series. Starts at 1.
|
| 174 |
+
SENTINEL1-ASC_TS : Selected channels for Sentinel-1 ascending time series. Starts at 1.
|
| 175 |
+
SENTINEL1-DESC_TS : Selected channels for Sentinel-1 descending time series. Starts at 1.
|
| 176 |
+
|
| 177 |
+
aux_loss:
|
| 178 |
+
AERIAL_RGBI : Apply auxiliary loss to AERIAL_RGBI input if mutliple modalities. [True/False]
|
| 179 |
+
AERIAL-RLT_PAN : [True/False]
|
| 180 |
+
DEM_ELEV : [True/False]
|
| 181 |
+
SPOT_RGBI : [True/False]
|
| 182 |
+
SENTINEL2_TS : [True/False]
|
| 183 |
+
SENTINEL1-ASC_TS : [True/False]
|
| 184 |
+
SENTINEL1-DESC_TS : [True/False]
|
| 185 |
+
|
| 186 |
+
aux_loss_weight: Multiplier for auxiliary loss before combining with main loss. Default 1.
|
| 187 |
+
modality_dropout: Dropout probability per modality (0 = keep all, 1 = drop all systematically).
|
| 188 |
+
AERIAL_RGBI : 0
|
| 189 |
+
AERIAL-RLT_PAN : 0
|
| 190 |
+
|
| 191 |
+
pre_processings:
|
| 192 |
+
filter_sentinel2: Enable filtering of Sentinel-2 based on masks.
|
| 193 |
+
filter_sentinel2_max_cloud : Max acceptable cloud cover in Sentinel-2 [%]. Default 1.
|
| 194 |
+
filter_sentinel2_max_snow : Max acceptable snow cover in Sentinel-2 [%]. Default 1.
|
| 195 |
+
filter_sentinel2_max_frac_cover : Max acceptable fractional invalid coverage in Sentinel-2. Default 0.05.
|
| 196 |
+
temporal_average_sentinel2 : Temporal averaging method for Sentinel-2 (False/monthly/semi-monthly).
|
| 197 |
+
temporal_average_sentinel1 : Temporal averaging method for Sentinel-1 (False/monthly/semi-monthly).
|
| 198 |
+
calc_elevation : Enable calculation oF DTM-DSM.
|
| 199 |
+
calc_elevation_stack_dsm : Stack DSM if elevation calculated.
|
| 200 |
+
use_augmentation: Enable data augmentation for training. Default False.
|
| 201 |
+
|
| 202 |
+
normalization:
|
| 203 |
+
norm_type : Normalization strategy (custom, scaling, without).
|
| 204 |
+
AERIAL_RGBI_means : Mean values used to normalize AERIAL_RGBI input if custom.
|
| 205 |
+
AERIAL_RGBI_stds : Std. dev. values used to normalize AERIAL_RGBI input if custom.
|
| 206 |
+
AERIAL-RLT_PAN_means : Mean values for AERIAL-RLT_PAN input if custom.
|
| 207 |
+
AERIAL-RLT_PAN_stds : Std. dev. values for AERIAL-RLT_PAN input if custom.
|
| 208 |
+
SPOT_RGBI_means : Mean values for SPOT_RGBI input if custom.
|
| 209 |
+
SPOT_RGBI_stds : Std. dev. values for SPOT_RGBI input if custom.
|
| 210 |
+
DEM_ELEV_means : Mean elevation values (DSM, DTM) if custom.
|
| 211 |
+
DEM_ELEV_stds : Std. dev. of elevation values (DSM, DTM) if custom.
|
| 212 |
+
```
|
| 213 |
+
|
| 214 |
+
#### config_models.yaml : <br>
|
| 215 |
+
```yaml
|
| 216 |
+
models:
|
| 217 |
+
|
| 218 |
+
monotemp_model: # Encoder-decoder architecture for single-date (monotemporal) inputs
|
| 219 |
+
|
| 220 |
+
arch: Encoder-decoder architecture from SMP. Eg, swin_tiny_patch4_window7_224-upernet
|
| 221 |
+
new_channels_init_mode: Strategy to initialize new input channels if above 3 channels (options: copy_first, copy_second, copy_third, random).
|
| 222 |
+
|
| 223 |
+
multitemp_model: # Architecture for handling multi-temporal (time series) inputs
|
| 224 |
+
|
| 225 |
+
ref_date: Reference date (MM-DD) for temporal position encoding.
|
| 226 |
+
encoder_widths: Channel sizes at each stage in the encoder; must match decoder.
|
| 227 |
+
decoder_widths: Channel sizes at each stage in the decoder; must match encoder.
|
| 228 |
+
out_conv: Output convolutional layer configuration [intermediate_channels, num_classes].
|
| 229 |
+
str_conv_k: Kernel size for structured convolutions.
|
| 230 |
+
str_conv_s: Stride for structured convolutions.
|
| 231 |
+
str_conv_p: Padding for structured convolutions.
|
| 232 |
+
agg_mode: Aggregation method for temporal features (e.g., att_group).
|
| 233 |
+
encoder_norm: Normalization type used in the encoder (e.g., group).
|
| 234 |
+
n_head: Number of attention heads in the model.
|
| 235 |
+
d_model: Dimensionality of the model features.
|
| 236 |
+
d_k: Key dimensionality for attention mechanism.
|
| 237 |
+
pad_value: Value used for padding missing temporal data.
|
| 238 |
+
padding_mode: Type of padding used in convolutions (e.g., reflect).
|
| 239 |
+
```
|
| 240 |
+
|
| 241 |
+
#### config_supervision.yaml : <br>
|
| 242 |
+
```yaml
|
| 243 |
+
labels: # List of tasks
|
| 244 |
+
- AERIAL_LABEL-COSIA
|
| 245 |
+
- ALL_LABEL-LPIS
|
| 246 |
+
|
| 247 |
+
labels_configs:
|
| 248 |
+
|
| 249 |
+
AERIAL_LABEL-COSIA:
|
| 250 |
+
task_weight: Weight assigned to this task during multi-task training. Default 1.
|
| 251 |
+
value_name: Mapping of class indices to semantic category names.
|
| 252 |
+
0 : 'building'
|
| 253 |
+
1 : 'greenhouse'
|
| 254 |
+
2 : 'swimming_pool'
|
| 255 |
+
3 : 'impervious surface'
|
| 256 |
+
4 : 'pervious surface'
|
| 257 |
+
5 : 'bare soil'
|
| 258 |
+
6 : 'water'
|
| 259 |
+
7 : 'snow'
|
| 260 |
+
8 : 'herbaceous vegetation'
|
| 261 |
+
9 : 'agricultural land'
|
| 262 |
+
10 : 'plowed land'
|
| 263 |
+
11 : 'vineyard'
|
| 264 |
+
12 : 'deciduous'
|
| 265 |
+
13 : 'coniferous'
|
| 266 |
+
14 : 'brushwood'
|
| 267 |
+
15 : 'clear cut'
|
| 268 |
+
16 : 'ligneous'
|
| 269 |
+
17 : 'mixed'
|
| 270 |
+
18 : 'undefined'
|
| 271 |
+
value_weights:
|
| 272 |
+
default: Default weight for all classes (used in loss calculation). Default 1.
|
| 273 |
+
default_exceptions: Specific class indices assigned 0 weight (ignored).
|
| 274 |
+
15: 0
|
| 275 |
+
16: 0
|
| 276 |
+
17: 0
|
| 277 |
+
18: 0
|
| 278 |
+
per_modality_exceptions: Placeholder for setting modality-specific class weights.
|
| 279 |
+
AERIAL_RGBI:
|
| 280 |
+
18: 0
|
| 281 |
+
|
| 282 |
+
ALL_LABEL-LPIS:
|
| 283 |
+
task_weight: Weight assigned to this task during multi-task training.
|
| 284 |
+
label_channel_nomenclature: Index of the label channel used.
|
| 285 |
+
value_name: Mapping of class indices to crop type names.
|
| 286 |
+
value_weights:
|
| 287 |
+
default: Default class weight for the entire label set.
|
| 288 |
+
default_exceptions: No exception weights defined (can be added).
|
| 289 |
+
per_modality_exceptions: Placeholder for modality-specific class weight overrides.
|
| 290 |
+
```
|
| 291 |
+
<br><br>
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
### Configuration for flair_zonal_detection :page_facing_up:
|
| 295 |
+
|
| 296 |
+
#### config_zonal_detection.yaml : <br>
|
| 297 |
+
```yaml
|
| 298 |
+
# ======================
|
| 299 |
+
# I/O
|
| 300 |
+
# ======================
|
| 301 |
+
output_path: Path to store output results.
|
| 302 |
+
output_name: Identifier name for the output files.
|
| 303 |
+
|
| 304 |
+
write_dataframe: Whether to write slicing geometries of input area. [True/False]
|
| 305 |
+
output_type: Format of the output predictions (argmax or class_prob).
|
| 306 |
+
cog_conversion: Convert outputs to Cloud-Optimized GeoTIFF format. [True/False]
|
| 307 |
+
|
| 308 |
+
# ======================
|
| 309 |
+
# Model & Inference
|
| 310 |
+
# ======================
|
| 311 |
+
model_weights: Path to pretrained model weights for inference. [.safetensors / .ckpt / .pth]
|
| 312 |
+
use_gpu: Whether to use GPU for inference.
|
| 313 |
+
batch_size: Number of samples per inference batch.
|
| 314 |
+
num_worker: Number of data loading workers during inference.
|
| 315 |
+
|
| 316 |
+
img_pixels_detection: Size of input image chunks in pixels.
|
| 317 |
+
margin: Overlap margin (in pixels) between tiles.
|
| 318 |
+
output_px_meters: Output resolution in meters per pixel.
|
| 319 |
+
|
| 320 |
+
# ======================
|
| 321 |
+
# Model Framework
|
| 322 |
+
# ======================
|
| 323 |
+
monotemp_arch: SMP Architecture used for monotemporal inference. Eg., swin_base_patch4_window12_384-upernet
|
| 324 |
+
multitemp_model_ref_date: Reference date (MM-DD) for aligning multi-temporal inputs.
|
| 325 |
+
|
| 326 |
+
# ======================
|
| 327 |
+
# Modalities (inputs used for inference)
|
| 328 |
+
# ======================
|
| 329 |
+
modalities:
|
| 330 |
+
|
| 331 |
+
inputs:
|
| 332 |
+
AERIAL_RGBI : Enable AERIAL_RGBI input. [True / False]
|
| 333 |
+
AERIAL-RLT_PAN : [True / False]
|
| 334 |
+
DEM_ELEV : [True / False]
|
| 335 |
+
SPOT_RGBI : [True / False]
|
| 336 |
+
SENTINEL2_TS : [True / False]
|
| 337 |
+
SENTINEL1-ASC_TS : [True / False]
|
| 338 |
+
SENTINEL1-DESC_TS : [True / False]
|
| 339 |
+
|
| 340 |
+
AERIAL_RGBI:
|
| 341 |
+
input_img_path: Path to AERIAL_RGBI input image.
|
| 342 |
+
channels: Channels used from the input image. Starts at 1.
|
| 343 |
+
normalization:
|
| 344 |
+
type: Normalization method (e.g., custom).
|
| 345 |
+
means: Per-channel mean for normalization.
|
| 346 |
+
stds: Per-channel standard deviation for normalization.
|
| 347 |
+
|
| 348 |
+
AERIAL-RLT_PAN:
|
| 349 |
+
input_img_path: Path to AERIAL-RLT_PAN input.
|
| 350 |
+
channels: Channels used.
|
| 351 |
+
normalization:
|
| 352 |
+
type: Normalization method.
|
| 353 |
+
means: Mean value.
|
| 354 |
+
stds: Standard deviation.
|
| 355 |
+
|
| 356 |
+
DEM_ELEV:
|
| 357 |
+
input_img_path: Path to DEM input.
|
| 358 |
+
channels: Channels used.
|
| 359 |
+
normalization:
|
| 360 |
+
type: Normalization method.
|
| 361 |
+
means: Per-channel mean.
|
| 362 |
+
stds: Per-channel standard deviation.
|
| 363 |
+
calc_elevation: Whether to compute elevation from DSM/DTM.
|
| 364 |
+
calc_elevation_stack_dsm: Stack derived DSM with the input.
|
| 365 |
+
|
| 366 |
+
SPOT_RGBI:
|
| 367 |
+
input_img_path: Path to SPOT imagery input.
|
| 368 |
+
channels: Channels used.
|
| 369 |
+
normalization:
|
| 370 |
+
type: Normalization method.
|
| 371 |
+
means: Per-channel mean.
|
| 372 |
+
stds: Per-channel standard deviation.
|
| 373 |
+
|
| 374 |
+
SENTINEL2_TS:
|
| 375 |
+
input_img_path: Path to Sentinel-2 time series input.
|
| 376 |
+
channels: Channels used.
|
| 377 |
+
dates_txt: Path to text file listing image dates.
|
| 378 |
+
filter_clouds: Enable cloud filtering.
|
| 379 |
+
filter_clouds_img_path: Path to Sentinel-2 cloud mask.
|
| 380 |
+
temporal_average: Whether to average the time series over time.
|
| 381 |
+
|
| 382 |
+
SENTINEL1-ASC_TS:
|
| 383 |
+
input_img_path: Path to Sentinel-1 ascending orbit input.
|
| 384 |
+
channels: Channels used.
|
| 385 |
+
dates_txt: Path to date list (optional).
|
| 386 |
+
temporal_average: Whether to average over time.
|
| 387 |
+
|
| 388 |
+
SENTINEL1-DESC_TS:
|
| 389 |
+
input_img_path: Path to Sentinel-1 descending orbit input.
|
| 390 |
+
channels: Channels used.
|
| 391 |
+
dates_txt: Path to date list (optional).
|
| 392 |
+
temporal_average: Whether to average over time.
|
| 393 |
+
|
| 394 |
+
# ======================
|
| 395 |
+
# Tasks
|
| 396 |
+
# ======================
|
| 397 |
+
tasks:
|
| 398 |
+
|
| 399 |
+
- name: AERIAL_LABEL-COSIA # Semantic segmentation label task (land cover classes)
|
| 400 |
+
active: Whether to activate this label set during inference. [True / False]
|
| 401 |
+
class_names: Mapping of class indices to category names.
|
| 402 |
+
0: building
|
| 403 |
+
1: greenhouse
|
| 404 |
+
2: swimming_pool
|
| 405 |
+
3: impervious surface
|
| 406 |
+
4: pervious surface
|
| 407 |
+
5: bare soil
|
| 408 |
+
6: water
|
| 409 |
+
7: snow
|
| 410 |
+
8: herbaceous vegetation
|
| 411 |
+
9: agricultural land
|
| 412 |
+
10: plowed land
|
| 413 |
+
11: vineyard
|
| 414 |
+
12: deciduous
|
| 415 |
+
13: coniferous
|
| 416 |
+
14: brushwood
|
| 417 |
+
15: clear cut
|
| 418 |
+
16: ligneous
|
| 419 |
+
17: mixed
|
| 420 |
+
18: undefined
|
| 421 |
+
|
| 422 |
+
- name: ALL_LABEL-LPIS # Crop type classification label task
|
| 423 |
+
active: Whether to activate this label set during inference. [True / False]
|
| 424 |
+
class_names: Mapping of class indices to crop categories.
|
| 425 |
+
```
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
<hr>
|
| 430 |
+
|
| 431 |
+
<br><br>
|
| 432 |
+
|
| 433 |
+
## Baseline results
|
| 434 |
+
|
| 435 |
+
| Model ID | Aerial VHR | Elevation | SPOT | S2 t.s. | S1 t.s. | Historical | PARA. | O.A. | mIoU |
|
| 436 |
+
|----------|------------|-----------|------|---------|---------|------------|--------|------|------|
|
| 437 |
+
|||||||||||
|
| 438 |
+
| LC-A | ✓ | | | | | | 89.4 | 77.5 | 64.1 |
|
| 439 |
+
| LC-B | ✓ | ✓ | | | | | 181.4 | 78.1 | 65.1 |
|
| 440 |
+
| LC-C | ✓ | ✓ | ✓ | | | | 270.6 | 78.2 | 65.2 |
|
| 441 |
+
| LC-D | ✓ | | | ✓ | | | 93.9 | 77.6 | 64.7 |
|
| 442 |
+
| LC-E | ✓ | | | | ✓ | | 95.8 | 77.7 | 64.5 |
|
| 443 |
+
| LC-F | ✓ | | | ✓ | ✓ | | 97.7 | 77.7 | 64.9 |
|
| 444 |
+
| LC-G | | | | ✓ | | | 0.9 | 57.8 | 34.2 |
|
| 445 |
+
| LC-H | | | | | ✓ | | 1.8 | 54.5 | 28.2 |
|
| 446 |
+
| LC-I | | | ✓ | | | | 89.2 | 64.1 | 43.5 |
|
| 447 |
+
| LC-J | | ✓ | | | | | 89.4 | 67.4 | 51.2 |
|
| 448 |
+
| LC-K | ✓ | | | | | ✓ | 181.4 | 77.6 | 64.3 |
|
| 449 |
+
| LC-L | ✓ | ✓ | ✓ | ✓ | ✓ | | 276.4 | 78.2 | 65.8 |
|
| 450 |
+
| LC-ALL | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | 365.8 | 78.2 | 65.6 |
|
| 451 |
+
|||||||||||
|
| 452 |
+
| LPIS-A | ✓ | | | | | | 89.4 | 86.6 | 24.4 |
|
| 453 |
+
| LPIS-B | ✓ | | ✓ | | | | 181.2 | 87.1 | 26.1 |
|
| 454 |
+
| LPIS-C | ✓ | | | ✓ | | | 93.9 | 87.5 | 29.8 |
|
| 455 |
+
| LPIS-D | ✓ | | | ✓ | ✓ | | 97.7 | 88.0 | 36.1 |
|
| 456 |
+
| LPIS-E | ✓ | | ✓ | ✓ | | | 183.1 | 87.6 | 30.3 |
|
| 457 |
+
| LPIS-F | | | | ✓ | | | 0.9 | 85.3 | 23.8 |
|
| 458 |
+
| LPIS-G | | | | | ✓ | | 1.8 | 84.5 | 18.1 |
|
| 459 |
+
| LPIS-H | | | | ✓ | ✓ | | 2.8 | 84.9 | 23.8 |
|
| 460 |
+
| LPIS-I | | | ✓ | ✓ | ✓ | | 97.5 | 87.2 | 39.2 |
|
| 461 |
+
| LPIS-J | ✓ | | ✓ | ✓ | ✓ | | 186.9 | 88.0 | 35.4 |
|
| 462 |
+
| LPIS-K | | | ✓ | | | | 89.2 | 84.5 | 15.1 |
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
## Inference classes and colors
|
| 468 |
+
|
| 469 |
+
```yaml
|
| 470 |
+
flair_LC =
|
| 471 |
+
0 : 'building' 'bâtiment' '#db0e9a'
|
| 472 |
+
1 : 'greenhouse' 'serre' '#9999ff'
|
| 473 |
+
2 : 'swimming_pool' 'piscine' '#3de6eb'
|
| 474 |
+
3 : 'impervious surface' 'zone imperméable' '#f80c00'
|
| 475 |
+
4 : 'pervious surface' 'zone perméable' '#938e7b'
|
| 476 |
+
5 : 'bare soil' 'sol nu' '#a97101'
|
| 477 |
+
6 : 'water' 'eau' '#1553ae'
|
| 478 |
+
7 : 'snow' 'neige' '#ffffff'
|
| 479 |
+
8 : 'herbaceous vegetation' 'surface herbacée' '#55ff00'
|
| 480 |
+
9 : 'agricultural land' 'culture' '#fff30d'
|
| 481 |
+
10 : 'plowed land' 'terre labourée' '#e4df7c'
|
| 482 |
+
11 : 'vineyard' 'vigne' '#660082'
|
| 483 |
+
12 : 'deciduous' 'feuillu' '#46e483'
|
| 484 |
+
13 : 'coniferous' 'conifère' '#194a26'
|
| 485 |
+
14 : 'brushwood' 'broussaille' '#f3a60d'
|
| 486 |
+
15 : 'clear cut' 'coupe' '#8ab3a0'
|
| 487 |
+
16 : 'ligneous' 'ligneux' '#c5dc42'
|
| 488 |
+
17 : 'mixed' 'mixte' '#6b714f'
|
| 489 |
+
18 : 'undefined' 'indéterminé' '#000000'
|
| 490 |
+
|
| 491 |
+
flair_LPIS =
|
| 492 |
+
0 : 'Grasses' 'Herbe prédominante' '#92d050'
|
| 493 |
+
1 : 'Wheat' 'Blé' '#d7e600'
|
| 494 |
+
2 : 'Barley' 'Orge' '#e0e000'
|
| 495 |
+
3 : 'Maize' 'Maïs' '#fff100'
|
| 496 |
+
4 : 'Other cereals' 'Autres céréales' '#ffff00'
|
| 497 |
+
5 : 'Rice' 'Riz' '#e8e8e8'
|
| 498 |
+
6 : 'Hemp/Flax/Tobacco' 'Lin/Chanvre/Tabac' '#dceaf7'
|
| 499 |
+
7 : 'Sunflower' 'Tournesol' '#d29ead'
|
| 500 |
+
8 : 'Rapeseed' 'Colza' '#d29ed0'
|
| 501 |
+
9 : 'Other oilseed crops' 'Autres oléagineux' '#ffbe99'
|
| 502 |
+
10 : 'Soy' 'Soja' '#ffc000'
|
| 503 |
+
11 : 'Other protein crops' 'Autres protéagineux' '#ff9000'
|
| 504 |
+
12 : 'Fodder legumes' 'Légumineuse fourragères' '#009999'
|
| 505 |
+
13 : 'Beetroots' 'Betterave' '#808000'
|
| 506 |
+
14 : 'Potatoes' 'Pomme de terre' '#a7a700'
|
| 507 |
+
15 : 'Other arable crops' 'Autres arables' '#89896d'
|
| 508 |
+
16 : 'Vineyard' 'Vigne' '#f2cfee'
|
| 509 |
+
17 : 'Olive groves' 'Oliveraie' '#6f6633'
|
| 510 |
+
18 : 'Fruit orchards' 'Verger fruits' '#ac8141'
|
| 511 |
+
19 : 'Nut orchards' 'Verger noix' '#996633'
|
| 512 |
+
20 : 'Other permanent crops' 'Autres pérenne' '#80c1d7'
|
| 513 |
+
21 : 'Mixed crops' 'Mélange' '#000000'
|
| 514 |
+
22 : 'Background' 'Autres' '#000000'
|
| 515 |
+
|
| 516 |
+
```
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
|
| 521 |
+
## 🔎 Filter dataset with the FLAIR-HUB Dataset Browser
|
| 522 |
+
|
| 523 |
+
A small desktop GUI to browse and download subsets
|
| 524 |
+
of the IGNF/FLAIR-HUB dataset from Hugging Face with filters for: Domain, Year, Modality or Data type.
|
| 525 |
+
|
| 526 |
+
Requirements:
|
| 527 |
+
|
| 528 |
+
- Python 3.9+
|
| 529 |
+
- Tkinter (usually included; on Linux you may need: sudo apt-get install python3-tk)
|
| 530 |
+
- Python packages: pip install `huggingface_hub`
|
| 531 |
+
|
| 532 |
+
Run:
|
| 533 |
+
1. Get the `flair-hub-HF-dl.py` file.
|
| 534 |
+
2. In a terminal: ```pip install huggingface_hub```
|
| 535 |
+
3. Launch: ```python flair-hub-HF-dl.py```
|
| 536 |
+
|
| 537 |
+
<br><br>
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
## Reference
|
| 541 |
+
Cite the following article if you use the FLAIR #1 dataset:
|
| 542 |
+
|
| 543 |
+
```bibtex
|
| 544 |
+
@article{GARIOUD2026271,
|
| 545 |
+
title = {FLAIR-HUB: Large-scale multimodal dataset for land cover and crop mapping},
|
| 546 |
+
author = {Anatol Garioud and Sébastien Giordano and Nicolas David and Nicolas Gonthier},
|
| 547 |
+
journal = {ISPRS Journal of Photogrammetry and Remote Sensing},
|
| 548 |
+
volume = {237},
|
| 549 |
+
pages = {271-300},
|
| 550 |
+
year = {2026},
|
| 551 |
+
issn = {0924-2716},
|
| 552 |
+
doi = {https://doi.org/10.1016/j.isprsjprs.2026.04.017},
|
| 553 |
+
url = {https://www.sciencedirect.com/science/article/pii/S0924271626001899},
|
| 554 |
+
}
|
| 555 |
+
```
|
| 556 |
+
|
| 557 |
+
```
|
| 558 |
+
Anatol Garioud, Sébastien Giordano, Nicolas David, Nicolas Gonthier.
|
| 559 |
+
FLAIR-HUB: Large-scale Multimodal Dataset for Land Cover and Crop Mapping.
|
| 560 |
+
ISPRS Journal of Photogrammetry and Remote Sensing, Volume 237, 2026.
|
| 561 |
+
DOI: https://doi.org/10.1016/j.isprsjprs.2026.04.017
|
| 562 |
+
```
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
## Acknowledgment
|
| 568 |
+
The experiments conducted in this study were performed using HPC/AI resources provided by GENCI-IDRIS (Grant 2024-A0161013803, 2024-AD011014286R2 and 2025-A0181013803).
|
| 569 |
+
|
| 570 |
+
## Dataset license
|
| 571 |
+
|
| 572 |
+
The "OPEN LICENCE 2.0/LICENCE OUVERTE" is a license created by the French government specifically for the purpose of facilitating the dissemination of open data by public administration.
|
| 573 |
+
If you are looking for an English version of this license, you can find it on the official GitHub page at the [official github page](https://github.com/etalab/licence-ouverte).<br>
|
| 574 |
+
Applicable legislation : This licence is governed by French law.<br>
|
| 575 |
+
Compatibility of this licence : This licence has been designed to be compatible with any free licence that at least requires an acknowledgement of authorship, and specifically with the previous version of this licence as well as with the following licences: United Kingdom’s “Open Government Licence” (OGL), Creative Commons’ “Creative Commons Attribution” (CC-BY) and Open Knowledge Foundation’s “Open Data Commons Attribution” (ODC-BY).
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/configs/train/config_task.yaml
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
paths :
|
| 2 |
+
|
| 3 |
+
out_folder: ../results/
|
| 4 |
+
out_model_name: test-lib
|
| 5 |
+
|
| 6 |
+
train_csv: ../toy/TRAIN_FLAIR-INC_TOY.csv
|
| 7 |
+
val_csv: ../toy/VALID_FLAIR-INC_TOY.csv
|
| 8 |
+
test_csv: ../toy/TEST_FLAIR-INC_TOY.csv
|
| 9 |
+
global_mtd_folder: FLAIR-HUB/GLOBAL_ALL_MTD/
|
| 10 |
+
ckpt_model_path:
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
tasks:
|
| 14 |
+
|
| 15 |
+
train: True
|
| 16 |
+
train_tasks:
|
| 17 |
+
init_weights_only_from_ckpt: False
|
| 18 |
+
resume_training_from_ckpt: False
|
| 19 |
+
|
| 20 |
+
predict: True
|
| 21 |
+
write_files: True
|
| 22 |
+
georeferencing_output: True
|
| 23 |
+
|
| 24 |
+
metrics_only: False
|
| 25 |
+
|
| 26 |
+
hyperparams:
|
| 27 |
+
|
| 28 |
+
num_epochs: 150
|
| 29 |
+
batch_size: 5
|
| 30 |
+
seed: 2025
|
| 31 |
+
learning_rate: 0.00005
|
| 32 |
+
|
| 33 |
+
optimizer: adamw # [sgd / adam / adamw]
|
| 34 |
+
optim_weight_decay: 0.01
|
| 35 |
+
optim_betas: [0.9, 0.999]
|
| 36 |
+
|
| 37 |
+
scheduler: one_cycle_lr # [one_cycle_lr / reduce_on_plateau / cycle_then_plateau]
|
| 38 |
+
warmup_fraction: 0.2 # if using one_cycle_lr. [0-1]
|
| 39 |
+
plateau_patience: 10 # if using cycle_then_plateau
|
| 40 |
+
|
| 41 |
+
hardware:
|
| 42 |
+
accelerator: 'gpu'
|
| 43 |
+
num_nodes: 1
|
| 44 |
+
gpus_per_node: 1
|
| 45 |
+
strategy: 'auto' # ddp_find_unused_parameters_true if num_nodes > 1
|
| 46 |
+
num_workers: 0
|
| 47 |
+
|
| 48 |
+
saving:
|
| 49 |
+
ckpt_save_also_last: True
|
| 50 |
+
ckpt_weights_only: False
|
| 51 |
+
ckpt_monitor: 'val_miou'
|
| 52 |
+
ckpt_monitor_mode: 'max'
|
| 53 |
+
ckpt_earlystopping_patience: 20
|
| 54 |
+
cp_csv_and_conf_to_output: True
|
| 55 |
+
enable_progress_bar: True
|
| 56 |
+
progress_rate: 10
|
| 57 |
+
ckpt_verbose: True
|
| 58 |
+
verbose_config: False
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/csv/FLAIR-HUB_FULL.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b903a51a83157e4637d951f80101d2e3a70cdfef0fe4cb819948777ba5c1c6d7
|
| 3 |
+
size 8803545
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/csv/FLAIR-HUB_TOY.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f719cf0a6db767679d2c16323d7d78fb571d2d9cad23298ddfa1bb6b4e171715
|
| 3 |
+
size 18549
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/flair-hub-HF-dl.py
ADDED
|
@@ -0,0 +1,849 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import time
|
| 3 |
+
import threading
|
| 4 |
+
import tkinter as tk
|
| 5 |
+
from tkinter import ttk, messagebox, filedialog
|
| 6 |
+
from huggingface_hub import HfApi, hf_hub_download
|
| 7 |
+
|
| 8 |
+
# ============================================================
|
| 9 |
+
# CONFIG
|
| 10 |
+
# ============================================================
|
| 11 |
+
|
| 12 |
+
DATASET_ID = "IGNF/FLAIR-HUB"
|
| 13 |
+
DEFAULT_DOWNLOAD_DIR = "./FLAIR-HUB_download"
|
| 14 |
+
|
| 15 |
+
os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "1"
|
| 16 |
+
|
| 17 |
+
api = HfApi()
|
| 18 |
+
|
| 19 |
+
checkbox_state = {}
|
| 20 |
+
file_sizes = {}
|
| 21 |
+
stop_flag = threading.Event()
|
| 22 |
+
dataset_files = []
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# ============================================================
|
| 26 |
+
# HELPER FUNCTIONS
|
| 27 |
+
# ============================================================
|
| 28 |
+
|
| 29 |
+
def human_bytes(num):
|
| 30 |
+
if num is None:
|
| 31 |
+
return "unknown"
|
| 32 |
+
for unit in ["B", "KB", "MB", "GB", "TB"]:
|
| 33 |
+
if num < 1024:
|
| 34 |
+
return f"{num:.1f} {unit}"
|
| 35 |
+
num /= 1024
|
| 36 |
+
return f"{num:.1f} PB"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def parse_zip_metadata(path: str):
|
| 40 |
+
"""
|
| 41 |
+
Parse data ZIP filename of the form:
|
| 42 |
+
DOMAIN-YEAR_MODALITY_DATATYPE.zip
|
| 43 |
+
|
| 44 |
+
Example:
|
| 45 |
+
data/D004-2021_AERIAL_RGBI_IMS.zip
|
| 46 |
+
-> domain=D004, year=2021, modality=AERIAL_RGBI, datatype=IMS
|
| 47 |
+
"""
|
| 48 |
+
name = os.path.basename(path)
|
| 49 |
+
if not name.lower().endswith(".zip"):
|
| 50 |
+
return None
|
| 51 |
+
|
| 52 |
+
if name == "GLOBAL_ALL_MTD.zip":
|
| 53 |
+
return None
|
| 54 |
+
|
| 55 |
+
stem = name[:-4]
|
| 56 |
+
if "-" not in stem:
|
| 57 |
+
return None
|
| 58 |
+
|
| 59 |
+
domain, rest = stem.split("-", 1)
|
| 60 |
+
parts = rest.split("_")
|
| 61 |
+
year = parts[0] if parts and parts[0].isdigit() else None
|
| 62 |
+
|
| 63 |
+
modality = None
|
| 64 |
+
datatype = None
|
| 65 |
+
|
| 66 |
+
if len(parts) >= 2:
|
| 67 |
+
if len(parts) >= 3:
|
| 68 |
+
datatype = parts[-1]
|
| 69 |
+
modality = "_".join(parts[1:-1])
|
| 70 |
+
else:
|
| 71 |
+
modality = parts[1]
|
| 72 |
+
|
| 73 |
+
return {
|
| 74 |
+
"path": path,
|
| 75 |
+
"name": name,
|
| 76 |
+
"domain": domain,
|
| 77 |
+
"year": year,
|
| 78 |
+
"modality": modality,
|
| 79 |
+
"datatype": datatype,
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
# ============================================================
|
| 84 |
+
# MAIN WINDOW & STYLES
|
| 85 |
+
# ============================================================
|
| 86 |
+
|
| 87 |
+
root = tk.Tk()
|
| 88 |
+
root.title("FLAIR-HUB Dataset Download Tool")
|
| 89 |
+
root.geometry("1100x780")
|
| 90 |
+
root.minsize(860, 620)
|
| 91 |
+
|
| 92 |
+
BG_MAIN = "#020617"
|
| 93 |
+
BG_CARD = "#111827"
|
| 94 |
+
ACCENT = "#98c220"
|
| 95 |
+
ACCENT_H = "#b4de34"
|
| 96 |
+
FG_TEXT = "#e5e7eb"
|
| 97 |
+
FG_MUTED = "#9ca3af"
|
| 98 |
+
BORDER = "#1f2937"
|
| 99 |
+
|
| 100 |
+
LIST_BG = "#f9fafb"
|
| 101 |
+
LIST_FG = "#111827"
|
| 102 |
+
LIST_SEL_BG = "#d1fae5"
|
| 103 |
+
LIST_SEL_FG = "#065f46"
|
| 104 |
+
|
| 105 |
+
style = ttk.Style()
|
| 106 |
+
if "clam" in style.theme_names():
|
| 107 |
+
style.theme_use("clam")
|
| 108 |
+
|
| 109 |
+
BASE_FONT = ("Segoe UI", 10)
|
| 110 |
+
INFO_FONT = ("Consolas", 9)
|
| 111 |
+
LOG_FONT = ("Consolas", 9)
|
| 112 |
+
|
| 113 |
+
root.option_add("*Font", BASE_FONT)
|
| 114 |
+
root.configure(bg=BG_MAIN)
|
| 115 |
+
|
| 116 |
+
style.configure("TFrame", background=BG_MAIN)
|
| 117 |
+
style.configure("Card.TFrame", background=BG_CARD)
|
| 118 |
+
|
| 119 |
+
style.configure(
|
| 120 |
+
"Treeview",
|
| 121 |
+
background=LIST_BG,
|
| 122 |
+
fieldbackground=LIST_BG,
|
| 123 |
+
foreground=LIST_FG,
|
| 124 |
+
rowheight=24,
|
| 125 |
+
borderwidth=0,
|
| 126 |
+
highlightthickness=0,
|
| 127 |
+
)
|
| 128 |
+
style.map(
|
| 129 |
+
"Treeview",
|
| 130 |
+
background=[("selected", LIST_SEL_BG)],
|
| 131 |
+
foreground=[("selected", LIST_SEL_FG)],
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
style.configure(
|
| 135 |
+
"Accent.TButton",
|
| 136 |
+
background="#111827",
|
| 137 |
+
foreground=FG_TEXT,
|
| 138 |
+
padding=(10, 4),
|
| 139 |
+
relief="flat",
|
| 140 |
+
borderwidth=1,
|
| 141 |
+
)
|
| 142 |
+
style.map(
|
| 143 |
+
"Accent.TButton",
|
| 144 |
+
background=[
|
| 145 |
+
("active", "#1f2937"),
|
| 146 |
+
("pressed", "#111827"),
|
| 147 |
+
("disabled", "#111827"),
|
| 148 |
+
],
|
| 149 |
+
foreground=[
|
| 150 |
+
("disabled", FG_MUTED),
|
| 151 |
+
],
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
style.configure(
|
| 155 |
+
"Primary.TButton",
|
| 156 |
+
background=ACCENT,
|
| 157 |
+
foreground="#030712",
|
| 158 |
+
padding=(12, 5),
|
| 159 |
+
relief="flat",
|
| 160 |
+
borderwidth=0,
|
| 161 |
+
font=("Segoe UI", 10, "bold"),
|
| 162 |
+
)
|
| 163 |
+
style.map(
|
| 164 |
+
"Primary.TButton",
|
| 165 |
+
background=[
|
| 166 |
+
("active", ACCENT_H),
|
| 167 |
+
("pressed", ACCENT),
|
| 168 |
+
("disabled", "#4b5563"),
|
| 169 |
+
],
|
| 170 |
+
foreground=[
|
| 171 |
+
("disabled", "#111827"),
|
| 172 |
+
],
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
style.configure(
|
| 176 |
+
"Accent.Horizontal.TProgressbar",
|
| 177 |
+
troughcolor=BG_MAIN,
|
| 178 |
+
bordercolor=BG_MAIN,
|
| 179 |
+
background=ACCENT,
|
| 180 |
+
lightcolor=ACCENT,
|
| 181 |
+
darkcolor=ACCENT,
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
root.update_idletasks()
|
| 185 |
+
w = root.winfo_width()
|
| 186 |
+
h = root.winfo_height()
|
| 187 |
+
x = (root.winfo_screenwidth() // 2) - (w // 2)
|
| 188 |
+
y = (root.winfo_screenheight() // 2) - (h // 2)
|
| 189 |
+
root.geometry(f"{w}x{h}+{x}+{y}")
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
# ============================================================
|
| 193 |
+
# LAYOUT
|
| 194 |
+
# ============================================================
|
| 195 |
+
|
| 196 |
+
main_paned = ttk.Panedwindow(root, orient=tk.VERTICAL)
|
| 197 |
+
main_paned.pack(fill=tk.BOTH, expand=True, padx=10, pady=(8, 4))
|
| 198 |
+
|
| 199 |
+
info_outer = tk.Frame(
|
| 200 |
+
main_paned,
|
| 201 |
+
bg=BG_MAIN,
|
| 202 |
+
)
|
| 203 |
+
info_frame = tk.Frame(
|
| 204 |
+
info_outer,
|
| 205 |
+
bg=BG_CARD,
|
| 206 |
+
highlightbackground=BORDER,
|
| 207 |
+
highlightthickness=1,
|
| 208 |
+
bd=0,
|
| 209 |
+
)
|
| 210 |
+
info_frame.pack(fill=tk.BOTH, expand=True)
|
| 211 |
+
main_paned.add(info_outer, weight=1)
|
| 212 |
+
|
| 213 |
+
info_label = tk.Label(
|
| 214 |
+
info_frame,
|
| 215 |
+
text="Dataset Information",
|
| 216 |
+
font=("Segoe UI", 11, "bold"),
|
| 217 |
+
bg=BG_CARD,
|
| 218 |
+
fg=FG_TEXT,
|
| 219 |
+
)
|
| 220 |
+
info_label.pack(anchor="w", pady=(8, 4), padx=8)
|
| 221 |
+
|
| 222 |
+
info_text = tk.Text(
|
| 223 |
+
info_frame,
|
| 224 |
+
height=7,
|
| 225 |
+
wrap="word",
|
| 226 |
+
font=INFO_FONT,
|
| 227 |
+
bg=BG_MAIN,
|
| 228 |
+
fg=FG_TEXT,
|
| 229 |
+
bd=0,
|
| 230 |
+
relief="flat",
|
| 231 |
+
)
|
| 232 |
+
info_text.pack(fill=tk.BOTH, expand=True, padx=8, pady=(0, 8))
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
# ============================================================
|
| 236 |
+
# FILES AREA (filters + two-column panel)
|
| 237 |
+
# ============================================================
|
| 238 |
+
|
| 239 |
+
files_outer = tk.Frame(root, bg=BG_MAIN)
|
| 240 |
+
files_card = tk.Frame(
|
| 241 |
+
files_outer,
|
| 242 |
+
bg=BG_CARD,
|
| 243 |
+
highlightbackground=BORDER,
|
| 244 |
+
highlightthickness=1,
|
| 245 |
+
bd=0,
|
| 246 |
+
)
|
| 247 |
+
files_card.pack(fill=tk.BOTH, expand=True)
|
| 248 |
+
main_paned.add(files_outer, weight=3)
|
| 249 |
+
|
| 250 |
+
tree_frame = ttk.Frame(files_card, style="Card.TFrame")
|
| 251 |
+
tree_frame.pack(fill=tk.BOTH, expand=True, padx=6, pady=6)
|
| 252 |
+
|
| 253 |
+
filter_bar = ttk.Frame(tree_frame, padding=(4, 4), style="Card.TFrame")
|
| 254 |
+
filter_bar.pack(side=tk.TOP, fill=tk.X)
|
| 255 |
+
|
| 256 |
+
filter_title = ttk.Label(
|
| 257 |
+
filter_bar,
|
| 258 |
+
text="Filters",
|
| 259 |
+
font=("Segoe UI", 10, "bold"),
|
| 260 |
+
background=BG_CARD,
|
| 261 |
+
foreground=FG_TEXT,
|
| 262 |
+
)
|
| 263 |
+
filter_title.grid(row=0, column=0, padx=(0, 8), sticky="w")
|
| 264 |
+
|
| 265 |
+
domain_var = tk.StringVar(value="All")
|
| 266 |
+
year_var = tk.StringVar(value="All")
|
| 267 |
+
modality_var = tk.StringVar(value="All")
|
| 268 |
+
datatype_var = tk.StringVar(value="All")
|
| 269 |
+
|
| 270 |
+
domain_label = ttk.Label(filter_bar, text="Domain", background=BG_CARD, foreground=FG_MUTED)
|
| 271 |
+
year_label = ttk.Label(filter_bar, text="Year", background=BG_CARD, foreground=FG_MUTED)
|
| 272 |
+
modality_label = ttk.Label(filter_bar, text="Modality", background=BG_CARD, foreground=FG_MUTED)
|
| 273 |
+
datatype_label = ttk.Label(filter_bar, text="Data type", background=BG_CARD, foreground=FG_MUTED)
|
| 274 |
+
|
| 275 |
+
domain_cb = ttk.Combobox(filter_bar, textvariable=domain_var, state="readonly", width=12, values=["All"])
|
| 276 |
+
year_cb = ttk.Combobox(filter_bar, textvariable=year_var, state="readonly", width=8, values=["All"])
|
| 277 |
+
modality_cb = ttk.Combobox(filter_bar, textvariable=modality_var, state="readonly", width=14, values=["All"])
|
| 278 |
+
datatype_cb = ttk.Combobox(filter_bar, textvariable=datatype_var, state="readonly", width=10, values=["All"])
|
| 279 |
+
|
| 280 |
+
domain_label.grid(row=0, column=1, sticky="w", padx=(0, 2))
|
| 281 |
+
domain_cb.grid(row=0, column=2, padx=(2, 8))
|
| 282 |
+
|
| 283 |
+
year_label.grid(row=0, column=3, sticky="w", padx=(0, 2))
|
| 284 |
+
year_cb.grid(row=0, column=4, padx=(2, 8))
|
| 285 |
+
|
| 286 |
+
modality_label.grid(row=0, column=5, sticky="w", padx=(0, 2))
|
| 287 |
+
modality_cb.grid(row=0, column=6, padx=(2, 8))
|
| 288 |
+
|
| 289 |
+
datatype_label.grid(row=0, column=7, sticky="w", padx=(0, 2))
|
| 290 |
+
datatype_cb.grid(row=0, column=8, padx=(2, 8))
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def reset_filters():
|
| 294 |
+
domain_var.set("All")
|
| 295 |
+
year_var.set("All")
|
| 296 |
+
modality_var.set("All")
|
| 297 |
+
datatype_var.set("All")
|
| 298 |
+
apply_filters()
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
def show_metadata_only():
|
| 302 |
+
domain_var.set("GLOBAL")
|
| 303 |
+
year_var.set("All")
|
| 304 |
+
modality_var.set("GLOBAL")
|
| 305 |
+
datatype_var.set("MTD")
|
| 306 |
+
apply_filters()
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
metadata_btn = ttk.Button(filter_bar, text="Metadata", style="Accent.TButton", command=show_metadata_only)
|
| 310 |
+
metadata_btn.grid(row=0, column=9, padx=(4, 0), sticky="w")
|
| 311 |
+
|
| 312 |
+
reset_btn = ttk.Button(filter_bar, text="Reset", style="Accent.TButton", command=reset_filters)
|
| 313 |
+
reset_btn.grid(row=0, column=10, padx=(4, 0), sticky="w")
|
| 314 |
+
|
| 315 |
+
for col in range(11):
|
| 316 |
+
filter_bar.columnconfigure(col, weight=0)
|
| 317 |
+
|
| 318 |
+
files_split = ttk.Panedwindow(tree_frame, orient=tk.HORIZONTAL)
|
| 319 |
+
files_split.pack(side=tk.TOP, fill=tk.BOTH, expand=True, pady=(4, 0))
|
| 320 |
+
|
| 321 |
+
left_files_frame = ttk.Frame(files_split, padding=(0, 4), style="Card.TFrame")
|
| 322 |
+
files_split.add(left_files_frame, weight=3)
|
| 323 |
+
|
| 324 |
+
left_label = ttk.Label(
|
| 325 |
+
left_files_frame,
|
| 326 |
+
text="Available files",
|
| 327 |
+
font=("Segoe UI", 10, "bold"),
|
| 328 |
+
background=BG_CARD,
|
| 329 |
+
foreground=FG_TEXT,
|
| 330 |
+
)
|
| 331 |
+
left_label.pack(anchor="w", padx=(2, 0))
|
| 332 |
+
|
| 333 |
+
left_container = ttk.Frame(left_files_frame, style="Card.TFrame")
|
| 334 |
+
left_container.pack(fill=tk.BOTH, expand=True, pady=(2, 0))
|
| 335 |
+
|
| 336 |
+
left_scroll = ttk.Scrollbar(left_container, orient=tk.VERTICAL)
|
| 337 |
+
left_scroll.pack(side=tk.RIGHT, fill=tk.Y)
|
| 338 |
+
|
| 339 |
+
file_tree = ttk.Treeview(left_container, yscrollcommand=left_scroll.set, selectmode="none")
|
| 340 |
+
file_tree.pack(fill=tk.BOTH, expand=True)
|
| 341 |
+
left_scroll.config(command=file_tree.yview)
|
| 342 |
+
|
| 343 |
+
file_tree["columns"] = ()
|
| 344 |
+
file_tree.column("#0", anchor=tk.W, stretch=True)
|
| 345 |
+
file_tree["show"] = "tree"
|
| 346 |
+
|
| 347 |
+
right_selected_frame = ttk.Frame(files_split, padding=(8, 4), style="Card.TFrame")
|
| 348 |
+
files_split.add(right_selected_frame, weight=2)
|
| 349 |
+
|
| 350 |
+
right_title_bar = tk.Frame(right_selected_frame, bg=BG_CARD)
|
| 351 |
+
right_title_bar.pack(fill=tk.X, pady=(0, 2))
|
| 352 |
+
|
| 353 |
+
right_label = tk.Label(
|
| 354 |
+
right_title_bar,
|
| 355 |
+
text="Selected files",
|
| 356 |
+
font=("Segoe UI", 10, "bold"),
|
| 357 |
+
bg=BG_CARD,
|
| 358 |
+
fg=FG_TEXT,
|
| 359 |
+
)
|
| 360 |
+
right_label.pack(side=tk.LEFT)
|
| 361 |
+
|
| 362 |
+
badge_label = tk.Label(
|
| 363 |
+
right_title_bar,
|
| 364 |
+
text="[ 0 file — 0 ]",
|
| 365 |
+
font=("Segoe UI", 9, "bold"),
|
| 366 |
+
bg=ACCENT,
|
| 367 |
+
fg="#111827",
|
| 368 |
+
padx=8,
|
| 369 |
+
pady=2,
|
| 370 |
+
)
|
| 371 |
+
badge_label.pack(side=tk.RIGHT, padx=4)
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
selected_container = ttk.Frame(right_selected_frame, style="Card.TFrame")
|
| 375 |
+
selected_container.pack(fill=tk.BOTH, expand=True, pady=(2, 0))
|
| 376 |
+
|
| 377 |
+
selected_scroll = ttk.Scrollbar(selected_container, orient=tk.VERTICAL)
|
| 378 |
+
selected_scroll.pack(side=tk.RIGHT, fill=tk.Y)
|
| 379 |
+
|
| 380 |
+
selected_listbox = tk.Listbox(
|
| 381 |
+
selected_container,
|
| 382 |
+
height=10,
|
| 383 |
+
font=LOG_FONT,
|
| 384 |
+
bg=LIST_BG,
|
| 385 |
+
fg=LIST_FG,
|
| 386 |
+
bd=0,
|
| 387 |
+
relief="flat",
|
| 388 |
+
selectbackground=LIST_SEL_BG,
|
| 389 |
+
selectforeground=LIST_SEL_FG,
|
| 390 |
+
)
|
| 391 |
+
selected_listbox.pack(fill=tk.BOTH, expand=True)
|
| 392 |
+
selected_listbox.config(yscrollcommand=selected_scroll.set)
|
| 393 |
+
selected_scroll.config(command=selected_listbox.yview)
|
| 394 |
+
|
| 395 |
+
def update_selected_panel():
|
| 396 |
+
"""Refresh the right-hand 'selected files' list and the badge."""
|
| 397 |
+
selected_listbox.delete(0, tk.END)
|
| 398 |
+
|
| 399 |
+
total_bytes = 0
|
| 400 |
+
selected_items = [m for m in dataset_files if checkbox_state.get(m["path"], False)]
|
| 401 |
+
|
| 402 |
+
for meta in sorted(selected_items, key=lambda m: m["name"]):
|
| 403 |
+
selected_listbox.insert(tk.END, meta["name"])
|
| 404 |
+
if meta.get("size_bytes") is not None:
|
| 405 |
+
total_bytes += meta["size_bytes"]
|
| 406 |
+
|
| 407 |
+
count = len(selected_items)
|
| 408 |
+
size_str = human_bytes(total_bytes) if total_bytes > 0 else "0"
|
| 409 |
+
|
| 410 |
+
badge_label.config(
|
| 411 |
+
text=f"[ {count} file{'s' if count != 1 else ''} — {size_str} ]"
|
| 412 |
+
)
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
# ============================================================
|
| 416 |
+
# BOTTOM CONTROLS / LOGS
|
| 417 |
+
# ============================================================
|
| 418 |
+
|
| 419 |
+
bottom_outer = tk.Frame(root, bg=BG_MAIN)
|
| 420 |
+
bottom_card = tk.Frame(
|
| 421 |
+
bottom_outer,
|
| 422 |
+
bg=BG_CARD,
|
| 423 |
+
highlightbackground=BORDER,
|
| 424 |
+
highlightthickness=1,
|
| 425 |
+
bd=0,
|
| 426 |
+
)
|
| 427 |
+
bottom_card.pack(fill=tk.X, padx=10, pady=(2, 0))
|
| 428 |
+
bottom_outer.pack(fill=tk.X)
|
| 429 |
+
|
| 430 |
+
bottom_frame = ttk.Frame(bottom_card, padding=(10, 8), style="Card.TFrame")
|
| 431 |
+
bottom_frame.pack(fill=tk.X)
|
| 432 |
+
|
| 433 |
+
path_label = ttk.Label(bottom_frame, text="Download to:", background=BG_CARD, foreground=FG_MUTED)
|
| 434 |
+
path_label.grid(row=0, column=0, sticky="w")
|
| 435 |
+
|
| 436 |
+
download_path = ttk.Entry(bottom_frame)
|
| 437 |
+
download_path.insert(0, DEFAULT_DOWNLOAD_DIR)
|
| 438 |
+
download_path.grid(row=0, column=1, sticky="ew", padx=(6, 6))
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
def choose_folder():
|
| 442 |
+
folder = filedialog.askdirectory()
|
| 443 |
+
if folder:
|
| 444 |
+
download_path.delete(0, tk.END)
|
| 445 |
+
download_path.insert(0, folder)
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
browse_btn = ttk.Button(bottom_frame, text="📂 Browse…", style="Accent.TButton", command=choose_folder)
|
| 449 |
+
browse_btn.grid(row=0, column=2, sticky="ew")
|
| 450 |
+
|
| 451 |
+
btn_frame = ttk.Frame(bottom_frame, style="Card.TFrame")
|
| 452 |
+
btn_frame.grid(row=0, column=3, sticky="e", padx=(10, 0))
|
| 453 |
+
|
| 454 |
+
select_all_btn = ttk.Button(btn_frame, text="Select All", style="Accent.TButton")
|
| 455 |
+
unselect_all_btn = ttk.Button(btn_frame, text="Unselect All", style="Accent.TButton")
|
| 456 |
+
download_btn = ttk.Button(btn_frame, text="⬇ Download", style="Primary.TButton")
|
| 457 |
+
stop_btn = ttk.Button(btn_frame, text="⛔ Stop", style="Accent.TButton", state="disabled")
|
| 458 |
+
|
| 459 |
+
select_all_btn.pack(side=tk.LEFT, padx=(0, 4))
|
| 460 |
+
unselect_all_btn.pack(side=tk.LEFT, padx=(0, 4))
|
| 461 |
+
download_btn.pack(side=tk.LEFT, padx=(0, 4))
|
| 462 |
+
stop_btn.pack(side=tk.LEFT)
|
| 463 |
+
|
| 464 |
+
bottom_frame.columnconfigure(1, weight=1)
|
| 465 |
+
|
| 466 |
+
status_outer = tk.Frame(root, bg=BG_MAIN)
|
| 467 |
+
status_card = tk.Frame(
|
| 468 |
+
status_outer,
|
| 469 |
+
bg=BG_CARD,
|
| 470 |
+
highlightbackground=BORDER,
|
| 471 |
+
highlightthickness=1,
|
| 472 |
+
bd=0,
|
| 473 |
+
)
|
| 474 |
+
status_card.pack(fill=tk.X, padx=10, pady=(4, 0))
|
| 475 |
+
status_outer.pack(fill=tk.X)
|
| 476 |
+
|
| 477 |
+
status_frame = ttk.Frame(status_card, padding=(10, 4), style="Card.TFrame")
|
| 478 |
+
status_frame.pack(fill=tk.X)
|
| 479 |
+
|
| 480 |
+
status_label = ttk.Label(status_frame, text="Ready.", background=BG_CARD, foreground=FG_MUTED)
|
| 481 |
+
status_label.pack(side=tk.LEFT)
|
| 482 |
+
|
| 483 |
+
progress = ttk.Progressbar(status_frame, mode="indeterminate", length=220, style="Accent.Horizontal.TProgressbar")
|
| 484 |
+
progress.pack(side=tk.RIGHT)
|
| 485 |
+
|
| 486 |
+
log_outer = tk.Frame(root, bg=BG_MAIN)
|
| 487 |
+
log_card = tk.Frame(
|
| 488 |
+
log_outer,
|
| 489 |
+
bg=BG_CARD,
|
| 490 |
+
highlightbackground=BORDER,
|
| 491 |
+
highlightthickness=1,
|
| 492 |
+
bd=0,
|
| 493 |
+
)
|
| 494 |
+
log_card.pack(fill=tk.BOTH, expand=True, padx=10, pady=(4, 8))
|
| 495 |
+
log_outer.pack(fill=tk.BOTH, expand=True)
|
| 496 |
+
|
| 497 |
+
log_frame = ttk.Frame(log_card, padding=4, style="Card.TFrame")
|
| 498 |
+
log_frame.pack(fill=tk.BOTH, expand=True)
|
| 499 |
+
|
| 500 |
+
log_scroll = ttk.Scrollbar(log_frame, orient=tk.VERTICAL)
|
| 501 |
+
log_scroll.pack(side=tk.RIGHT, fill=tk.Y)
|
| 502 |
+
|
| 503 |
+
log_text = tk.Text(
|
| 504 |
+
log_frame,
|
| 505 |
+
height=10,
|
| 506 |
+
wrap="none",
|
| 507 |
+
font=LOG_FONT,
|
| 508 |
+
bg=BG_MAIN,
|
| 509 |
+
fg=FG_TEXT,
|
| 510 |
+
bd=0,
|
| 511 |
+
relief="flat",
|
| 512 |
+
)
|
| 513 |
+
log_text.pack(fill=tk.BOTH, expand=True)
|
| 514 |
+
log_text.config(state="disabled")
|
| 515 |
+
log_scroll.config(command=log_text.yview)
|
| 516 |
+
log_text.config(yscrollcommand=log_scroll.set)
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
def append_log(line: str):
|
| 520 |
+
log_text.config(state="normal")
|
| 521 |
+
log_text.insert("end", line + "\n")
|
| 522 |
+
log_text.see("end")
|
| 523 |
+
log_text.config(state="disabled")
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
def clear_log():
|
| 527 |
+
log_text.config(state="normal")
|
| 528 |
+
log_text.delete("1.0", "end")
|
| 529 |
+
log_text.config(state="disabled")
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
# ============================================================
|
| 533 |
+
# TREE / CHECKBOX LOGIC
|
| 534 |
+
# ============================================================
|
| 535 |
+
|
| 536 |
+
def refresh_checkboxes():
|
| 537 |
+
"""Update tree item text based on checkbox_state."""
|
| 538 |
+
for iid in file_tree.get_children(""):
|
| 539 |
+
checked = checkbox_state.get(iid, False)
|
| 540 |
+
meta = next((f for f in dataset_files if f["path"] == iid), None)
|
| 541 |
+
if meta is None:
|
| 542 |
+
continue
|
| 543 |
+
prefix = "☑ " if checked else "☐ "
|
| 544 |
+
file_tree.item(iid, text=f"{prefix}{meta['name']}")
|
| 545 |
+
update_selected_panel()
|
| 546 |
+
|
| 547 |
+
|
| 548 |
+
def apply_filters(*_):
|
| 549 |
+
"""Rebuild the left tree based on current filter values."""
|
| 550 |
+
file_tree.delete(*file_tree.get_children(""))
|
| 551 |
+
|
| 552 |
+
d_filter = domain_var.get()
|
| 553 |
+
y_filter = year_var.get()
|
| 554 |
+
m_filter = modality_var.get()
|
| 555 |
+
t_filter = datatype_var.get()
|
| 556 |
+
|
| 557 |
+
for meta in dataset_files:
|
| 558 |
+
if d_filter != "All" and meta["domain"] != d_filter:
|
| 559 |
+
continue
|
| 560 |
+
if y_filter != "All" and meta["year"] != y_filter:
|
| 561 |
+
continue
|
| 562 |
+
if m_filter != "All" and meta["modality"] != m_filter:
|
| 563 |
+
continue
|
| 564 |
+
if t_filter != "All" and meta["datatype"] != t_filter:
|
| 565 |
+
continue
|
| 566 |
+
|
| 567 |
+
path = meta["path"]
|
| 568 |
+
if path not in checkbox_state:
|
| 569 |
+
checkbox_state[path] = False
|
| 570 |
+
|
| 571 |
+
checked = checkbox_state[path]
|
| 572 |
+
prefix = "☑ " if checked else "☐ "
|
| 573 |
+
file_tree.insert("", "end", iid=path, text=f"{prefix}{meta['name']}")
|
| 574 |
+
|
| 575 |
+
update_selected_panel()
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
def toggle_all(state: bool):
|
| 579 |
+
"""Select/unselect only currently visible (filtered) files."""
|
| 580 |
+
for iid in file_tree.get_children(""):
|
| 581 |
+
checkbox_state[iid] = state
|
| 582 |
+
refresh_checkboxes()
|
| 583 |
+
status_label.config(text=f"{'Selected' if state else 'Unselected'} filtered files.")
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
def on_tree_click(event):
|
| 587 |
+
region = file_tree.identify("region", event.x, event.y)
|
| 588 |
+
column = file_tree.identify_column(event.x)
|
| 589 |
+
row = file_tree.identify_row(event.y)
|
| 590 |
+
|
| 591 |
+
if region == "tree" and column == "#0" and row:
|
| 592 |
+
bbox = file_tree.bbox(row)
|
| 593 |
+
if bbox and event.x > bbox[0] + 20:
|
| 594 |
+
current = checkbox_state.get(row, False)
|
| 595 |
+
checkbox_state[row] = not current
|
| 596 |
+
refresh_checkboxes()
|
| 597 |
+
|
| 598 |
+
|
| 599 |
+
file_tree.bind("<Button-1>", on_tree_click)
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
# ============================================================
|
| 603 |
+
# DATASET LOAD
|
| 604 |
+
# ============================================================
|
| 605 |
+
|
| 606 |
+
def load_dataset():
|
| 607 |
+
global file_sizes, dataset_files
|
| 608 |
+
info_text.delete(1.0, tk.END)
|
| 609 |
+
file_tree.delete(*file_tree.get_children(""))
|
| 610 |
+
checkbox_state.clear()
|
| 611 |
+
file_sizes = {}
|
| 612 |
+
dataset_files = []
|
| 613 |
+
|
| 614 |
+
status_label.config(text="Contacting Hugging Face API…")
|
| 615 |
+
root.update_idletasks()
|
| 616 |
+
|
| 617 |
+
try:
|
| 618 |
+
info = api.dataset_info(DATASET_ID, files_metadata=True)
|
| 619 |
+
except Exception as e:
|
| 620 |
+
messagebox.showerror("Error", f"Failed to load: {e}")
|
| 621 |
+
status_label.config(text="Failed to load dataset.")
|
| 622 |
+
return
|
| 623 |
+
|
| 624 |
+
created = info.created_at.strftime("%Y-%m-%d %H:%M") if info.created_at else "N/A"
|
| 625 |
+
modified = info.lastModified.strftime("%Y-%m-%d %H:%M") if info.lastModified else "N/A"
|
| 626 |
+
size = getattr(info, "usedStorage", 0) or 0
|
| 627 |
+
size_str = f"{size/1e9:.2f} GB" if size > 1e9 else f"{size/1e6:.2f} MB"
|
| 628 |
+
|
| 629 |
+
meta_info = f"""
|
| 630 |
+
ID : {info.id}
|
| 631 |
+
Author : {info.author or 'Unknown'}
|
| 632 |
+
Created : {created}
|
| 633 |
+
Modified : {modified}
|
| 634 |
+
Size : {size_str}
|
| 635 |
+
Downloads : {info.downloads or 0}
|
| 636 |
+
Likes : {info.likes or 0}
|
| 637 |
+
Tags : {', '.join(info.tags or [])}
|
| 638 |
+
Tasks : {', '.join((info.cardData or {}).get('task_categories', []))}
|
| 639 |
+
""".rstrip()
|
| 640 |
+
|
| 641 |
+
info_text.insert(tk.END, meta_info)
|
| 642 |
+
|
| 643 |
+
for s in info.siblings:
|
| 644 |
+
path = s.rfilename
|
| 645 |
+
|
| 646 |
+
if path.endswith("GLOBAL_ALL_MTD.zip"):
|
| 647 |
+
size_attr = getattr(s, "size", None)
|
| 648 |
+
m = {
|
| 649 |
+
"path": path,
|
| 650 |
+
"name": os.path.basename(path),
|
| 651 |
+
"domain": "GLOBAL",
|
| 652 |
+
"year": None,
|
| 653 |
+
"modality": "GLOBAL",
|
| 654 |
+
"datatype": "MTD",
|
| 655 |
+
"size_bytes": size_attr,
|
| 656 |
+
}
|
| 657 |
+
dataset_files.append(m)
|
| 658 |
+
if size_attr is not None:
|
| 659 |
+
file_sizes[path] = size_attr
|
| 660 |
+
continue
|
| 661 |
+
|
| 662 |
+
if not path.startswith("data/"):
|
| 663 |
+
continue
|
| 664 |
+
if not path.lower().endswith(".zip"):
|
| 665 |
+
continue
|
| 666 |
+
|
| 667 |
+
m = parse_zip_metadata(path)
|
| 668 |
+
if m is None:
|
| 669 |
+
continue
|
| 670 |
+
|
| 671 |
+
size_attr = getattr(s, "size", None)
|
| 672 |
+
m["size_bytes"] = size_attr
|
| 673 |
+
dataset_files.append(m)
|
| 674 |
+
|
| 675 |
+
if size_attr is not None:
|
| 676 |
+
file_sizes[path] = size_attr
|
| 677 |
+
|
| 678 |
+
domains = sorted({f["domain"] for f in dataset_files if f["domain"]})
|
| 679 |
+
years = sorted({f["year"] for f in dataset_files if f["year"]})
|
| 680 |
+
modalities = sorted({f["modality"] for f in dataset_files if f["modality"]})
|
| 681 |
+
datatypes = sorted({f["datatype"] for f in dataset_files if f["datatype"]})
|
| 682 |
+
|
| 683 |
+
domain_cb["values"] = ["All"] + domains
|
| 684 |
+
year_cb["values"] = ["All"] + years
|
| 685 |
+
modality_cb["values"] = ["All"] + modalities
|
| 686 |
+
datatype_cb["values"] = ["All"] + datatypes
|
| 687 |
+
|
| 688 |
+
domain_var.set("All")
|
| 689 |
+
year_var.set("All")
|
| 690 |
+
modality_var.set("All")
|
| 691 |
+
datatype_var.set("All")
|
| 692 |
+
|
| 693 |
+
apply_filters()
|
| 694 |
+
|
| 695 |
+
status_label.config(text=f"Loaded {len(dataset_files)} ZIP files from FLAIR-HUB (tiles + metadata).")
|
| 696 |
+
append_log("=== Dataset loaded: FLAIR-HUB (data/*.zip + GLOBAL_ALL_MTD.zip) ===")
|
| 697 |
+
|
| 698 |
+
|
| 699 |
+
# ============================================================
|
| 700 |
+
# DOWNLOAD LOGIC
|
| 701 |
+
# ============================================================
|
| 702 |
+
|
| 703 |
+
def stop_download():
|
| 704 |
+
stop_flag.set()
|
| 705 |
+
status_label.config(text="⏹ Stop requested. Finishing current file…")
|
| 706 |
+
stop_btn.config(state="disabled")
|
| 707 |
+
append_log("⛔ Stop requested by user.")
|
| 708 |
+
|
| 709 |
+
|
| 710 |
+
def download_selected():
|
| 711 |
+
folder = download_path.get().strip()
|
| 712 |
+
os.makedirs(folder, exist_ok=True)
|
| 713 |
+
|
| 714 |
+
files_to_download = [
|
| 715 |
+
iid for iid in file_tree.get_children("")
|
| 716 |
+
if checkbox_state.get(iid, False)
|
| 717 |
+
]
|
| 718 |
+
|
| 719 |
+
if not files_to_download:
|
| 720 |
+
messagebox.showinfo("No Selection", "No files selected (in current filter).")
|
| 721 |
+
return
|
| 722 |
+
|
| 723 |
+
total = len(files_to_download)
|
| 724 |
+
stop_flag.clear()
|
| 725 |
+
|
| 726 |
+
download_btn.config(state="disabled")
|
| 727 |
+
select_all_btn.config(state="disabled")
|
| 728 |
+
unselect_all_btn.config(state="disabled")
|
| 729 |
+
browse_btn.config(state="disabled")
|
| 730 |
+
stop_btn.config(state="normal")
|
| 731 |
+
|
| 732 |
+
progress["mode"] = "indeterminate"
|
| 733 |
+
progress.start(15)
|
| 734 |
+
status_label.config(text=f"🚀 Launching download: {total} file(s)…")
|
| 735 |
+
append_log(f"=== Download session started: {total} file(s) ===")
|
| 736 |
+
|
| 737 |
+
def worker():
|
| 738 |
+
t_session = time.time()
|
| 739 |
+
processed = 0
|
| 740 |
+
|
| 741 |
+
for index, fid in enumerate(files_to_download, start=1):
|
| 742 |
+
if stop_flag.is_set():
|
| 743 |
+
append_log("⛔ Download stopped by user.")
|
| 744 |
+
break
|
| 745 |
+
|
| 746 |
+
processed += 1
|
| 747 |
+
|
| 748 |
+
meta = next((f for f in dataset_files if f["path"] == fid), None)
|
| 749 |
+
name = meta["name"] if meta else fid
|
| 750 |
+
planned = meta["size_bytes"] if meta else None
|
| 751 |
+
size_info = human_bytes(planned) if planned else "unknown"
|
| 752 |
+
|
| 753 |
+
def set_label(f=name, i=index):
|
| 754 |
+
status_label.config(text=f"({i}/{total}) Downloading: {f}")
|
| 755 |
+
root.after(0, set_label)
|
| 756 |
+
|
| 757 |
+
root.after(
|
| 758 |
+
0,
|
| 759 |
+
lambda f=name, i=index, s=size_info: append_log(
|
| 760 |
+
f"▶ [{i}/{total}] {f} :: size ~ {s}"
|
| 761 |
+
),
|
| 762 |
+
)
|
| 763 |
+
|
| 764 |
+
t0 = time.time()
|
| 765 |
+
local_path = None
|
| 766 |
+
error = None
|
| 767 |
+
|
| 768 |
+
try:
|
| 769 |
+
local_path = hf_hub_download(
|
| 770 |
+
repo_id=DATASET_ID,
|
| 771 |
+
repo_type="dataset",
|
| 772 |
+
filename=fid,
|
| 773 |
+
local_dir=folder,
|
| 774 |
+
force_download=True,
|
| 775 |
+
)
|
| 776 |
+
except Exception as e:
|
| 777 |
+
error = e
|
| 778 |
+
|
| 779 |
+
elapsed = max(time.time() - t0, 1e-3)
|
| 780 |
+
|
| 781 |
+
size_bytes = planned
|
| 782 |
+
if size_bytes is None and local_path and os.path.exists(local_path):
|
| 783 |
+
try:
|
| 784 |
+
size_bytes = os.path.getsize(local_path)
|
| 785 |
+
except OSError:
|
| 786 |
+
size_bytes = None
|
| 787 |
+
|
| 788 |
+
if size_bytes and elapsed > 0:
|
| 789 |
+
speed_mbps = (size_bytes / elapsed) / (1024 * 1024)
|
| 790 |
+
else:
|
| 791 |
+
speed_mbps = None
|
| 792 |
+
|
| 793 |
+
if error is None:
|
| 794 |
+
size_h = human_bytes(size_bytes)
|
| 795 |
+
if speed_mbps is not None:
|
| 796 |
+
summary = f" ✅ Avg speed: {speed_mbps:.1f} MB/s | {size_h} in {elapsed:.1f}s"
|
| 797 |
+
else:
|
| 798 |
+
summary = f" ✅ {size_h} in {elapsed:.1f}s"
|
| 799 |
+
else:
|
| 800 |
+
summary = f" ❌ ERROR: {error}"
|
| 801 |
+
|
| 802 |
+
def push_summary(line=summary):
|
| 803 |
+
append_log(line)
|
| 804 |
+
append_log("")
|
| 805 |
+
root.after(0, push_summary)
|
| 806 |
+
|
| 807 |
+
def finish():
|
| 808 |
+
progress.stop()
|
| 809 |
+
stop_btn.config(state="disabled")
|
| 810 |
+
download_btn.config(state="normal")
|
| 811 |
+
select_all_btn.config(state="normal")
|
| 812 |
+
unselect_all_btn.config(state="normal")
|
| 813 |
+
browse_btn.config(state="normal")
|
| 814 |
+
|
| 815 |
+
session_time = time.time() - t_session
|
| 816 |
+
append_log(f"=== Download session ended :: {session_time:.1f}s ===")
|
| 817 |
+
|
| 818 |
+
if stop_flag.is_set():
|
| 819 |
+
status_label.config(text="⛔ Download stopped.")
|
| 820 |
+
messagebox.showinfo("Stopped", "Downloads were stopped.")
|
| 821 |
+
else:
|
| 822 |
+
status_label.config(text=f"✅ Completed. Processed {processed} file(s).")
|
| 823 |
+
messagebox.showinfo(
|
| 824 |
+
"Download Complete",
|
| 825 |
+
f"Download finished.\nProcessed {processed} file(s) in {session_time:.1f}s.",
|
| 826 |
+
)
|
| 827 |
+
|
| 828 |
+
root.after(0, finish)
|
| 829 |
+
|
| 830 |
+
threading.Thread(target=worker, daemon=True).start()
|
| 831 |
+
|
| 832 |
+
|
| 833 |
+
# ============================================================
|
| 834 |
+
# WIRING
|
| 835 |
+
# ============================================================
|
| 836 |
+
|
| 837 |
+
select_all_btn.config(command=lambda: toggle_all(True))
|
| 838 |
+
unselect_all_btn.config(command=lambda: toggle_all(False))
|
| 839 |
+
download_btn.config(command=download_selected)
|
| 840 |
+
stop_btn.config(command=stop_download)
|
| 841 |
+
|
| 842 |
+
domain_cb.bind("<<ComboboxSelected>>", apply_filters)
|
| 843 |
+
year_cb.bind("<<ComboboxSelected>>", apply_filters)
|
| 844 |
+
modality_cb.bind("<<ComboboxSelected>>", apply_filters)
|
| 845 |
+
datatype_cb.bind("<<ComboboxSelected>>", apply_filters)
|
| 846 |
+
|
| 847 |
+
load_dataset()
|
| 848 |
+
|
| 849 |
+
root.mainloop()
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/imgs/flair_bandeau.jpg
ADDED
|
Git LFS Details
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/setup.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from setuptools import setup, find_packages
|
| 2 |
+
|
| 3 |
+
with open("README.md", "r", encoding="utf-8") as fh:
|
| 4 |
+
long_description = fh.read()
|
| 5 |
+
|
| 6 |
+
setup(
|
| 7 |
+
name='flair-hub',
|
| 8 |
+
version='1.0.0',
|
| 9 |
+
author='IGNF | Anatol Garioud',
|
| 10 |
+
author_email='flair@ign.fr',
|
| 11 |
+
description='Baseline and demo code for the FLAIR-HUB dataset',
|
| 12 |
+
long_description=long_description,
|
| 13 |
+
long_description_content_type='text/markdown',
|
| 14 |
+
url='https://github.com/IGNF/FLAIR-HUB',
|
| 15 |
+
license='Apache-2.0',
|
| 16 |
+
project_urls={
|
| 17 |
+
'Bug Tracker': 'https://github.com/IGNF/FLAIR-HUB/issues'
|
| 18 |
+
},
|
| 19 |
+
classifiers=[
|
| 20 |
+
'Programming Language :: Python :: 3',
|
| 21 |
+
'License :: OSI Approved :: Apache Software License',
|
| 22 |
+
'Operating System :: OS Independent',
|
| 23 |
+
'Topic :: Scientific/Engineering :: Artificial Intelligence',
|
| 24 |
+
'Topic :: Scientific/Engineering :: Image Recognition'
|
| 25 |
+
],
|
| 26 |
+
package_dir={'': 'src'},
|
| 27 |
+
packages=find_packages(where='src'),
|
| 28 |
+
python_requires=">=3.11,<3.14",
|
| 29 |
+
install_requires=[
|
| 30 |
+
'geopandas==1.1.2',
|
| 31 |
+
'rasterio==1.4.3',
|
| 32 |
+
'omegaconf',
|
| 33 |
+
'jsonargparse',
|
| 34 |
+
'matplotlib',
|
| 35 |
+
'pandas==2.2.3',
|
| 36 |
+
'scikit-image==0.25.2',
|
| 37 |
+
'scikit-learn==1.6.1',
|
| 38 |
+
'pillow',
|
| 39 |
+
'torchmetrics==1.7.0',
|
| 40 |
+
'pytorch-lightning==2.5.1',
|
| 41 |
+
'segmentation-models-pytorch==0.4.0',
|
| 42 |
+
'tensorboard==2.19.0',
|
| 43 |
+
'pyarrow==23.0.1',
|
| 44 |
+
'pyogrio==0.10.0',
|
| 45 |
+
'safetensors==0.5.3'
|
| 46 |
+
],
|
| 47 |
+
include_package_data=True,
|
| 48 |
+
package_data={'': ['*.yml']},
|
| 49 |
+
entry_points={
|
| 50 |
+
'console_scripts': [
|
| 51 |
+
'flairhub=flair_hub.main:main',
|
| 52 |
+
'flairhub_zonal=flair_zonal_detection.main:main',
|
| 53 |
+
]
|
| 54 |
+
}
|
| 55 |
+
)
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/__init__.py
ADDED
|
File without changes
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/data/dataloader.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
from typing import Dict
|
| 5 |
+
from torch.utils.data import Dataset
|
| 6 |
+
|
| 7 |
+
from flair_hub.data.utils_data.io import read_patch
|
| 8 |
+
from flair_hub.data.utils_data.norm import norm
|
| 9 |
+
from flair_hub.data.utils_data.augmentations import apply_numpy_augmentations
|
| 10 |
+
from flair_hub.data.utils_data.label import reshape_label_ohe
|
| 11 |
+
from flair_hub.data.utils_data.elevation import calc_elevation
|
| 12 |
+
from flair_hub.data.utils_data.sentinel import (
|
| 13 |
+
reshape_sentinel,
|
| 14 |
+
filter_time_series,
|
| 15 |
+
temporal_average,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class flair_dataset(Dataset):
|
| 20 |
+
"""
|
| 21 |
+
PyTorch Dataset for multimodal remote sensing data.
|
| 22 |
+
Applies normalization, temporal aggregation, cloud filtering, and augmentations.
|
| 23 |
+
Args:
|
| 24 |
+
config (Dict): Configuration dictionary containing model and modality-specific settings, such as
|
| 25 |
+
input channels, normalization parameters, and temporal processing options.
|
| 26 |
+
dict_paths (Dict): A dictionary mapping data modalities (e.g., "AERIAL_RGBI", "LABELS")
|
| 27 |
+
to their corresponding file paths.
|
| 28 |
+
use_augmentations (callable, optional): A callable function or transformation pipeline to
|
| 29 |
+
apply augmentations to the samples. Defaults to None.
|
| 30 |
+
Methods:
|
| 31 |
+
__len__() -> int:
|
| 32 |
+
Returns the number of samples in the dataset.
|
| 33 |
+
__getitem__(index: int) -> Dict:
|
| 34 |
+
Retrieves batch_elements. Applies
|
| 35 |
+
normalization, temporal aggregation, and augmentations (if specified).
|
| 36 |
+
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
def __init__(self, config: Dict, dict_paths: Dict, use_augmentations: callable = None) -> None:
|
| 40 |
+
|
| 41 |
+
self.config = config
|
| 42 |
+
|
| 43 |
+
# flair_dataset __init__
|
| 44 |
+
if use_augmentations is True:
|
| 45 |
+
self.use_augmentations = apply_numpy_augmentations
|
| 46 |
+
else:
|
| 47 |
+
self.use_augmentations = use_augmentations
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# Data and label setup (same as before)
|
| 51 |
+
self._init_data_paths(dict_paths)
|
| 52 |
+
self._init_label_info(dict_paths)
|
| 53 |
+
self._init_normalization()
|
| 54 |
+
self.ref_date = config['models']['multitemp_model']['ref_date']
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _init_data_paths(self, dict_paths):
|
| 58 |
+
self.list_patch = {}
|
| 59 |
+
enabled = self.config["modalities"]["inputs"]
|
| 60 |
+
for mod, enabled_flag in enabled.items():
|
| 61 |
+
if enabled_flag and mod in dict_paths:
|
| 62 |
+
self.list_patch[mod] = np.array(dict_paths[mod])
|
| 63 |
+
if mod == "SENTINEL2_TS":
|
| 64 |
+
self.list_patch["SENTINEL2_MSK-SC"] = np.array(dict_paths["SENTINEL2_MSK-SC"])
|
| 65 |
+
|
| 66 |
+
self.dict_dates = {}
|
| 67 |
+
if "SENTINEL2_TS" in enabled:
|
| 68 |
+
self.dict_dates["SENTINEL2_TS"] = dict_paths.get("DATES_S2", {})
|
| 69 |
+
if "SENTINEL1-ASC_TS" in enabled:
|
| 70 |
+
self.dict_dates["SENTINEL1-ASC_TS"] = dict_paths.get("DATES_S1_ASC", {})
|
| 71 |
+
if "SENTINEL1-DESC_TS" in enabled:
|
| 72 |
+
self.dict_dates["SENTINEL1-DESC_TS"] = dict_paths.get("DATES_S1_DESC", {})
|
| 73 |
+
|
| 74 |
+
def _init_label_info(self, dict_paths):
|
| 75 |
+
self.tasks = {}
|
| 76 |
+
for task in self.config["labels"]:
|
| 77 |
+
label_conf = self.config["labels_configs"][task]
|
| 78 |
+
self.tasks[task] = {
|
| 79 |
+
"data_paths": np.array(dict_paths[task]),
|
| 80 |
+
"num_classes": len(label_conf["value_name"]),
|
| 81 |
+
"channels": [label_conf.get("label_channel_nomenclature", 1)]
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
def _init_normalization(self):
|
| 85 |
+
self.norm_type = self.config["modalities"]["normalization"]["norm_type"]
|
| 86 |
+
enabled_modalities = self.config["modalities"]["inputs"]
|
| 87 |
+
self.channels = {
|
| 88 |
+
mod: self.config["modalities"]["inputs_channels"].get(mod, [])
|
| 89 |
+
for mod, active in enabled_modalities.items() if active
|
| 90 |
+
}
|
| 91 |
+
self.normalization = {
|
| 92 |
+
mod: {
|
| 93 |
+
"mean": self.config["modalities"]["normalization"].get(f"{mod}_means", []),
|
| 94 |
+
"std": self.config["modalities"]["normalization"].get(f"{mod}_stds", [])
|
| 95 |
+
}
|
| 96 |
+
for mod, active in enabled_modalities.items() if active
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
def __len__(self):
|
| 100 |
+
for task in self.tasks.values():
|
| 101 |
+
if len(task["data_paths"]) > 0:
|
| 102 |
+
return len(task["data_paths"])
|
| 103 |
+
return 0
|
| 104 |
+
|
| 105 |
+
def __getitem__(self, index):
|
| 106 |
+
batch = {}
|
| 107 |
+
|
| 108 |
+
# Supervision
|
| 109 |
+
for task, info in self.tasks.items():
|
| 110 |
+
batch[f"ID_{task}"] = info["data_paths"][index]
|
| 111 |
+
area_elem = info["data_paths"][index].split("/")[-1].split("_")
|
| 112 |
+
area_elem = "_".join([area_elem[0], area_elem[-2], area_elem[-1].split(".")[0]])
|
| 113 |
+
|
| 114 |
+
# AERIAL_RGBI
|
| 115 |
+
key = "AERIAL_RGBI"
|
| 116 |
+
if key in self.list_patch:
|
| 117 |
+
data = read_patch(self.list_patch[key][index], self.channels[key])
|
| 118 |
+
batch[key] = norm(data,
|
| 119 |
+
self.norm_type,
|
| 120 |
+
self.normalization[key]["mean"],
|
| 121 |
+
self.normalization[key]["std"]
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
# AERIAL-RLT_PAN
|
| 125 |
+
key = "AERIAL-RLT_PAN"
|
| 126 |
+
if key in self.list_patch:
|
| 127 |
+
data = read_patch(self.list_patch[key][index], self.channels[key])
|
| 128 |
+
batch[key] = norm(data,
|
| 129 |
+
self.norm_type,
|
| 130 |
+
self.normalization[key]["mean"],
|
| 131 |
+
self.normalization[key]["std"]
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
# DEM_ELEV
|
| 135 |
+
key = "DEM_ELEV"
|
| 136 |
+
if key in self.list_patch and self.list_patch[key][index] is not None:
|
| 137 |
+
zdata = read_patch(self.list_patch[key][index])
|
| 138 |
+
if self.config["modalities"]["pre_processings"]["calc_elevation"]:
|
| 139 |
+
elev_data = calc_elevation(zdata)
|
| 140 |
+
if self.config["modalities"]["pre_processings"]["calc_elevation_stack_dsm"]:
|
| 141 |
+
elev_data = np.stack((zdata[0, :, :], elev_data[0]), axis=0)
|
| 142 |
+
batch[key] = elev_data
|
| 143 |
+
else:
|
| 144 |
+
batch[key] = zdata
|
| 145 |
+
batch[key] = norm(
|
| 146 |
+
batch[key],
|
| 147 |
+
self.norm_type,
|
| 148 |
+
self.normalization[key]["mean"],
|
| 149 |
+
self.normalization[key]["std"]
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
# SPOT_RGBI
|
| 153 |
+
key = "SPOT_RGBI"
|
| 154 |
+
if key in self.list_patch:
|
| 155 |
+
data = read_patch(self.list_patch[key][index], self.channels[key])
|
| 156 |
+
batch[key] = norm(data,
|
| 157 |
+
self.norm_type,
|
| 158 |
+
self.normalization[key]["mean"],
|
| 159 |
+
self.normalization[key]["std"]
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
# SENTINEL2_TS
|
| 163 |
+
key = "SENTINEL2_TS"
|
| 164 |
+
if key in self.list_patch:
|
| 165 |
+
s2 = read_patch(self.list_patch[key][index])
|
| 166 |
+
s2 = reshape_sentinel(s2, chunk_size=10)[:, [x - 1 for x in self.channels[key]], :, :]
|
| 167 |
+
|
| 168 |
+
s2_dates_dict = self.dict_dates[key][area_elem]
|
| 169 |
+
s2_dates = s2_dates_dict["dates"]
|
| 170 |
+
s2_dates_diff = s2_dates_dict["diff_dates"]
|
| 171 |
+
|
| 172 |
+
if self.config["modalities"]["pre_processings"]["filter_sentinel2"]:
|
| 173 |
+
msk = read_patch(self.list_patch["SENTINEL2_MSK-SC"][index])
|
| 174 |
+
msk = reshape_sentinel(msk, chunk_size=2)
|
| 175 |
+
idx_valid = filter_time_series(
|
| 176 |
+
msk,
|
| 177 |
+
max_cloud_value=self.config["modalities"]["pre_processings"]["filter_sentinel2_max_cloud"],
|
| 178 |
+
max_snow_value=self.config["modalities"]["pre_processings"]["filter_sentinel2_max_snow"],
|
| 179 |
+
max_fraction_covered=self.config["modalities"]["pre_processings"]["filter_sentinel2_max_frac_cover"]
|
| 180 |
+
)
|
| 181 |
+
s2 = s2[np.where(idx_valid)[0]]
|
| 182 |
+
s2_dates = s2_dates[np.where(idx_valid)[0]]
|
| 183 |
+
s2_dates_diff = s2_dates_diff[np.where(idx_valid)[0]]
|
| 184 |
+
|
| 185 |
+
if self.config["modalities"]["pre_processings"]["temporal_average_sentinel2"]:
|
| 186 |
+
s2, s2_dates_diff = temporal_average(
|
| 187 |
+
s2, s2_dates,
|
| 188 |
+
period=self.config["modalities"]["pre_processings"]["temporal_average_sentinel2"],
|
| 189 |
+
ref_date=self.ref_date
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
batch[key] = s2
|
| 193 |
+
batch[key.replace("_TS", "_DATES")] = s2_dates_diff
|
| 194 |
+
|
| 195 |
+
# SENTINEL1 ASC
|
| 196 |
+
key = "SENTINEL1-ASC_TS"
|
| 197 |
+
if key in self.list_patch and self.list_patch[key][index] is not None:
|
| 198 |
+
sentinel1asc_data = read_patch(self.list_patch[key][index])
|
| 199 |
+
sentinel1asc_data = reshape_sentinel(sentinel1asc_data, chunk_size=2)[:,
|
| 200 |
+
[x - 1 for x in self.channels[key]], :, :]
|
| 201 |
+
|
| 202 |
+
sentinel1asc_dates_dict = self.dict_dates[key][area_elem]
|
| 203 |
+
sentinel1asc_dates = sentinel1asc_dates_dict['dates']
|
| 204 |
+
sentinel1asc_dates_diff = sentinel1asc_dates_dict['diff_dates']
|
| 205 |
+
|
| 206 |
+
if self.config["modalities"]["pre_processings"]["temporal_average_sentinel1"]:
|
| 207 |
+
sentinel1asc_data, sentinel1asc_dates_diff = temporal_average(
|
| 208 |
+
sentinel1asc_data,
|
| 209 |
+
sentinel1asc_dates,
|
| 210 |
+
period=self.config["modalities"]["pre_processings"]["temporal_average_sentinel1"],
|
| 211 |
+
ref_date=self.ref_date
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
batch[key] = sentinel1asc_data
|
| 215 |
+
batch[key.replace('_TS', '_DATES')] = sentinel1asc_dates_diff
|
| 216 |
+
|
| 217 |
+
# SENTINEL1 DESC
|
| 218 |
+
key = "SENTINEL1-DESC_TS"
|
| 219 |
+
if key in self.list_patch and self.list_patch[key][index] is not None:
|
| 220 |
+
sentinel1desc_data = read_patch(self.list_patch[key][index])
|
| 221 |
+
sentinel1desc_data = reshape_sentinel(sentinel1desc_data, chunk_size=2)[:,
|
| 222 |
+
[x - 1 for x in self.channels[key]], :, :]
|
| 223 |
+
|
| 224 |
+
sentinel1desc_dates_dict = self.dict_dates[key][area_elem]
|
| 225 |
+
sentinel1desc_dates = sentinel1desc_dates_dict['dates']
|
| 226 |
+
sentinel1desc_dates_diff = sentinel1desc_dates_dict['diff_dates']
|
| 227 |
+
|
| 228 |
+
if self.config["modalities"]["pre_processings"]["temporal_average_sentinel1"]:
|
| 229 |
+
sentinel1desc_data, sentinel1desc_dates_diff = temporal_average(
|
| 230 |
+
sentinel1desc_data,
|
| 231 |
+
sentinel1desc_dates,
|
| 232 |
+
period=self.config["modalities"]["pre_processings"]["temporal_average_sentinel1"],
|
| 233 |
+
ref_date=self.ref_date
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
batch[key] = sentinel1desc_data
|
| 237 |
+
batch[key.replace('_TS', '_DATES')] = sentinel1desc_dates_diff
|
| 238 |
+
|
| 239 |
+
# Labels
|
| 240 |
+
for task, info in self.tasks.items():
|
| 241 |
+
label = read_patch(info["data_paths"][index], info["channels"])
|
| 242 |
+
batch[task] = reshape_label_ohe(label, info["num_classes"])
|
| 243 |
+
|
| 244 |
+
# Apply numpy augmentations
|
| 245 |
+
if callable(self.use_augmentations):
|
| 246 |
+
input_keys = [k for k, v in self.config["modalities"]["inputs"].items() if v]
|
| 247 |
+
label_keys = list(self.config["labels"])
|
| 248 |
+
batch = self.use_augmentations(batch, input_keys, label_keys)
|
| 249 |
+
|
| 250 |
+
# Convert to torch tensors
|
| 251 |
+
batch = {
|
| 252 |
+
k: torch.tensor(v, dtype=torch.float32)
|
| 253 |
+
if isinstance(v, (np.ndarray, list)) and "ID_" not in k else v
|
| 254 |
+
for k, v in batch.items()
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
return batch
|
| 258 |
+
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/data/datamodule.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from torch.utils.data import DataLoader
|
| 2 |
+
from pytorch_lightning import LightningDataModule
|
| 3 |
+
from typing import Dict, Optional
|
| 4 |
+
|
| 5 |
+
from flair_hub.data.dataloader import flair_dataset
|
| 6 |
+
from flair_hub.data.utils_data.padding import pad_collate_flair
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class FlairDataModule(LightningDataModule):
|
| 10 |
+
def __init__(
|
| 11 |
+
self,
|
| 12 |
+
config,
|
| 13 |
+
dict_train: Optional[Dict] = None,
|
| 14 |
+
dict_val: Optional[Dict] = None,
|
| 15 |
+
dict_test: Optional[Dict] = None,
|
| 16 |
+
num_workers: int = 1,
|
| 17 |
+
batch_size: int = 2,
|
| 18 |
+
drop_last: bool = True,
|
| 19 |
+
use_augmentations: bool = True,
|
| 20 |
+
):
|
| 21 |
+
"""
|
| 22 |
+
Initialize the FlairDataModule.
|
| 23 |
+
Args:
|
| 24 |
+
config: Configuration dictionary with settings for the dataset.
|
| 25 |
+
dict_train (dict, optional): Dictionary containing paths for training data.
|
| 26 |
+
dict_val (dict, optional): Dictionary containing paths for validation data.
|
| 27 |
+
dict_test (dict, optional): Dictionary containing paths for test data.
|
| 28 |
+
num_workers (int, optional): Number of workers for data loading.
|
| 29 |
+
batch_size (int, optional): Batch size for data loading.
|
| 30 |
+
drop_last (bool, optional): Whether to drop the last batch in training and validation.
|
| 31 |
+
use_augmentations (bool, optional): Whether to apply augmentations.
|
| 32 |
+
"""
|
| 33 |
+
super().__init__()
|
| 34 |
+
self.config = config
|
| 35 |
+
self.dict_train = dict_train
|
| 36 |
+
self.dict_val = dict_val
|
| 37 |
+
self.dict_test = dict_test
|
| 38 |
+
self.batch_size = batch_size
|
| 39 |
+
self.num_workers = num_workers
|
| 40 |
+
self.drop_last = drop_last
|
| 41 |
+
self.use_augmentations = use_augmentations
|
| 42 |
+
self.train_dataset = None
|
| 43 |
+
self.val_dataset = None
|
| 44 |
+
self.pred_dataset = None
|
| 45 |
+
|
| 46 |
+
def prepare_data(self):
|
| 47 |
+
"""Prepare the data. This is a placeholder function."""
|
| 48 |
+
pass
|
| 49 |
+
|
| 50 |
+
def setup(self, stage: Optional[str] = None):
|
| 51 |
+
"""
|
| 52 |
+
Set up the datasets for training, validation, or prediction.
|
| 53 |
+
Args:
|
| 54 |
+
stage (str, optional): The stage for setting up the data ('fit', 'validate', 'predict').
|
| 55 |
+
"""
|
| 56 |
+
if stage in ("fit", "validate"):
|
| 57 |
+
self._setup_train_val_datasets()
|
| 58 |
+
elif stage == "predict":
|
| 59 |
+
self._setup_pred_dataset()
|
| 60 |
+
|
| 61 |
+
def _setup_train_val_datasets(self):
|
| 62 |
+
"""Helper function to set up the training and validation datasets."""
|
| 63 |
+
self.train_dataset = self._create_flair_dataset(self.dict_train, self.use_augmentations)
|
| 64 |
+
self.val_dataset = self._create_flair_dataset(self.dict_val, use_augmentations=None)
|
| 65 |
+
|
| 66 |
+
def _setup_pred_dataset(self):
|
| 67 |
+
"""Helper function to set up the prediction dataset."""
|
| 68 |
+
self.pred_dataset = self._create_flair_dataset(self.dict_test, use_augmentations=None)
|
| 69 |
+
|
| 70 |
+
def _create_flair_dataset(self, dict_paths: Dict[str, str], use_augmentations: Optional[bool]) -> "flair_dataset":
|
| 71 |
+
"""
|
| 72 |
+
Helper function to create a flair dataset.
|
| 73 |
+
Args:
|
| 74 |
+
dict_paths (dict): Dictionary containing the paths to the data.
|
| 75 |
+
use_augmentations (bool, optional): Whether to apply augmentations.
|
| 76 |
+
Returns:
|
| 77 |
+
flair_dataset: The created dataset.
|
| 78 |
+
"""
|
| 79 |
+
return flair_dataset(
|
| 80 |
+
self.config,
|
| 81 |
+
dict_paths=dict_paths,
|
| 82 |
+
use_augmentations=use_augmentations
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
def _create_dataloader(self, dataset, batch_size: int, shuffle: bool, drop_last: bool):
|
| 86 |
+
"""
|
| 87 |
+
Helper function to create a DataLoader for a given dataset.
|
| 88 |
+
Args:
|
| 89 |
+
dataset: The dataset to be used in the DataLoader.
|
| 90 |
+
batch_size (int): Batch size for the DataLoader.
|
| 91 |
+
shuffle (bool): Whether to shuffle the dataset.
|
| 92 |
+
drop_last (bool): Whether to drop the last batch.
|
| 93 |
+
Returns:
|
| 94 |
+
DataLoader: The configured DataLoader.
|
| 95 |
+
"""
|
| 96 |
+
return DataLoader(
|
| 97 |
+
dataset=dataset,
|
| 98 |
+
batch_size=batch_size,
|
| 99 |
+
shuffle=shuffle,
|
| 100 |
+
num_workers=self.num_workers,
|
| 101 |
+
drop_last=drop_last,
|
| 102 |
+
collate_fn=pad_collate_flair
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
def train_dataloader(self):
|
| 106 |
+
"""
|
| 107 |
+
Returns the DataLoader for training.
|
| 108 |
+
"""
|
| 109 |
+
return self._create_dataloader(self.train_dataset, self.batch_size, shuffle=True, drop_last=self.drop_last)
|
| 110 |
+
|
| 111 |
+
def val_dataloader(self):
|
| 112 |
+
"""
|
| 113 |
+
Returns the DataLoader for validation.
|
| 114 |
+
"""
|
| 115 |
+
return self._create_dataloader(self.val_dataset, self.batch_size, shuffle=False, drop_last=self.drop_last)
|
| 116 |
+
|
| 117 |
+
def predict_dataloader(self):
|
| 118 |
+
"""
|
| 119 |
+
Returns the DataLoader for prediction.
|
| 120 |
+
"""
|
| 121 |
+
return self._create_dataloader(self.pred_dataset, batch_size=1, shuffle=False, drop_last=False)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/main.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
from flair_hub.tasks.stages import training_stage, predict_stage
|
| 7 |
+
from flair_hub.tasks.module_setup import build_data_module
|
| 8 |
+
from flair_hub.data.utils_data.paths import get_datasets
|
| 9 |
+
from flair_hub.utils.messaging import start_msg, end_msg, Logger
|
| 10 |
+
from flair_hub.utils.config_io import setup_environment, copy_csv_and_config
|
| 11 |
+
from flair_hub.utils.config_display import print_recap
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
argParser = argparse.ArgumentParser()
|
| 15 |
+
argParser.add_argument("--config", "--conf", "--c", help="Path to the .yaml config file", required=True)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def main():
|
| 19 |
+
"""
|
| 20 |
+
Main function to set up the training and prediction process. It reads the config file, sets up the output folder,
|
| 21 |
+
initiates the training and prediction stages, and tracks emissions if enabled.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
args = argParser.parse_args()
|
| 25 |
+
config, out_dir = setup_environment(args)
|
| 26 |
+
sys.stdout = Logger(
|
| 27 |
+
Path(config['paths']["out_folder"], config['paths']["out_model_name"], f'flair-compute{config["paths"]["out_model_name"]}.log').as_posix())
|
| 28 |
+
|
| 29 |
+
start_msg()
|
| 30 |
+
|
| 31 |
+
# Define datasets
|
| 32 |
+
dict_train, dict_val, dict_test = get_datasets(config)
|
| 33 |
+
print_recap(config, dict_train, dict_val, dict_test)
|
| 34 |
+
|
| 35 |
+
# Copy relevant files for tracking
|
| 36 |
+
if config['saving']["cp_csv_and_conf_to_output"]:
|
| 37 |
+
copy_csv_and_config(config, out_dir, args)
|
| 38 |
+
|
| 39 |
+
# Get LightningDataModule
|
| 40 |
+
dm = build_data_module(config, dict_train=dict_train, dict_val=dict_val, dict_test=dict_test)
|
| 41 |
+
|
| 42 |
+
# Initialize variable for weights
|
| 43 |
+
trained_state_dict = None
|
| 44 |
+
|
| 45 |
+
# Training
|
| 46 |
+
if config['tasks']['train']:
|
| 47 |
+
trained_state_dict = training_stage(config, dm, out_dir)
|
| 48 |
+
|
| 49 |
+
# Inference
|
| 50 |
+
if config['tasks'].get('predict') or config['tasks'].get('metrics_only'):
|
| 51 |
+
out_dir_predict = Path(out_dir, 'results_' + config['paths']["out_model_name"])
|
| 52 |
+
out_dir_predict.mkdir(parents=True, exist_ok=True)
|
| 53 |
+
predict_stage(config, dm, out_dir_predict, trained_state_dict)
|
| 54 |
+
else:
|
| 55 |
+
print("[WARNING] Neither prediction nor metrics_only was enabled. Finishing.")
|
| 56 |
+
|
| 57 |
+
end_msg()
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
main()
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/tasks/stages.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import os
|
| 3 |
+
import datetime
|
| 4 |
+
|
| 5 |
+
from datetime import timedelta
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Dict, Optional
|
| 8 |
+
from collections import OrderedDict
|
| 9 |
+
from pytorch_lightning import seed_everything
|
| 10 |
+
|
| 11 |
+
from flair_hub.writer.prediction_writer import PredictionWriter
|
| 12 |
+
from flair_hub.tasks.trainers import train, predict
|
| 13 |
+
from flair_hub.models.checkpoint import load_checkpoint
|
| 14 |
+
from flair_hub.tasks.module_setup import get_input_img_sizes, build_segmentation_module
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def training_stage(
|
| 19 |
+
config: Dict,
|
| 20 |
+
data_module,
|
| 21 |
+
out_dir: Path
|
| 22 |
+
) -> OrderedDict:
|
| 23 |
+
"""
|
| 24 |
+
Conducts the training stage of the model: sets up the training environment, loads the model weights
|
| 25 |
+
from a checkpoint if available, trains the model, and logs the training information.
|
| 26 |
+
Args:
|
| 27 |
+
config (Dict): Configuration dictionary containing parameters for the task.
|
| 28 |
+
data_module: Data module providing training, validation, and testing data.
|
| 29 |
+
out_dir (Path): Path object representing the output directory for saving checkpoints and logs.
|
| 30 |
+
Returns:
|
| 31 |
+
OrderedDict: The state dictionary of the best-performing trained model.
|
| 32 |
+
"""
|
| 33 |
+
start = datetime.datetime.now()
|
| 34 |
+
|
| 35 |
+
seed_everything(config['hyperparams']['seed'], workers=True)
|
| 36 |
+
|
| 37 |
+
in_img_sizes = get_input_img_sizes(config, data_module, stage='fit')
|
| 38 |
+
|
| 39 |
+
seg_module = build_segmentation_module(config, in_img_sizes, stage='train')
|
| 40 |
+
|
| 41 |
+
if config['tasks']['train_tasks']['init_weights_only_from_ckpt']:
|
| 42 |
+
load_checkpoint(config, seg_module, exit_on_fail=True)
|
| 43 |
+
|
| 44 |
+
ckpt_callback = train(config, data_module, seg_module, out_dir)
|
| 45 |
+
|
| 46 |
+
best_trained_state_dict = torch.load(ckpt_callback.best_model_path, map_location=torch.device('cpu'))['state_dict']
|
| 47 |
+
|
| 48 |
+
end = datetime.datetime.now()
|
| 49 |
+
training_time_seconds = end - start
|
| 50 |
+
training_time_seconds = training_time_seconds.total_seconds()
|
| 51 |
+
|
| 52 |
+
print(f"\n[Training finished in {str(timedelta(seconds=training_time_seconds))} HH:MM:SS with "
|
| 53 |
+
f"{config['hardware']['num_nodes']} nodes and {config['hardware']['gpus_per_node']} gpus per node]")
|
| 54 |
+
print(f"Model path: {os.path.join(out_dir, 'checkpoints')}\n\n")
|
| 55 |
+
print('-' * 40)
|
| 56 |
+
|
| 57 |
+
return best_trained_state_dict
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def predict_stage(
|
| 62 |
+
config: Dict,
|
| 63 |
+
data_module,
|
| 64 |
+
out_dir_predict: Path,
|
| 65 |
+
trained_state_dict: Optional[OrderedDict] = None
|
| 66 |
+
) -> None:
|
| 67 |
+
"""
|
| 68 |
+
Conducts the prediction stage of the model: runs inference and optionally computes metrics.
|
| 69 |
+
Handles prediction, evaluation from disk, or notifies if neither task is enabled.
|
| 70 |
+
Args:
|
| 71 |
+
config (Dict): Configuration dictionary containing prediction and evaluation settings.
|
| 72 |
+
data_module: Data module providing data for prediction.
|
| 73 |
+
out_dir_predict (Path): Directory where predictions and results are saved.
|
| 74 |
+
trained_state_dict (Optional[OrderedDict]): Optional state dictionary of the trained model.
|
| 75 |
+
If not provided, model weights will be loaded from checkpoint.
|
| 76 |
+
Returns:
|
| 77 |
+
None
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
out_dir_predict = Path(out_dir_predict)
|
| 81 |
+
|
| 82 |
+
if config['tasks'].get("metrics_only", False) and not config['tasks'].get("predict", False):
|
| 83 |
+
print("[ ] Running in metrics-only mode: loading predictions from disk . . .")
|
| 84 |
+
writer = PredictionWriter(config, out_dir_predict, write_interval="batch")
|
| 85 |
+
writer.load_predictions_and_compute_metrics()
|
| 86 |
+
return
|
| 87 |
+
|
| 88 |
+
if config['tasks'].get("predict", False):
|
| 89 |
+
in_img_sizes = get_input_img_sizes(config, data_module, stage="predict")
|
| 90 |
+
seg_module = build_segmentation_module(config, in_img_sizes, stage='predict')
|
| 91 |
+
|
| 92 |
+
if config['tasks']['train']:
|
| 93 |
+
seg_module.load_state_dict(trained_state_dict, strict=False)
|
| 94 |
+
else:
|
| 95 |
+
load_checkpoint(config, seg_module)
|
| 96 |
+
|
| 97 |
+
print("[ ] Running inference and metrics calculation . . .")
|
| 98 |
+
predict(config, data_module, seg_module, out_dir_predict)
|
| 99 |
+
|
| 100 |
+
if not config['tasks'].get("predict") and not config['tasks'].get("metrics_only"):
|
| 101 |
+
print("[ ] Neither 'predict' nor 'metrics_only' is enabled. Finishing.")
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/tasks/trainers.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import torch
|
| 4 |
+
import torch.nn as nn
|
| 5 |
+
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Dict, Any
|
| 8 |
+
from pytorch_lightning import Trainer
|
| 9 |
+
from pytorch_lightning.callbacks import EarlyStopping, ModelCheckpoint
|
| 10 |
+
from pytorch_lightning.callbacks.progress.tqdm_progress import TQDMProgressBar
|
| 11 |
+
from pytorch_lightning.loggers import TensorBoardLogger
|
| 12 |
+
|
| 13 |
+
from flair_hub.writer.prediction_writer import PredictionWriter
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def check_batchnorm_and_batch_size(config: Dict[str, Any], seg_module: nn.Module) -> None:
|
| 17 |
+
"""
|
| 18 |
+
Check if the model contains BatchNorm layers and if the batch size is 1.
|
| 19 |
+
If both conditions are met, print a message and abort the script.
|
| 20 |
+
Args:
|
| 21 |
+
config (dict): Configuration dictionary containing parameters for training.
|
| 22 |
+
seg_module (nn.Module): Segmentation module for training.
|
| 23 |
+
"""
|
| 24 |
+
batch_size = config['hyperparams']['batch_size']
|
| 25 |
+
|
| 26 |
+
for module in seg_module.modules():
|
| 27 |
+
if isinstance(module, (nn.BatchNorm1d, nn.BatchNorm2d, nn.BatchNorm3d)) and batch_size == 1:
|
| 28 |
+
print("Warning: The model contains BatchNorm layers and the batch size is set to 1.")
|
| 29 |
+
print("Aborting training to avoid potential issues.")
|
| 30 |
+
print("Please set a batch size >1 in the current model provider configuration.")
|
| 31 |
+
sys.exit(1)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def train(config: Dict[str, Any], data_module: Any, seg_module: nn.Module, out_dir: str) -> ModelCheckpoint:
|
| 35 |
+
"""
|
| 36 |
+
Trains a model using the provided data module and segmentation module.
|
| 37 |
+
Args:
|
| 38 |
+
config (dict): Configuration dictionary containing parameters for training.
|
| 39 |
+
data_module: Data module for training, validation, and testing.
|
| 40 |
+
seg_module (nn.Module): Segmentation module for training.
|
| 41 |
+
out_dir (str): Output directory for saving model checkpoints.
|
| 42 |
+
Returns:
|
| 43 |
+
ModelCheckpoint: Callback for model checkpointing.
|
| 44 |
+
"""
|
| 45 |
+
check_batchnorm_and_batch_size(config, seg_module)
|
| 46 |
+
|
| 47 |
+
ckpt_callback = ModelCheckpoint(
|
| 48 |
+
monitor=config['saving']['ckpt_monitor'],
|
| 49 |
+
dirpath=os.path.join(out_dir, "checkpoints"),
|
| 50 |
+
filename="ckpt-{epoch:02d}-{val_loss:.2f}_" + config['paths']["out_model_name"],
|
| 51 |
+
save_top_k=1,
|
| 52 |
+
mode=config['saving']['ckpt_monitor_mode'],
|
| 53 |
+
save_last=config['saving']['ckpt_save_also_last'],
|
| 54 |
+
verbose=config['saving']['ckpt_verbose'],
|
| 55 |
+
save_weights_only=config['saving']['ckpt_weights_only'],
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
early_stop_callback = EarlyStopping(
|
| 59 |
+
monitor=config['saving']['ckpt_monitor'],
|
| 60 |
+
min_delta=0.00,
|
| 61 |
+
patience=config['saving']['ckpt_earlystopping_patience'],
|
| 62 |
+
mode=config['saving']['ckpt_monitor_mode'],
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
prog_rate = TQDMProgressBar(refresh_rate=config['saving']["progress_rate"])
|
| 66 |
+
|
| 67 |
+
callbacks = [
|
| 68 |
+
ckpt_callback,
|
| 69 |
+
early_stop_callback,
|
| 70 |
+
prog_rate,
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
logger = TensorBoardLogger(
|
| 74 |
+
save_dir=out_dir,
|
| 75 |
+
name=Path("tensorboard_logs_" + config['paths']["out_model_name"]).as_posix(),
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
loggers = [logger]
|
| 79 |
+
|
| 80 |
+
trainer = Trainer(
|
| 81 |
+
accelerator=config['hardware']["accelerator"],
|
| 82 |
+
devices=config['hardware']["gpus_per_node"],
|
| 83 |
+
strategy=config['hardware']["strategy"],
|
| 84 |
+
num_nodes=config['hardware']["num_nodes"],
|
| 85 |
+
max_epochs=config['hyperparams']["num_epochs"],
|
| 86 |
+
num_sanity_val_steps=0,
|
| 87 |
+
callbacks=callbacks,
|
| 88 |
+
logger=loggers,
|
| 89 |
+
enable_progress_bar=config['saving']["enable_progress_bar"],
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
if config['tasks']['train_tasks']['resume_training_from_ckpt']:
|
| 93 |
+
print('---------------------------------------------------------------')
|
| 94 |
+
print('------------- RESUMING TRAINING FROM CKPT_PATH ----------------')
|
| 95 |
+
print('---------------------------------------------------------------')
|
| 96 |
+
trainer.fit(seg_module, datamodule=data_module, ckpt_path=config['paths']['ckpt_model_path'])
|
| 97 |
+
else:
|
| 98 |
+
trainer.fit(seg_module, datamodule=data_module)
|
| 99 |
+
|
| 100 |
+
trainer.validate(seg_module, datamodule=data_module)
|
| 101 |
+
|
| 102 |
+
return ckpt_callback
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def predict(config: Dict[str, Any], data_module: Any, seg_module: nn.Module, out_dir: str) -> None:
|
| 106 |
+
"""
|
| 107 |
+
This function makes predictions using the provided data module and segmentation module.
|
| 108 |
+
Args:
|
| 109 |
+
config (dict): Configuration dictionary containing parameters for prediction.
|
| 110 |
+
data_module: Data module for training, validation, and testing.
|
| 111 |
+
seg_module (nn.Module): Segmentation module for prediction.
|
| 112 |
+
out_dir (str): Output directory for saving the predictions.
|
| 113 |
+
"""
|
| 114 |
+
writer_callback = PredictionWriter(
|
| 115 |
+
config,
|
| 116 |
+
output_dir=os.path.join(out_dir),
|
| 117 |
+
write_interval="batch",
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
trainer = Trainer(
|
| 121 |
+
accelerator=config['hardware']["accelerator"],
|
| 122 |
+
devices=config['hardware']["gpus_per_node"],
|
| 123 |
+
strategy=config['hardware']["strategy"],
|
| 124 |
+
num_nodes=config['hardware']["num_nodes"],
|
| 125 |
+
callbacks=[writer_callback],
|
| 126 |
+
enable_progress_bar=config['saving']["enable_progress_bar"],
|
| 127 |
+
logger=False,
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
trainer.predict(seg_module, datamodule=data_module, return_predictions=False)
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/utils/config_io.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import yaml
|
| 2 |
+
import os
|
| 3 |
+
import shutil
|
| 4 |
+
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from typing import Dict
|
| 7 |
+
from pytorch_lightning.utilities.rank_zero import rank_zero_only
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def read_config(path: str) -> Dict[str, dict]:
|
| 12 |
+
"""
|
| 13 |
+
Reads and combines YAML configuration(s) from a file or all files in a directory.
|
| 14 |
+
Args:
|
| 15 |
+
path (str): Path to a single YAML file or a directory containing YAML files.
|
| 16 |
+
Returns:
|
| 17 |
+
Dict[str, dict]: A combined dictionary with the contents of the YAML file(s).
|
| 18 |
+
"""
|
| 19 |
+
combined_config = {}
|
| 20 |
+
|
| 21 |
+
if os.path.isfile(path) and path.endswith('.yaml'):
|
| 22 |
+
with open(path, "r") as f:
|
| 23 |
+
config = yaml.safe_load(f)
|
| 24 |
+
if isinstance(config, dict):
|
| 25 |
+
combined_config.update(config)
|
| 26 |
+
elif os.path.isdir(path):
|
| 27 |
+
for file_name in os.listdir(path):
|
| 28 |
+
if file_name.endswith('.yaml'):
|
| 29 |
+
file_path = os.path.join(path, file_name)
|
| 30 |
+
with open(file_path, "r") as f:
|
| 31 |
+
config = yaml.safe_load(f)
|
| 32 |
+
if isinstance(config, dict):
|
| 33 |
+
combined_config.update(config)
|
| 34 |
+
else:
|
| 35 |
+
raise ValueError(f"Invalid path: {path}. Must be a .yaml file or a directory containing .yaml files.")
|
| 36 |
+
|
| 37 |
+
return combined_config
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def setup_environment(args) -> tuple:
|
| 41 |
+
"""
|
| 42 |
+
This function reads the configuration file, creates the output directory,
|
| 43 |
+
and sets up the logger.
|
| 44 |
+
Args:
|
| 45 |
+
args: Command-line arguments.
|
| 46 |
+
Returns:
|
| 47 |
+
tuple: Contains the config dictionary and the output directory path.
|
| 48 |
+
"""
|
| 49 |
+
config = read_config(args.config)
|
| 50 |
+
out_dir = Path(config['paths']["out_folder"], config['paths']["out_model_name"])
|
| 51 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 52 |
+
return config, out_dir
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@rank_zero_only
|
| 56 |
+
def copy_csv_and_config(config: dict, out_dir: Path, args) -> None:
|
| 57 |
+
"""
|
| 58 |
+
Copy the CSV files and configuration file to the output directory.
|
| 59 |
+
Args:
|
| 60 |
+
config (dict): Configuration dictionary.
|
| 61 |
+
out_dir (Path): Output directory path.
|
| 62 |
+
args: Command-line arguments.
|
| 63 |
+
"""
|
| 64 |
+
csv_copy_dir = Path(out_dir, 'used_csv_and_config')
|
| 65 |
+
csv_copy_dir.mkdir(parents=True, exist_ok=True)
|
| 66 |
+
|
| 67 |
+
if config["tasks"]["train"]:
|
| 68 |
+
shutil.copy(config["paths"]["train_csv"], csv_copy_dir)
|
| 69 |
+
shutil.copy(config["paths"]["val_csv"], csv_copy_dir)
|
| 70 |
+
|
| 71 |
+
if config["tasks"]["predict"]:
|
| 72 |
+
shutil.copy(config["paths"]["test_csv"], csv_copy_dir)
|
| 73 |
+
|
| 74 |
+
if os.path.isdir(args.config):
|
| 75 |
+
shutil.copytree(args.config, csv_copy_dir, dirs_exist_ok=True)
|
| 76 |
+
elif os.path.isfile(args.config):
|
| 77 |
+
shutil.copy(args.config, csv_copy_dir / Path(args.config).name)
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_hub/utils/messaging.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys, os
|
| 2 |
+
import datetime
|
| 3 |
+
|
| 4 |
+
from pytorch_lightning.utilities.rank_zero import rank_zero_only
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@rank_zero_only
|
| 8 |
+
def start_msg():
|
| 9 |
+
print("""
|
| 10 |
+
_____ _ _ ___ ____ _ _ _ _ ____
|
| 11 |
+
| ___| | / \ |_ _| _ \ | | | | | | | __ )
|
| 12 |
+
| |_ | | / _ \ | || |_) _____| |_| | | | | _ \
|
| 13 |
+
| _| | |___ / ___ \ | || _ |_____| _ | |_| | |_) |
|
| 14 |
+
|_| |_____/_/ \_|___|_| \_\ |_| |_|\___/|____/
|
| 15 |
+
_______________________________________________________
|
| 16 |
+
|
| 17 |
+
#######################################################
|
| 18 |
+
#################### LAUNCHING #######################
|
| 19 |
+
""")
|
| 20 |
+
print(datetime.datetime.now().strftime("Starting: %Y-%m-%d %H:%M") + '\n')
|
| 21 |
+
print("""
|
| 22 |
+
[ ] Setting up Logger . . .
|
| 23 |
+
[ ] Creating output files . . .
|
| 24 |
+
[ ] Reading config files . . .
|
| 25 |
+
[ ] Building up datasets . . .
|
| 26 |
+
|
| 27 |
+
"""
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
@rank_zero_only
|
| 32 |
+
def end_msg():
|
| 33 |
+
print("""
|
| 34 |
+
#######################################################
|
| 35 |
+
#################### FINISHED #######################
|
| 36 |
+
""")
|
| 37 |
+
print(datetime.datetime.now().strftime("Ending: %Y-%m-%d %H:%M") + '\n')
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
@rank_zero_only
|
| 42 |
+
class Logger:
|
| 43 |
+
"""
|
| 44 |
+
Custom logger that mirrors stdout to both the terminal and a log file.
|
| 45 |
+
Useful for capturing experiment logs during training or inference.
|
| 46 |
+
|
| 47 |
+
Attributes:
|
| 48 |
+
terminal (TextIO): The original system stdout.
|
| 49 |
+
log (TextIO): The file object to write logs to.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
def __init__(self, filename: str = 'Default.log') -> None:
|
| 53 |
+
"""
|
| 54 |
+
Initialize a Logger instance that writes both to stdout and a file.
|
| 55 |
+
|
| 56 |
+
Args:
|
| 57 |
+
filename (str): The log file name. Will be made unique if already exists.
|
| 58 |
+
"""
|
| 59 |
+
filename = self._get_unique_filename(filename)
|
| 60 |
+
self.terminal = sys.stdout
|
| 61 |
+
self.log = open(filename, 'w', encoding='utf-8')
|
| 62 |
+
self.encoding = self.terminal.encoding
|
| 63 |
+
|
| 64 |
+
def _get_unique_filename(self, filename: str) -> str:
|
| 65 |
+
"""
|
| 66 |
+
Generate a unique filename by appending a version suffix if needed.
|
| 67 |
+
|
| 68 |
+
Args:
|
| 69 |
+
filename (str): The initial filename requested.
|
| 70 |
+
|
| 71 |
+
Returns:
|
| 72 |
+
str: A unique filename that doesn't overwrite existing files.
|
| 73 |
+
"""
|
| 74 |
+
base, ext = os.path.splitext(filename)
|
| 75 |
+
if not os.path.exists(filename):
|
| 76 |
+
return filename
|
| 77 |
+
|
| 78 |
+
version = 1
|
| 79 |
+
while True:
|
| 80 |
+
new_filename = f"{base}_v{version}{ext}"
|
| 81 |
+
if not os.path.exists(new_filename):
|
| 82 |
+
return new_filename
|
| 83 |
+
version += 1
|
| 84 |
+
|
| 85 |
+
def write(self, message: str) -> None:
|
| 86 |
+
"""
|
| 87 |
+
Write a message to both stdout and the log file.
|
| 88 |
+
|
| 89 |
+
Args:
|
| 90 |
+
message (str): The string message to be logged.
|
| 91 |
+
"""
|
| 92 |
+
self.terminal.write(message)
|
| 93 |
+
self.log.write(message)
|
| 94 |
+
|
| 95 |
+
def flush(self) -> None:
|
| 96 |
+
"""
|
| 97 |
+
Flush the log file stream.
|
| 98 |
+
"""
|
| 99 |
+
self.log.flush()
|
| 100 |
+
|
| 101 |
+
def close(self) -> None:
|
| 102 |
+
"""
|
| 103 |
+
Close the log file stream.
|
| 104 |
+
"""
|
| 105 |
+
self.log.close()
|
| 106 |
+
|
| 107 |
+
def isatty(self) -> bool:
|
| 108 |
+
"""
|
| 109 |
+
Indicates whether the stream is interactive. Needed for tqdm compatibility.
|
| 110 |
+
|
| 111 |
+
Returns:
|
| 112 |
+
bool: Always False to ensure tqdm behaves correctly.
|
| 113 |
+
"""
|
| 114 |
+
return False
|
models/pretrained/landcover/flair-hub-rgb-swinbase-upernet/upstream/src/flair_zonal_detection/main.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
|
| 3 |
+
from flair_zonal_detection.inference import run_inference
|
| 4 |
+
|
| 5 |
+
def main() -> None:
|
| 6 |
+
parser = argparse.ArgumentParser(description="Run zonal detection inference.")
|
| 7 |
+
parser.add_argument(
|
| 8 |
+
"--config", type=str, required=True, help="Path to the detection config file"
|
| 9 |
+
)
|
| 10 |
+
args = parser.parse_args()
|
| 11 |
+
run_inference(args.config)
|
| 12 |
+
|
| 13 |
+
if __name__ == '__main__':
|
| 14 |
+
main()
|
models/satquery_water_bundle/MODEL_CARD.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SatQuery water model
|
| 2 |
+
|
| 3 |
+
SatlasPretrain Sentinel-2 multispectral Swin-v2-Base + explicit spectral fusion head, fine-tuned on hand-labeled Sen1Floods11 with event-exclusive splits and shadow hard negatives.
|
| 4 |
+
|
| 5 |
+
- Test F1: 0.8343
|
| 6 |
+
- Test IoU: 0.7157
|
| 7 |
+
- Test precision: 0.9209
|
| 8 |
+
- Test recall: 0.7626
|
| 9 |
+
- Dark-land false-positive rate: 0.0060
|
| 10 |
+
|
| 11 |
+
Limitations: optical imagery cannot see through thick cloud. Validate on the target sensor, geography, season, and water definition. Use Sentinel-1 fusion for all-weather flood mapping.
|
models/satquery_water_bundle/satquery_model_health.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"inference_verified": true,
|
| 3 |
+
"checkpoint_sha256": "e93903a19a09b98d9d8c2ac3f9973491f03359c679e8fc5cda3c9c8432b956d5",
|
| 4 |
+
"verified_at": "2026-09-23T19:03:38.338051+00:00",
|
| 5 |
+
"output_shape": [
|
| 6 |
+
1,
|
| 7 |
+
2,
|
| 8 |
+
512,
|
| 9 |
+
512
|
| 10 |
+
],
|
| 11 |
+
"device": "cuda",
|
| 12 |
+
"peak_allocated_vram_bytes": 1027438080,
|
| 13 |
+
"class_map": [
|
| 14 |
+
"background",
|
| 15 |
+
"water"
|
| 16 |
+
],
|
| 17 |
+
"sensor": "Sentinel-2",
|
| 18 |
+
"test_metrics": {
|
| 19 |
+
"precision": 0.9209026999318032,
|
| 20 |
+
"recall": 0.7625802115746306,
|
| 21 |
+
"f1": 0.834296767675814,
|
| 22 |
+
"iou": 0.7157025429297199,
|
| 23 |
+
"specificity": 0.9931365170414005,
|
| 24 |
+
"balanced_accuracy": 0.8778583643080156,
|
| 25 |
+
"dark_land_fpr": 0.005988187308963608
|
| 26 |
+
}
|
| 27 |
+
}
|
models/satquery_water_bundle/satquery_water_config.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"format_version": 1,
|
| 3 |
+
"task": "surface_water_segmentation",
|
| 4 |
+
"architecture": "SatlasWaterNet",
|
| 5 |
+
"pretrained_model": "Sentinel2_SwinB_SI_MS",
|
| 6 |
+
"source_band_order": [
|
| 7 |
+
"B1",
|
| 8 |
+
"B2",
|
| 9 |
+
"B3",
|
| 10 |
+
"B4",
|
| 11 |
+
"B5",
|
| 12 |
+
"B6",
|
| 13 |
+
"B7",
|
| 14 |
+
"B8",
|
| 15 |
+
"B8A",
|
| 16 |
+
"B9",
|
| 17 |
+
"B10",
|
| 18 |
+
"B11",
|
| 19 |
+
"B12"
|
| 20 |
+
],
|
| 21 |
+
"satlas_band_order": [
|
| 22 |
+
"R_from_B4",
|
| 23 |
+
"G_from_B3",
|
| 24 |
+
"B_from_B2",
|
| 25 |
+
"B5",
|
| 26 |
+
"B6",
|
| 27 |
+
"B7",
|
| 28 |
+
"B8",
|
| 29 |
+
"B11",
|
| 30 |
+
"B12"
|
| 31 |
+
],
|
| 32 |
+
"spectral_features": [
|
| 33 |
+
"NDWI",
|
| 34 |
+
"MNDWI",
|
| 35 |
+
"NDVI",
|
| 36 |
+
"AWEI_shadow",
|
| 37 |
+
"visible_brightness",
|
| 38 |
+
"B10_cirrus"
|
| 39 |
+
],
|
| 40 |
+
"normalization": {
|
| 41 |
+
"RGB": "clip(raw/3000,0,1)",
|
| 42 |
+
"B5_B6_B7_B8_B11_B12": "clip(raw/8160,0,1)",
|
| 43 |
+
"source_scale": 10000
|
| 44 |
+
},
|
| 45 |
+
"postprocess": {
|
| 46 |
+
"threshold": 0.5999999999999999,
|
| 47 |
+
"min_area_pixels": 16
|
| 48 |
+
},
|
| 49 |
+
"tile_inference": {
|
| 50 |
+
"tile_size": 512,
|
| 51 |
+
"overlap": 128,
|
| 52 |
+
"blend": "Hann"
|
| 53 |
+
},
|
| 54 |
+
"event_split": {
|
| 55 |
+
"Bolivia": "test",
|
| 56 |
+
"Ghana": "val",
|
| 57 |
+
"India": "train",
|
| 58 |
+
"Mekong": "train",
|
| 59 |
+
"Nigeria": "train",
|
| 60 |
+
"Pakistan": "train",
|
| 61 |
+
"Paraguay": "test",
|
| 62 |
+
"Somalia": "train",
|
| 63 |
+
"Spain": "val",
|
| 64 |
+
"Sri-Lanka": "train",
|
| 65 |
+
"USA": "train"
|
| 66 |
+
},
|
| 67 |
+
"seed": 20260922
|
| 68 |
+
}
|
models/satquery_water_bundle/satquery_water_metrics.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"validation": {
|
| 3 |
+
"precision": 0.8908810168728125,
|
| 4 |
+
"recall": 0.8982742527951183,
|
| 5 |
+
"f1": 0.8945623594863392,
|
| 6 |
+
"iou": 0.8092381937263012,
|
| 7 |
+
"specificity": 0.9885565110100245,
|
| 8 |
+
"balanced_accuracy": 0.9434153819025715,
|
| 9 |
+
"dark_land_fpr": 0.008992282683002863
|
| 10 |
+
},
|
| 11 |
+
"test": {
|
| 12 |
+
"precision": 0.9209026999318032,
|
| 13 |
+
"recall": 0.7625802115746306,
|
| 14 |
+
"f1": 0.834296767675814,
|
| 15 |
+
"iou": 0.7157025429297199,
|
| 16 |
+
"specificity": 0.9931365170414005,
|
| 17 |
+
"balanced_accuracy": 0.8778583643080156,
|
| 18 |
+
"dark_land_fpr": 0.005988187308963608
|
| 19 |
+
},
|
| 20 |
+
"per_test_event": {
|
| 21 |
+
"Bolivia": {
|
| 22 |
+
"precision": 0.9277822733037633,
|
| 23 |
+
"recall": 0.8797047029441767,
|
| 24 |
+
"f1": 0.9031040774941685,
|
| 25 |
+
"iou": 0.8233270440380979,
|
| 26 |
+
"specificity": 0.9870917395338736,
|
| 27 |
+
"balanced_accuracy": 0.9333982212390252,
|
| 28 |
+
"dark_land_fpr": 0.0
|
| 29 |
+
},
|
| 30 |
+
"Paraguay": {
|
| 31 |
+
"precision": 0.9182150207252384,
|
| 32 |
+
"recall": 0.7245027120250382,
|
| 33 |
+
"f1": 0.8099374097871166,
|
| 34 |
+
"iou": 0.6805838755440851,
|
| 35 |
+
"specificity": 0.9940910843947834,
|
| 36 |
+
"balanced_accuracy": 0.8592968982099108,
|
| 37 |
+
"dark_land_fpr": 0.0
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
}
|
models/satquery_water_bundle/satquery_water_state_dict.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e93903a19a09b98d9d8c2ac3f9973491f03359c679e8fc5cda3c9c8432b956d5
|
| 3 |
+
size 360362139
|
models/satquery_water_bundle/thresholds.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"water_probability_threshold": 0.6,
|
| 3 |
+
"minimum_component_area_pixels": 16,
|
| 4 |
+
"uncertainty_threshold": 0.3
|
| 5 |
+
}
|
models/water/s2-water-unetplusplus-efficientnet-b4/config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"encoder_name": "efficientnet-b4",
|
| 3 |
+
"architecture": "unetplusplus",
|
| 4 |
+
"num_channels": 6,
|
| 5 |
+
"num_classes": 2,
|
| 6 |
+
"use_timm_model": false,
|
| 7 |
+
"timm_model_name": null,
|
| 8 |
+
"model_type": "timm_segmentation"
|
| 9 |
+
}
|
models/water/s2-water-unetplusplus-efficientnet-b4/model.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fb8ae300b8b8e929fa764d72ac476a419e8eb9f121e52cce6c0c8816a48d487e
|
| 3 |
+
size 84032530
|