- Clone the github repository to your local machine.
git clone [email protected]:byurk/model-dune.git-
Open up the project by navigating inside the directory and click
model-dune.Rproj. -
Restore the pinned package environment (
renvbootstraps itself on first open):
renv::restore()Done! Now you should be able to run the code in the project.
renv.lock pins R 4.3.2 and 208 packages to the CRAN state of 2024-06-13 — the day
outputs/xgb_model_final.rds was fit (see the "final model selection" commit). This is not
housekeeping; the saved model does not work on current packages:
- The fitted booster's
$rawisxgb.serialize()internal-state format, which needsxgb.Booster.complete()— a function removed in xgboost >= 2.0. Current xgboost cannot load this model at all. predict(workflow, new_data)additionally fails under current hardhat (blueprint drift).
With the pinned versions (xgboost 1.7.7.1, hardhat 1.4.0, parsnip 1.2.1, recipes 1.0.10),
predict() on the saved workflow just works — verified 99.1% on 5,000 labeled pixels.
Notes for anyone rebuilding this environment:
- The lock's repo is a dated Posit Package Manager snapshot, so
renv::restore()gets the same versions on any platform (binaries on Linux, sources/binaries elsewhere). vipandglcmare archived on CRAN today but are regular packages in that snapshot — another reason the date pin matters.- Data lives in gitignored
raw_data/,clean_data/,outputs/— symlink these to the project data (canonical copy on euler underproducts/SHNA/2019-07-05_grass_paper/).
The project is organized into the following directories:
-
code - Contains the modeling code in R scripts and quarto documents.
-
raw_data - Contains the features/images for the ground-based model and orthomosaic data for the drone-based model.
-
clean_data - Contains the classified images, the extracted pixels for training data, features for the orthomosaic.
-
outputs - Vegetation density map of the dune complex.
You should either create the raw_data, clean_data, and outputs directories and/or create symlinks to these directories (probably somewhere on Google Drive).
-
The training data for the ground-based model was extracted using labelme
- In the 50 RGB photographs (the 50 quadrats) polygons were drawn of the different surface compositions (sand, grass, dead vegetation, etc.) Each quadrat directory has a
polygons.jsonfile with the associated geometries and class labels. - The script
code/src/sample-all-ground-pixels.Rextracts the pixels from the polygons and saves them as a.rdsfile in theclean_datadirectory.
- In the 50 RGB photographs (the 50 quadrats) polygons were drawn of the different surface compositions (sand, grass, dead vegetation, etc.) Each quadrat directory has a
-
The ground-based model performs pixel based classification in the ground based imagery as grass, dead vegetation, and sand. The quarto document
code/ground-based-model.qmdcontains the code for this model.
- The model chosen is an xGBoost model, but any model can be used.
- Save the workflow and model (using tidymodel conventions) in
clean_data. - Run the script
code/src/classify-all-images.Rto classify all the images in theraw_datadirectory and save the classified images in theclean_datadirectory. This will save the classified quadrats inside a folder named after the model.
- Once a model is selected and the quadrats are classified, the drone-based model can be trained. The drone-based model uses the classified quadrats to predict the surface composition of the entire orthomosaic map. The quarto document
code/drone-based-model.qmdcontains the code for this model.
- The model chosen is a multinomial regression with regularization, but any model can be used.
- First run
code/src/generate-orthomsaic-features.Rto extract the features from the orthomosaic and save them in theclean_datadirectory. - Next, run
code/src/create-training-set.Rto createtraining.rdsthat contains coverage estimates from the close-up quadrats and the multispectral data from the drone-based quadarts. - Fit the multinomial regression model using data from
training.rds. - Save the workflow and model (using tidymodel conventions) in
clean_data. - Run the script
code/src/predict-orthomosaic.Rto predict the surface composition of the entire orthomosaic map and save the map in theoutputsdirectory.
Explore the training/testing data, follow single photograph (quadrat) through the ground-based model and the drone-based model.
Pixel based classification of ~50 close up photographs of Saugatuck Harbor Natural Area (SHNA) sand dune.
Multinomial regression with regularization predicting surface composition estimates from the ground-based model using multispectral drone imagery of SHNA.
Predicting surface composition across the entire stitched orthomosiac map of SHNA.