weecology / weecology/DeepForest

Improve deepforest.utilities.read_file for reading a .shp that doesn't have a image_path column

Open
#997 1 comment 0 reactions 1 assignee View on GitHub

@bw4sz is already working on this.

Since Apr 2, 2025.

good first issue
Dominant language
Python
Stars
774
Forks
265
PR merge metrics
No merged PRs in 30d

Description

Reading in data is often the hardest thing for users, we want to help them as much as possible at this step.

>>> ground_truth = read_file("/Users/benweinstein/Downloads/data/individual_align.shp")
m = main.deepforest()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/benweinstein/Documents/DeepForest/src/deepforest/utilities.py", line 331, in read_file
    df = shapefile_to_annotations(input, root_dir=root_dir)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/benweinstein/Documents/DeepForest/src/deepforest/utilities.py", line 184, in shapefile_to_annotations
    raise ValueError(
ValueError: No image_path column found in shapefile, please specify rgb path
  1. We should allow users to pass an image_path to read_file. We currently have a root_dir argument, but no image_path argument.
  2. This assumes that all annotations in the file relate to the image_path, add a warning to make it clear.
  3. The same is true for the label column, should be an argument to read_file.
  4. Write tests for shapefiles, this is the common place we see this.
  5. Add an example to docs getting started for reading the file.

Current workaround

raster_path = "/Users/benweinstein/Downloads/data/SPA25_nogcp_crossrotate_aligned.tif"
gdf = gpd.read_file("/Users/benweinstein/Downloads/data/individual_align.shp")
gdf["image_path"] = os.path.basename(raster_path)
gdf["label"] = "Tree"
ground_truth = read_file(gdf, root_dir = os.path.dirname(raster_path))

This requires two unneeded library imports (os and geopandas) and supplies the root dir. The full versus relative path is an ongoing debate in DeepForest API and should not addressed here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.