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

Raster Vision Tutorials #13

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e9aa6c5
updated setup instructions and section 1
NoaMillsUSDA-ARS Dec 15, 2023
8cd26b7
Finished section 2, started section 3
NoaMillsUSDA-ARS Dec 18, 2023
e81d7bf
Draft of tutorial 1, including revamp of image convolution discussion
NoaMillsUSDA-ARS Jan 11, 2024
e12f64c
Merge branch 'master' of https://github.com/NoaMillsUSDA-ARS/geospati…
NoaMillsUSDA-ARS Jan 11, 2024
6ee4d14
Edits to working in tutorial 1
NoaMillsUSDA-ARS Jan 30, 2024
900ad5d
Merge branch 'update_image_processing'
NoaMillsUSDA-ARS Jan 30, 2024
9e0244a
Edits to wording of tutorial 1
NoaMillsUSDA-ARS Jan 30, 2024
51625b5
Merge branch 'master' of https://github.com/NoaMillsUSDA-ARS/geospati…
NoaMillsUSDA-ARS Jan 30, 2024
f140213
Merge branch 'ISUgenomics:master' into master
NoaMillsUSDA-ARS Jan 30, 2024
14a7d9e
Replaced %whos command with numpy array attributes
NoaMillsUSDA-ARS Feb 10, 2024
9b44e5a
Merge branch 'master' of https://github.com/NoaMillsUSDA-ARS/geospati…
NoaMillsUSDA-ARS Feb 10, 2024
921f8a0
Added hidden cells that users can reveal to check their answers
NoaMillsUSDA-ARS Feb 14, 2024
800329e
add visualizations of 1-2 color channels
Feb 19, 2024
9079998
add rgb2hsv color conversion
Feb 19, 2024
2016388
add rgb object-specific crop
Feb 19, 2024
4a24563
smoothing RGB convolutions, outline rest of convolutions section
Feb 22, 2024
3859e37
update rgb_tutorial markdown files
Feb 23, 2024
38f9fef
update rgb_tutorial markdown files
Feb 23, 2024
1547d7c
Merge branch 'rgb_tutorial' of https://github.com/burnsal/geospatialw…
Feb 23, 2024
f6cec5a
Added draft of setup instructions
NoaMillsUSDA-ARS Feb 28, 2024
1d9e6ee
Merge branch 'master' of https://github.com/burnsal/geospatialworkboo…
Feb 28, 2024
bc6e0e8
pull updates from upstream fork
Feb 28, 2024
e886263
Merge pull request #1 from burnsal/rgb_tutorial
NoaMillsUSDA-ARS Feb 28, 2024
6e85af5
Raster Vision workbook progress, split content into 7 different tutor…
NoaMillsUSDA-ARS Mar 29, 2024
76b88b3
Merge branch 'master' of https://github.com/NoaMillsUSDA-ARS/geospati…
NoaMillsUSDA-ARS Mar 29, 2024
69aeb6e
Cleaned up headers, added conclusions, updated setup instruction images
NoaMillsUSDA-ARS Apr 2, 2024
03045d6
Updates and edits to parts 1 through 6
NoaMillsUSDA-ARS Apr 5, 2024
935ef72
Finished rough draft of tutorials 1-7
NoaMillsUSDA-ARS Apr 5, 2024
3e2fbb9
Post-atlas maintenance updates. Updated tutorial images, started swit…
NoaMillsUSDA-ARS May 23, 2024
0b47739
Added pygcdl tutorial
NoaMillsUSDA-ARS May 29, 2024
ef68b75
Progress through tutorial 8, dealing with heisenbug.
NoaMillsUSDA-ARS Jul 11, 2024
1e0b363
Merge branch 'master' of https://github.com/NoaMillsUSDA-ARS/geospati…
NoaMillsUSDA-ARS Jul 11, 2024
6fcbfc7
Updated through section 3
NoaMillsUSDA-ARS Jul 11, 2024
163960e
Updated final raster chipping image
NoaMillsUSDA-ARS Jul 11, 2024
1214f04
Created vis for chip size = 250, stride length = 200
NoaMillsUSDA-ARS Jul 12, 2024
b94fdff
Removing irrelevant padding content
NoaMillsUSDA-ARS Jul 12, 2024
1cb9a9f
Updated chipping image parameters
NoaMillsUSDA-ARS Jul 12, 2024
0a2d4fb
Updated through section 4.1
NoaMillsUSDA-ARS Jul 12, 2024
ed6d935
Updated plot_metrics() function to accept multiple model directories
NoaMillsUSDA-ARS Jul 16, 2024
7014c87
Final draft of raster vision tutorial series content
NoaMillsUSDA-ARS Jul 29, 2024
0ca8141
Added missing image
NoaMillsUSDA-ARS Jul 29, 2024
221dfe5
Progress on adding Raster Vision tutorials to website
NoaMillsUSDA-ARS Jul 29, 2024
3da1467
Added author bio
NoaMillsUSDA-ARS Jul 29, 2024
cb6de55
Finished updating line break fix
NoaMillsUSDA-ARS Jul 29, 2024
e1f783e
Merge branch 'master' of https://github.com/NoaMillsUSDA-ARS/geospati…
NoaMillsUSDA-ARS Jul 29, 2024
e5838d0
Finished adding and formatting Raster Vision content
NoaMillsUSDA-ARS Jul 29, 2024
4cfc644
Added landing page description, fixed image processing markdown
NoaMillsUSDA-ARS Jul 29, 2024
78be308
Minor wording change
NoaMillsUSDA-ARS Jul 29, 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
2 changes: 1 addition & 1 deletion ExampleGeoWorkflows/GRWGWorkshop.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Materials modified from the [USDA-ARS SCINet Geospatial Research Working Group W

| Tutorial | Python | R |
|:--|:--|
| SCINet Geospatial Common Data Library (GeoCDL) | | [view](GRWG22_GeoCDL_R) [download](../tutorials/GRWG22_GeoCDL.Rmd) |
| SCINet Geospatial Common Data Library (GeoCDL) | [view](pygcdl_tutorial) [download](../tutorials/pygcdl_tutorial.ipynb) | [view](GRWG22_GeoCDL_R) [download](../tutorials/GRWG22_GeoCDL.Rmd) |
| Handling Vector Data | [view](GRWG22_VectorData_python) [download](../tutorials/GRWG22_VectorData.ipynb) | [view](GRWG22_VectorData_R) [download](../tutorials/GRWG22_VectorData.Rmd) |
| Raster Calculations with Tiles | [view](GRWG22_RasterTiles_python) [download](../tutorials/GRWG22_RasterTiles.ipynb) | [view](GRWG22_RasterTiles_R) [download](../tutorials/GRWG22_RasterTiles.Rmd) |
| SLURM Job Arrays for Many Data Input Files | [view](GRWG22_ZonalStats_wSLURM_python) [download](../tutorials/GRWG22_ZonalStats_wSLURM.ipynb) | [view](GRWG22_ZonalStats_wSLURM_R) [download](../tutorials/GRWG22_ZonalStats_wSLURM.Rmd) |
Expand Down
358 changes: 358 additions & 0 deletions ExampleGeoWorkflows/pygcdl_tutorial.md

Large diffs are not rendered by default.

1,317 changes: 1,006 additions & 311 deletions IntroductionToImageAnalysis/Tutorial1_Image_Processing_Essentials_Boucheron.md

Large diffs are not rendered by default.

Binary file added IntroductionToImageAnalysis/output_105_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_10_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_124_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_131_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_13_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_144_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_151_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_153_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_155_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_28_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_33_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_40_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_49_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_51_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_57_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_58_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_59_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_63_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_76_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_78_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_80_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_97_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IntroductionToImageAnalysis/output_99_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions RasterVisionTutorialSeries/RV_LandingPage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: "Raster Vision Tutorial Series"
layout: single
header:
overlay_color: "444444"
overlay_image: assets/images/RV_cover.png
---

# Tutorial Series Info
This tutorial series is intended for USDA-ARS researchers with SCINet accounts. Code, data, and interactive versions on jupyter notebooks are available on Atlas. The browser-viewable versions of tutorials are available here for reference. The intended workflow involves following the first tutorial in the browser to get all of the interactive tutorials on Atlas, and then following along with the interactive tutorials on Atlas.

## Index

| Tutorial | Python |
|:--|:--|
| Part 1: Tutorial Setup | [view](Raster_Vision_Part_1) |
| Part 2: Overview of Deep Learning for Imagery and the Raster Vision Pipeline | [view](Raster_Vision_Part_2) |
| Part 3: Constructing and Exploring the Apptainer Image | [view](Raster_Vision_Part_3) |
| Part 4: Exploring the Dataset and Problem Space | [view](Raster_Vision_Part_4.md) |
| Part 5: Overview of Raster Vision Model Configuration and Setup | [view](Raster_Vision_Part_5.md) |
| Part 6: Breakdown of Raster Vision Code Version 1 | [view](Raster_Vision_Part_6.md) |
| Part 7: Evaluating Training Performance and Visualizing Predictions | [view](Raster_Vision_Part_7.md) |
| Part 8: Modifying Model Configuration - Hyperparameter Tuning | [view](Raster_Vision_Part_8.md) |
124 changes: 124 additions & 0 deletions RasterVisionTutorialSeries/Raster_Vision_Part_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
title: "Raster Vision Tutorial Series Part 1: Tutorial Setup on SCINet"
layout: single
author: Noa Mills
author_profile: true
header:
overlay_color: "444444"
overlay_image: /assets/images/margaret-weir-GZyjbLNOaFg-unsplash_dark.jpg
---


# Semantic Segmentation of Aerial Imagery with Raster Vision
## Part 1: Tutorial Setup on SCINet

This tutorial series walks through an example of using [Raster Vision](https://rastervision.io/) to train a deep learning model to identify buildings in satellite imagery.<br>

*Primary Libraries and Tools*:

|Name|Description|Link|
|-|-|-|
| `Raster Vision ` | Library and framework for geospatial semantic segmentation, object detection, and chip classification in python| https://rastervision.io/ |
| `Apptainer` | Containerization software that allows for transportable and reproducible software | https://apptainer.org/ |
| `pandas` | Python library supporting dataframes and other datatypes for data analysis and manipulation | https://pandas.pydata.org/ |
| `geopandas` | Python library that extends pandas to support geospatial vector data and spatial operations | https://geopandas.org/en/stable/ |
| `rioxarray` | Python library supporting data structures and operations for geospatial raster data | https://github.com/corteva/rioxarray |
| `pathlib` | A Python library for handling files and paths in the filesystem | https://docs.python.org/3/library/pathlib.html |

*Prerequisites*:
* Basic understanding of navigating the Linux command line, including navigating among directories and editing text files
* Basic python skills, including an understanding of object-oriented programming, function calls, and basic data types
* Basic understanding of shell scripts and job scheduling with SLURM for running code on Atlas
* A SCINet account for running this tutorial on Atlas

*Tutorials in this Series*:
* 1\. **Tutorial Setup on SCINet <span style="color: red;">_(You are here)_</span>**
* 2\. **Overview of Deep Learning for Imagery and the Raster Vision Pipeline**
* 3\. **Constructing and Exploring the Apptainer Image**
* 4\. **Exploring the Dataset and Problem Space**
* 5\. **Overview of Raster Vision Model Configuration and Setup**
* 6\. **Breakdown of Raster Vision Code Version 1**
* 7\. **Evaluating Training Performance and Visualizing Predictions**
* 8\. **Modifying Model Configuration - Hyperparameter Tuning**

## Tutorial Setup

To kick off this series of tutorials, we will begin with a tutorial dedicated to setting up your computational environment on Atlas! First, launch [Open OnDemand](https://atlas-ood.hpc.msstate.edu/pun/sys/dashboard) in your browser. Log in with your SCINet credentials. <br>

#### Project Group Identification
This tutorial requires users to specify an account name. This name will be used to launch a jupyter session in this tutorial, and to run batch scripts through SLURM in future tutorials. If you are a part of a project group, then you can use that project group name as your account name to launch jupyter run scripts. The following steps will allow you to see what project groups you are a part of. <br> <br>
From [MSU OnDemand](https://atlas-ood.hpc.msstate.edu/pun/sys/dashboard), click <b>Clusters</b>, then <b>Atlas Shell Access</b>. <br>
![Cluster_tab.png](imgs/atlas_shell_access.png) <br>
This will open up a terminal tab in another browser window. Log in with your SCINet credentials, then run the following command: <br>
`sacctmgr -Pns show user format=account where user=$USER` <br> <br>
This will output a list of project groups you are a part of. If you are a part of a project group, you can use any of these project group names to launch jobs for this tutorial. <br> <br>
<b>Note</b>: If you only see the project group name `sandbox`, then you are not a part of a project group yet. We advise against using the `sandbox` account name for launching scripts in tutorials 6 and on, since only a very limited amount of computational resources will be available to you. <br> <br>
If you are <b>not</b> a part of a project group, you can request an account [here](https://scinet.usda.gov/support/request), and use the `sandbox` account name to complete the first 5 tutorials while your request is processing. <br><br>
Take note of the project group name you would like to use, as we will need it in the next section.

#### Picking a Project Directory
Next, decide on a project directory location. We recommend not using your home directory since you will quickly run out of space. Instead, we recommend either using `/90daydata/shared/$USER/whatever_subdirectory`, or a `/project/project_group_name/whatever_subdirectory` directory if you have one. Make a note of the directory you would like to use - in the following steps, we will create a `rastervision` directory here, and transfer the needed files to this directory.

#### Launching JupyterLab
Click on <b> Interactive Apps </b>, then <b>Jupyter</b>. <br>
![interactive_session.png](imgs/interactive_session.png) <br>
Input the following job specifications, replacing "Account Name" with your project group name, and "Working Directory" with the directory you chose above. You may also wish to change the number of hours based on how long you intend to work on this tutorial for now. <br>
- Working Directory: <b> path to desired project directory</b>, ie /90daydata/shared/$USER
- Account Name: <b> project group name</b>, ie geospatialworkshop
- Partition Name: atlas
- QOS: ood – Max Time: 8-00:00:00
- Number of hours: 4
- Number of nodes: 1
- Number of tasks: 1
- Additional Slurm Parameters: --mem=32gb

Then click the `Launch` button at the bottom of the page. Once your session loads, click the `Connect to Jupyter` button.

Once the jupyter session is launched, we will open up a terminal. Click the `+` button on the top left, above the navigation pane.<br>
![plus_button.png](imgs/plus_button.png)<br>
Then click on the `Terminal` button. <br>
![open_terminal.png](imgs/open_terminal.png) <br>

#### Setting Project Shell Variables
<b>Navigate to your project directory</b>, (ie with `cd /90daydata/shared/$USER`) and run the following two commands. This will create a directory called `rastervision/` for all of your Raster Vision tutorials and materials, and store the the path to this `rastervision/` directory into the shell variable `project_dir`. <br><br>
`mkdir rastervision` <br>
``project_dir=`pwd`/rastervision`` <br>

Then, run this command to store your project group name into a shell variable. If you are not a part of the geospatialworkshop project group, replace "geospatialworkshop" with the name of a project group you are a part of. <br>
`project_name="geospatialworkshop"`

#### Transferring Workshop Files to Project Directory
This workshop refers to files stored in the `/reference/workshops/rastervision` folder. We will only transfer some of the contents of `/reference/workshops/rastervision` to our project directory because some of the files are very large and can be referenced in-place.

Use the following commands to copy the reference files to your project directory. <br>
`cd $project_dir` <br>
`cp -r /reference/workshops/rastervision/model/ .` <br>
`cp -r /reference/workshops/rastervision/tutorial_notebooks/ .` <br>

Here, the `model/` directory contains all of our code to create our container and train our model. The `tutorial_notebooks` folder contains all of the jupyter notebooks for this series, in addition to the `imgs/` folder which includes images used in the tutorials.

#### Creating the Kernel

Run these commands in the terminal to create the jupyter kernel. You can copy and paste this entire block into your terminal. <br>
`source /reference/workshops/rastervision/rastervision_env/bin/activate` <br>
`module load python` <br>
`ipython kernel install --name "rastervision_env" --user` <br>
`cp /reference/workshops/rastervision/rastervision_env/rastervision_env.json ~/.local/share/jupyter/kernels/rastervision_env/kernel.json` <br>

#### Open Workbook

From the navigation pane on the left side of the screen, navigate to your `rastervision` directory.<br>
<br>
![open_workbook_directory.png](imgs/open_workbook_directory.png) <br>
Here, you will see the two folders you just copied over: `model/` and `tutorial_notebooks/`. Click on `tutorial_notebooks/`.
![rastervision_directory.png](imgs/rastervision_directory.png)

Here, you will see all of the Raster Vision tutorial notebooks including this notebook, and the `imgs/` directory. You can go ahead and open up all of the notebooks in the series if you'd like, or just open up the first few.<br>
![open_workbook.png](imgs/open_workbook.png) <br>

Lastly, set the kernel by clicking on the `Kernel` tab, selecting `Change Kernel...`, and then selecting the `rastervision_env` kernel. <br>
![change_kernel.png](imgs/change_kernel.png)
![select_kernel.png](imgs/select_kernel.PNG)

#### Conclusion
You are now all ready to work through this tutorial series! Next, now open up Raster_Vision_Part_2.ipynb to learn more about Deep Learning and the Raster Vision Pipeline.
Loading