weecology / DeepForest

Python Package for Airborne RGB machine learning
https://deepforest.readthedocs.io/
MIT License
524 stars 177 forks source link

[TEST]: Pr813 #815

Open henrykironde opened 1 month ago

henrykironde commented 1 month ago

@Ben I tested the PR #813, With a few changes we were able to go from 11 failed to 3 failed. Some errors are here

tests/test_visualize.py::test_predict_image_and_plot FAILED                                                                                                  [100%]

============================================================================= FAILURES =============================================================================
___________________________________________________________________ test_predict_image_and_plot ____________________________________________________________________

m = deepforest(
  (model): RetinaNet(
    (backbone): BackboneWithFPN(
      (body): IntermediateLayerGetter(
        (con..._size=1333, mode='bilinear')
    )
  )
  (iou_metric): IntersectionOverUnion()
  (mAP_metric): MeanAveragePrecision()
)
tmpdir = local('/private/var/folders/5r/ggnt4_dx6_z0gspdn36dkprc0000gn/T/pytest-of-henrysenyondo/pytest-13/test_predict_image_and_plot0')

    def test_predict_image_and_plot(m, tmpdir):
        sample_image_path = get_data("OSBS_029.png")
        results = m.predict_image(path=sample_image_path)
>       visualize.plot_results(results, savedir=tmpdir)

tests/test_visualize.py:72: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
deepforest/visualize.py:485: in plot_results
    root_dir = results.root_dir
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self =      xmin   ymin   xmax   ymax label     score    image_path
0   330.0  342.0  373.0  391.0  Tree  0.802979  OSBS_029....    0.0  375.0    8.0  397.0  Tree  0.315891  OSBS_029.png
55  162.0  264.0  188.0  292.0  Tree  0.306989  OSBS_029.png
name = 'root_dir'

    @final
    def __getattr__(self, name: str):
        """
        After regular attribute access, try looking up the name
        This allows simpler access to columns for interactive use.
        """
        # Note: obj.x will always call obj.__getattribute__('x') prior to
        # calling obj.__getattr__('x').
        if (
            name not in self._internal_names_set
            and name not in self._metadata
            and name not in self._accessors
            and self._info_axis._can_hold_identifiers_and_holds_name(name)
        ):
            return self[name]
>       return object.__getattribute__(self, name)
E       AttributeError: 'DataFrame' object has no attribute 'root_dir'

/opt/miniconda3/envs/deepforest/lib/python3.11/site-packages/pandas/core/generic.py:6299: AttributeError
---------------------------------------------------------------------- Captured stdout setup -----------------------------------------------------------------------
running 

Another


tests/test_main.py::test_predict_image_fromarray FAILED                                                                                                                         [100%]

====================================================================================== FAILURES =======================================================================================
____________________________________________________________________________ test_predict_image_fromarray _____________________________________________________________________________

m = deepforest(
  (model): RetinaNet(
    (backbone): BackboneWithFPN(
      (body): IntermediateLayerGetter(
        (con..._size=1333, mode='bilinear')
    )
  )
  (iou_metric): IntersectionOverUnion()
  (mAP_metric): MeanAveragePrecision()
)

    def test_predict_image_fromarray(m):
        image_path = get_data(path="2019_YELL_2_528000_4978000_image_crop2.png")

        # assert error of dtype
        with pytest.raises(TypeError):
            image = Image.open(image_path)
            prediction = m.predict_image(image=image)

        image = np.array(Image.open(image_path).convert("RGB"))
        with pytest.warns(UserWarning, match="Image type is uint8, transforming to float32"):
>           prediction = m.predict_image(image=image)

tests/test_main.py:231: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
deepforest/main.py:418: in predict_image
    results = utilities.read_file(result)
deepforest/utilities.py:318: in read_file
    return shapefile_to_annotations(input, root_dir=root_dir)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

shapefile =       xmin    ymin    xmax    ymax label     score                                           geometry
0   1695.0  2265...25, 378 18, 73...
44    28.0  1083.0   586.0  1722.0  Tree  0.103576  POLYGON ((586 1083, 586 1722, 28 1722, 28 1083...
rgb = None, root_dir = None, buffer_size = None, convert_point = False, geometry_type = None, save_dir = None

    def shapefile_to_annotations(shapefile,
                                 rgb=None,
                                 root_dir=None,
                                 buffer_size=None,
                                 convert_point=False,
                                 geometry_type=None,
                                 save_dir=None):
        """Convert a shapefile of annotations into annotations csv file for
        DeepForest training and evaluation.

        Args:
            shapefile: Path to a shapefile on disk. If a label column is present, it will be used, else all labels are assumed to be "Tree"
            rgb: Path to the RGB image on disk
            root_dir: Optional directory to prepend to the image_path column
        Returns:
            results: a pandas dataframe
        """
        # Deprecation of previous arguments
        if geometry_type:
            warnings.warn(
                "geometry_type argument is deprecated and will be removed in DeepForest 2.0. The function will infer geometry from the shapefile directly.",
                DeprecationWarning)
        if save_dir:
            warnings.warn(
                "save_dir argument is deprecated and will be removed in DeepForest 2.0. The function will return a pandas dataframe instead of saving to disk.",
                DeprecationWarning)

        # Read shapefile
        if isinstance(shapefile, str):
            gdf = gpd.read_file(shapefile)
        else:
            gdf = shapefile.copy(deep=True)

        if rgb is None:
            if "image_path" not in gdf.columns:
>               raise ValueError(
                    "No image_path column found in shapefile, please specify rgb path")
E               ValueError: No image_path column found in shapefile, please specify rgb path

deepforest/utilities.py:189: ValueError