From a43369a565f42e36c6c1f9415c90886345c933aa Mon Sep 17 00:00:00 2001 From: Henry Senyondo Date: Sun, 31 Mar 2024 22:02:57 -0400 Subject: [PATCH] Use deepforest config file and deepforest's boxes_to_shapefile --- deepforest_config.yml | 40 +++++++++++++++++++++++++++++++++++ everglades_dryrun_workflow.sh | 6 +++--- everglades_workflow.sh | 2 +- predict.py | 31 --------------------------- 4 files changed, 44 insertions(+), 35 deletions(-) create mode 100644 deepforest_config.yml diff --git a/deepforest_config.yml b/deepforest_config.yml new file mode 100644 index 0000000..30211be --- /dev/null +++ b/deepforest_config.yml @@ -0,0 +1,40 @@ +# Config file for DeepForest pytorch module + +# Cpu workers for data loaders +# Dataloaders +workers: 1 +devices: 1 +accelerator: 'gpu' +batch_size: 1 + +# Model Architecture +architecture: 'retinanet' +num_classes: 1 +nms_thresh: 0.05 + +# Architecture specific params +retinanet: + # Non-max supression of overlapping predictions + score_thresh: 0.1 + +train: + csv_file: + root_dir: + + # Optimizer initial learning rate + lr: 0.001 + + # Print loss every n epochs + epochs: 1 + # Useful debugging flag in pytorch lightning, set to True to get a single batch of training to test settings. + fast_dev_run: False + # pin images to GPU memory for fast training. This depends on GPU size and number of images. + preload_images: False + +validation: + # callback args + csv_file: + root_dir: + # Intersection over union evaluation + iou_threshold: 0.4 + val_accuracy_interval: 20 \ No newline at end of file diff --git a/everglades_dryrun_workflow.sh b/everglades_dryrun_workflow.sh index 941f9a8..09361d8 100644 --- a/everglades_dryrun_workflow.sh +++ b/everglades_dryrun_workflow.sh @@ -3,7 +3,7 @@ #SBATCH --mail-user=henrysenyondo@ufl.edu #SBATCH --mail-type=FAIL #SBATCH --gpus=a100:1 -#SBATCH --cpus-per-task=10 +#SBATCH --cpus-per-task=3 #SBATCH --mem=200gb #SBATCH --time=01:30:00 #SBATCH --partition=gpu @@ -23,5 +23,5 @@ cd /blue/ewhite/everglades/EvergladesTools/Zooniverse snakemake --unlock echo "INFO [$(date "+%Y-%m-%d %H:%M:%S")] Starting Snakemake pipeline" -snakemake --printshellcmds --keep-going --cores 10 --resources gpu=1 --rerun-incomplete --latency-wait 1 --use-conda -echo "INFO [$(date "+%Y-%m-%d %H:%M:%S")] End" \ No newline at end of file +snakemake --printshellcmds --keep-going --cores 3 --resources gpu=1 --rerun-incomplete --latency-wait 1 --use-conda +echo "INFO [$(date "+%Y-%m-%d %H:%M:%S")] End" diff --git a/everglades_workflow.sh b/everglades_workflow.sh index 7fdcb06..ddc715c 100644 --- a/everglades_workflow.sh +++ b/everglades_workflow.sh @@ -23,4 +23,4 @@ cd /blue/ewhite/everglades/EvergladesTools/Zooniverse snakemake --unlock echo "INFO [$(date "+%Y-%m-%d %H:%M:%S")] Starting Snakemake pipeline" snakemake --printshellcmds --keep-going --cores 30 --resources gpu=1 --rerun-incomplete --latency-wait 10 --use-conda -echo "INFO [$(date "+%Y-%m-%d %H:%M:%S")] End" \ No newline at end of file +echo "INFO [$(date "+%Y-%m-%d %H:%M:%S")] End" diff --git a/predict.py b/predict.py index a27ceb8..9070352 100644 --- a/predict.py +++ b/predict.py @@ -11,37 +11,6 @@ from deepforest.utilities import boxes_to_shapefile -def project(raster_path, boxes): - """ - Convert image coordinates into a geospatial object to overlap with input image. - Args: - raster_path: path to the raster .tif on disk. Assumed to have a valid spatial projection - boxes: a prediction pandas dataframe from deepforest.predict_tile() - Returns: - a geopandas dataframe with predictions in input projection. - """ - with rasterio.open(raster_path) as dataset: - bounds = dataset.bounds - pixelSizeX, pixelSizeY = dataset.res - - # subtract origin. Recall that numpy origin is top left! Not bottom left. - boxes["xmin"] = (boxes["xmin"] * pixelSizeX) + bounds.left - boxes["xmax"] = (boxes["xmax"] * pixelSizeX) + bounds.left - boxes["ymin"] = bounds.top - (boxes["ymin"] * pixelSizeY) - boxes["ymax"] = bounds.top - (boxes["ymax"] * pixelSizeY) - - # create geometry column - boxes['geometry'] = boxes.apply(lambda x: shapely.geometry.box(x.xmin, x.ymin, x.xmax, x.ymax), axis=1) - - # drop unnecessary columns - boxes = boxes.drop(columns=['xmin', 'ymin', 'xmax', 'ymax']) - - # Create a GeoDataFrame - gdf = geopandas.GeoDataFrame(boxes, geometry='geometry') - - return gdf - - def run(proj_tile_path, checkpoint_path, savedir="."): """Apply trained model to a drone tile"""