Skip to content

Commit 436ea78

Browse files
committed
Make anthropogenic example work
1 parent 6ce611c commit 436ea78

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

examples/anthropogenic-activities/config_trne.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ prepare_data.py:
55
fp_shapefile: data/FP_labels.gpkg # FP labels
66
# empty_tiles_aoi: data/AoI/<AOI_SHPFILE> # AOI in which additional empty tiles can be selected. Only one 'empty_tiles' option can be selected
77
# empty_tiles_year: 2023 # If "empty_tiles_aoi" selected then provide a year. Choice: (1) numeric (i.e. 2020), (2) [year1, year2] (random selection of a year within a given year range)
8-
empty_tiles_shp: data/20240726_EPT.gpkg # Provided shapefile of selected empty tiles. Only one 'empty_tiles' option can be selected
8+
empty_tiles_shp: data/20250924_ept_tiles.gpkg # Provided shapefile of selected empty tiles. Only one 'empty_tiles' option can be selected
99
category_field: Classe
1010
output_folder: output/trne/
1111
zoom_level: 16
@@ -16,11 +16,12 @@ generate_tilesets.py:
1616
enable: False # sample of tiles
1717
nb_tiles_max: 2000
1818
working_directory: .
19+
output_folder: output/trne/
1920
datasets:
2021
aoi_tiles: output/trne/tiles.geojson
2122
ground_truth_labels: output/trne/labels.geojson
22-
fp_labels: # Uncomment if FP shapefile exists in prepare_data.py
23-
fp_shp: output/trne/FP.geojson
23+
add_fp_labels: # Uncomment if FP shapefile exists in prepare_data.py
24+
fp_labels: output/trne/FP.geojson
2425
frac_trn: 0.7 # fraction of fp tiles to add to the trn dataset, then the remaining tiles will be split in 2 and added to tst and val datasets
2526
image_source:
2627
type: XYZ # supported values: 1. MIL = Map Image Layer 2. WMS 3. XYZ 4. FOLDER
@@ -30,7 +31,6 @@ generate_tilesets.py:
3031
tiles_frac: 0.5 # fraction (relative to the number of tiles intersecting labels) of empty tiles to add
3132
frac_trn: 0.7 # fraction of empty tiles to add to the trn dataset, then the remaining tiles will be split in 2 and added to tst and val datasets
3233
keep_oth_tiles: False # keep tiles in oth dataset not intersecting oth labels
33-
output_folder: output/trne/
3434
tile_size: 256 # per side, in pixels
3535
overwrite: True
3636
n_jobs: 10

helpers/download_tiles.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ def download_tiles(datasets_dict, gt_labels_gdf, oth_labels_gdf, fp_labels_gdf,
214214
OTH_TILES = empty_tiles_dict['keep_oth_tiles'] if 'keep_oth_tiles' in empty_tiles_dict.keys() else True
215215

216216
logger.info('Adding empty tiles to the datasets...')
217-
tmp_gdf = aoi_tiles_gdf.copy()
218-
tmp_gdf = tmp_gdf[~tmp_gdf['id'].isin(id_list_gt_tiles)] if GT_LABELS else tmp_gdf
219-
tmp_gdf = tmp_gdf[~tmp_gdf['id'].isin(id_list_fp_tiles)] if FP_LABELS else tmp_gdf
220-
all_empty_tiles_gdf = tmp_gdf[~tmp_gdf['id'].isin(id_list_oth_tiles)] if OTH_LABELS else tmp_gdf
217+
label_tiles = \
218+
(id_list_gt_tiles if GT_LABELS else [])\
219+
+ (id_list_fp_tiles if FP_LABELS else [])\
220+
+ (id_list_oth_tiles if OTH_LABELS else [])
221+
all_empty_tiles_gdf = aoi_tiles_gdf[~aoi_tiles_gdf['id'].isin(label_tiles)].copy()
221222

222223
nb_gt_tiles = len(id_list_gt_tiles) if GT_LABELS else 0
223224
nb_fp_tiles = len(id_list_fp_tiles) if FP_LABELS else 0

helpers/misc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@ def find_category(df):
189189
if 'category' in df.columns:
190190
df.rename(columns={'category': 'CATEGORY'}, inplace = True)
191191
elif 'CATEGORY' not in df.columns:
192-
logger.critical('The GT labels have no category. Please produce a CATEGORY column when preparing the data.')
192+
logger.critical('The labels have no category. Please produce a CATEGORY column when preparing the data.')
193193
sys.exit(1)
194194

195195
if 'supercategory' in df.columns:
196196
df.rename(columns={'supercategory': 'SUPERCATEGORY'}, inplace = True)
197197
elif 'SUPERCATEGORY' not in df.columns:
198-
logger.critical('The GT labels have no supercategory. Please produce a SUPERCATEGORY column when preparing the data.')
199-
sys.exit(1)
198+
logger.warning('The labels have no supercategory. A standard "foo" supercategory will be assigned.')
199+
df['SUPERCATEGORY'] = 'foo'
200200

201201
return df
202202

scripts/generate_tilesets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ def main(cfg_file_path):
124124

125125
# Get label info if available
126126
GT_LABELS = DATASETS['ground_truth_labels'] if 'ground_truth_labels' in DATASETS.keys() else None
127-
OTH_LABELS = DATASETS['other_labels'] if 'other_labels' in DATASETS.keys() else None
127+
OTH_LABELS = DATASETS['other_labels'] if 'other_labels' in DATASETS.keys() else None # Labels that are not good enough to be used for training
128128

129129
# Choose to add emtpy and FP tiles
130-
ADD_EMPTY_TILES = cfg['add_empty_tiles'] if 'add_empty_tiles' in cfg.keys() else False # Selected from oth tiles
130+
EMPTY_TILES_DICT = cfg['empty_tiles'] if 'empty_tiles' in cfg.keys() else False # Selected from oth tiles
131131
ADD_FP_LABELS = DATASETS['add_fp_labels'] if 'add_fp_labels' in DATASETS.keys() else False # Determine FP tiles based on FP labels
132132
if ADD_FP_LABELS:
133133
FP_LABELS = ADD_FP_LABELS['fp_labels']
@@ -178,13 +178,13 @@ def main(cfg_file_path):
178178

179179
# ------ Tile download
180180
aoi_tiles_gdf, img_metadata_dict, id_list_ept_tiles, dt_written_files = download_tiles(
181-
DATASETS, gt_labels_gdf, oth_labels_gdf, fp_labels_gdf, ADD_EMPTY_TILES, TILE_SIZE, N_JOBS, OUTPUT_DIR, DEBUG_MODE, DEBUG_MODE_LIMIT, OVERWRITE
181+
DATASETS, gt_labels_gdf, oth_labels_gdf, fp_labels_gdf, EMPTY_TILES_DICT, TILE_SIZE, N_JOBS, OUTPUT_DIR, DEBUG_MODE, DEBUG_MODE_LIMIT, OVERWRITE
182182
)
183183
written_files.extend(dt_written_files)
184184

185185
# ------ Split tiles between training/validation/test/other
186186
split_aoi_tiles_with_img_md_gdf, st_written_files = split_tiles(
187-
aoi_tiles_gdf, gt_labels_gdf, oth_labels_gdf, fp_labels_gdf, FP_FRAC_TRN, ADD_EMPTY_TILES, id_list_ept_tiles, img_metadata_dict, TILE_SIZE, SEED,
187+
aoi_tiles_gdf, gt_labels_gdf, oth_labels_gdf, fp_labels_gdf, FP_FRAC_TRN, EMPTY_TILES_DICT, id_list_ept_tiles, img_metadata_dict, TILE_SIZE, SEED,
188188
OUTPUT_DIR, DEBUG_MODE
189189
)
190190
written_files.extend(st_written_files)

0 commit comments

Comments
 (0)