Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

565 feature geo inference integration #566

Merged
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7bef6c8
Update environment.yml with new dependencies
Apr 17, 2024
cae1bf7
Refactor code to support geo-inference package
Apr 17, 2024
22ecdaa
Update model_path in inference config files
Apr 17, 2024
24dd60b
Refactor batch size calculation and add stride size in geo_inference
May 1, 2024
71b60c2
Add batch_size parameter to inference configuration files
May 1, 2024
138f76e
Update geo_inference function call in inference_segmentation.py
May 15, 2024
fd5dfe8
Remove unused function and add logging parameters
May 15, 2024
e7d610e
Add inference segmentation test files
May 15, 2024
ce92822
Merge branch 'develop' of https://github.com/NRCan/geo-deep-learning …
May 16, 2024
5b0df44
Add support for handling logits and multiple classes in ScriptModel
May 27, 2024
7bd07e8
Add logging statement and update model initialization parameters
May 27, 2024
40a1026
Add support for saving scripted model
May 27, 2024
9df072e
Merge branch 'geo-inference' of https://github.com/NRCan/geo-deep-lea…
May 30, 2024
9d48ad1
Update script_model flag to True
Jun 4, 2024
81451bd
Fix wildcard in inference_segmentation.py
Jun 4, 2024
f0d2d03
Fix condition for checking if GPUs are requested
Jun 10, 2024
b6570c2
Add training.num_gpus=0 to hydra overrides
Jun 10, 2024
078459c
Update normalization parameters in basic_augmentation_segmentation.yaml
Jun 10, 2024
41ba98b
Update output path in evaluate_segmentation.py
Jun 10, 2024
8318786
Update Python and PyTorch versions in environment.yml
Jun 10, 2024
c645f63
Remove mkl dependency
Jun 10, 2024
f1cfd45
Update dependencies in environment.yml
Jun 11, 2024
8e12e4a
Update dependencies in environment.yml
Jun 11, 2024
99ddc42
Update inference config files with new post-processing option
Jun 11, 2024
a7e161e
Fix mask_to_vec parameter in inference_segmentation.py
Jun 11, 2024
f3266dd
Update environment.yml file with new name for environment
Jun 11, 2024
cfc293e
Add geo-inference package and update dependencies
Jun 12, 2024
d06f792
Merge branch 'develop' of https://github.com/valhassan/geo-deep-learn…
Jun 17, 2024
0780249
Update geo-inference dependency installation option
Jun 17, 2024
2079e2f
Update geo-inference dependency to version 2.0.5 with torch 1.12.0
Jun 17, 2024
973a2bd
Update dependencies in environment.yml
Jun 18, 2024
1d34680
Fix import statement for rank_zero_only in utils.py
Jun 18, 2024
1f08e95
Remove unnecessary channels from environment.yml
Jun 18, 2024
48820a8
Merge branch 'develop' of https://github.com/valhassan/geo-deep-learn…
Jun 25, 2024
6de73e2
Add geopandas dependency
Jun 25, 2024
93d7fea
Update dependencies in environment.yml
Jun 25, 2024
c190509
Add numpy import and convert raster_np to float32
Jun 25, 2024
be749a1
Add import statement for DataSourceError in test_aoi.py
Jun 25, 2024
f26337d
Refactor dataset initialization and add spatial reference
Jun 25, 2024
8a1adc1
Remove unused utils.inference.py file and test_inference.py
Jun 25, 2024
4a12cc6
Update visualization.py with matplotlib import changes
Jun 25, 2024
25f0e1d
Add debug print statements in inference_segmentation.py
Jun 27, 2024
a5e36ce
Add debug print statements for image names
Jun 27, 2024
8ba8838
Update geo-inference version to 2.0.7
valhassan Jul 4, 2024
0e5133e
Refactor inference_segmentation.py to remove unnecessary print statem…
valhassan Jul 4, 2024
2ace890
Update GitHub Actions CI workflow
Jul 8, 2024
c0a09c8
Update conda environment activation command
Jul 8, 2024
4bf67c3
Update GitHub Actions workflow to use Conda environment
Jul 8, 2024
39ac351
Update GitHub Actions workflow to run pytest tests
Jul 8, 2024
afb6dae
Merge branch 'develop' of https://github.com/valhassan/geo-deep-learn…
Jul 9, 2024
cfbde31
Update normalization parameters in basic_augmentation_segmentation.yaml
Jul 12, 2024
0d71ef7
Remove print statements in evaluate_segmentation.py
Jul 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 17 additions & 55 deletions .github/workflows/github-actions-ci.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,22 @@
name: GitHub Actions Unit Tests
name: tests
on: [push, pull_request]
jobs:
clean-and-deploy-env:
runs-on: ubuntu-latest
env:
LD_LIBRARY_PATH: "/opt/conda/lib"
run-tests:
runs-on: ubuntu-22.04
defaults:
run:
shell: bash -el {0}
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
- name: checkout repository
uses: actions/checkout@v4.1.2

- name: create environment
uses: conda-incubator/setup-miniconda@v3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false

# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: false
haskell: false
large-packages: false
docker-images: false
swap-storage: false

- name: Update the environment
mamba-version: "*"
activate-environment: geo_deep_env
environment-file: environment.yml

- name: test with pytest
run: |
sudo apt-get update \
&& sudo apt-get install -y --no-install-recommends git wget unzip bzip2 build-essential

- name: Install Mamba
run: |
sudo wget https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-x86_64.sh -O /tmp/mamba.sh && \
/bin/bash /tmp/mamba.sh -b -p /opt/conda && \
sudo rm -rf /tmp/* && \
sudo apt-get clean && \
sudo rm -rf /var/lib/apt/lists/*

- name: Set system variables
run: |
echo '/opt/conda' >> $GITHUB_PATH

- name: Check if Custom Paths are Added
run: |
echo "$PATH"
echo "$LD_LIBRARY_PATH"

- name: Install pyenv
run: |
pip install pipenv
pip install pytest
- uses: actions/checkout@v2

- name: Install dependencies
run: |
/opt/conda/bin/mamba env create -f environment.yml
echo '/opt/conda/envs/geo_deep_env/bin' >> $GITHUB_PATH

- name: Test with pytest
run: |
pipenv run pytest tests/
pytest tests/
4 changes: 2 additions & 2 deletions config/augmentation/basic_augmentation_segmentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ augmentation:

# Augmentations done immediately before conversion to torch tensor
normalization: # Normalization: parameters for finetuning. See examples below:
mean: # -> mean: [0.485, 0.456, 0.406]
std: # -> std: std: [0.229, 0.224, 0.225])
mean: [1e-8, 1e-8, 1e-8] # -> mean: [0.485, 0.456, 0.406]
std: [1e-8, 1e-8, 1e-8] # -> std: std: [0.229, 0.224, 0.225])
scale_data: [ 0, 1 ] # Min and max value to scale values of input imagery

6 changes: 3 additions & 3 deletions config/inference/default_binary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ inference:
raw_data_csv: tests/inference/inference_segmentation_binary.csv
root_dir: inferences
input_stac_item: # alternatively, use a path or url to stac item directly
state_dict_path: ${general.save_weights_dir}/
model_path: ${general.save_weights_dir}/
output_path:
checkpoint_dir: # (string, optional): directory in which to save the object if url
batch_size: 8
chunk_size: # if empty, will be calculated automatically from max_pix_per_mb_gpu
# Maximum number of pixels each Mb of GPU Ram to allow. E.g. if GPU has 1000 Mb of Ram and this parameter is set to
# 10, chunk_size will be set to sqrt(1000 * 10) = 100.
use_hanning: True # enables smoothening with Hann windows; creates overlapping tiles.
max_pix_per_mb_gpu: 25
prep_data_only: False
override_model_params: False
Expand All @@ -22,4 +22,4 @@ inference:
max_used_ram: ${training.max_used_ram} # If RAM usage of detected GPU exceeds this percentage, it will be ignored

# Post-processing
ras2vec: False # if True, a polygonized version of the inference (.gpkg) will be created with rasterio tools
mask_to_vector: False # if True, a polygonized version of the inference (.gpkg) will be created with rasterio tools
5 changes: 3 additions & 2 deletions config/inference/default_multiclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ inference:
raw_data_csv: tests/inference/inference_segmentation_multiclass.csv
root_dir: inferences
input_stac_item: # alternatively, use a path or url to stac item directly
state_dict_path: ${general.save_weights_dir}/
model_path: ${general.save_weights_dir}/
output_path:
checkpoint_dir: # (string, optional): directory in which to save the object if url
batch_size: 8
chunk_size: # if empty, will be calculated automatically from max_pix_per_mb_gpu
# Maximum number of pixels each Mb of GPU Ram to allow. E.g. if GPU has 1000 Mb of Ram and this parameter is set to
# 10, chunk_size will be set to sqrt(1000 * 10) = 100.
Expand All @@ -21,4 +22,4 @@ inference:
max_used_ram: ${training.max_used_ram} # If RAM usage of detected GPU exceeds this percentage, it will be ignored

# Post-processing
ras2vec: False # if True, a polygonized version of the inference (.gpkg) will be created with rasterio tools
mask_to_vector: False # if True, a polygonized version of the inference (.gpkg) will be created with rasterio tools
2 changes: 1 addition & 1 deletion config/training/default_training.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ training:
max_used_perc:
state_dict_path:
state_dict_strict_load: True
script_model: False
script_model: True
compute_sampler_weights: False

# precision: 16
Expand Down
16 changes: 3 additions & 13 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
name: geo_deep_env
channels:
- pytorch
- conda-forge
dependencies:
- coverage>=6.3.1
- docker-py>=4.4.4
- geopandas>=0.10.2
- hydra-core>=1.2.0
- python==3.11.5
- pip
- pynvml>=11.0
- gdal
- pystac>=0.3.0
- pytest>=7.1
- python>=3.10
- pytorch==1.12
- mkl<=2024.0
- rich>=11.1
- ruamel_yaml>=0.15
- scikit-image>=0.18
- torchgeo>=0.3
- torchvision>=0.12
- pip:
- geo-inference>=2.0.7
- hydra-colorlog>=1.1.0
- hydra-optuna-sweeper>=1.1.0
- ttach>=0.0.3
- mlflow>=1.2 # causes env solving to hang if not with pip
4 changes: 3 additions & 1 deletion evaluate_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ def main(params):
gpkg_name_ = []

for aoi in tqdm(list_aois, desc='Evaluating from input list', position=0, leave=True):
output_path = working_folder / f"{aoi.aoi_id}_pred.tif" if not inference_image else inference_image
print(f"\nEvaluating AOI: {aoi.aoi_id}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to switch to logging,info() instead of print()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will take out the debug print statements. it's not meant to be there!

print(f"working_folder: {working_folder}")
output_path = working_folder / f"{aoi.aoi_id}_mask.tif" if not inference_image else inference_image
if not output_path.is_file():
raise FileNotFoundError(f"Couldn't locate inference to evaluate metrics with. Make inference has been run "
f"before you run evaluate mode.")
Expand Down
Loading