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

DetectionBaseModel label method throws AttributeError when sahi True #107

Closed
2 tasks done
tomgause opened this issue Dec 24, 2023 · 2 comments · Fixed by #108
Closed
2 tasks done

DetectionBaseModel label method throws AttributeError when sahi True #107

tomgause opened this issue Dec 24, 2023 · 2 comments · Fixed by #108
Labels
bug Something isn't working

Comments

@tomgause
Copy link

Search before asking

  • I have searched the Autodistill issues and found no similar bug report.

Bug

Description:
While using the base model in Autodistill for image labeling with SAHI, passing a file path (string) instead of an image object to Supervision InferenceSlicer results in an AttributeError. This issue occurs in the label method of DetectionBaseModel when sahi is set to True.

Error Stack Trace:

{
	"name": "AttributeError",
	"message": "'str' object has no attribute 'shape'",
	"stack": "---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 6
      2 from autodistill.detection import CaptionOntology
      4 base_model = GroundingDINO(ontology=CaptionOntology({\"milk bottle\": \"bottle\", \"milk bottle cap\": \"bottle cap\"}))
----> 6 base_model.label(
      7   input_folder=\"./images\",
      8   output_folder=\"./dataset\",
      9   sahi=True
     10 )

File c:\\users\\tomsg\\work\\open-source\\autodistill\\autodistill\\autodistill\\detection\\detection_base_model.py:66, in DetectionBaseModel.label(self, input_folder, extension, output_folder, human_in_the_loop, roboflow_project, roboflow_tags, sahi)
     63 images_map[f_path_short] = image.copy()
     65 if sahi:
---> 66     detections = slicer(f_path)
     67 else:
     68     detections = self.predict(f_path)

File c:\\Users\\tomsg\\Work\\open-source\\autodistill\\.venv\\Lib\\site-packages\\supervision\\detection\\tools\\inference_slicer.py:98, in InferenceSlicer.__call__(self, image)
     66 \"\"\"
     67 Performs slicing-based inference on the provided image using the specified
     68     callback.
   (...)
     95     ```
     96 \"\"\"
     97 detections_list = []
---> 98 resolution_wh = (image.shape[1], image.shape[0])
     99 offsets = self._generate_offset(
    100     resolution_wh=resolution_wh,
    101     slice_wh=self.slice_wh,
    102     overlap_ratio_wh=self.overlap_ratio_wh,
    103 )
    105 with ThreadPoolExecutor(max_workers=self.thread_workers) as executor:

AttributeError: 'str' object has no attribute 'shape'"
}

Environment

  • Autodistill: commit 0b90409 (built from source)
  • Supervision: 0.17.1
  • Python: 3.11.3
  • OS: Microsoft Windows 11 Pro for Workstations

Minimal Reproducible Example

Steps to Reproduce:

  1. Initialize GroundingDINO with a custom ontology in Autodistill.
  2. Call base_model.label with the sahi flag set to True.
  3. Encounter AttributeError due to string input instead of image object.
from autodistill_grounding_dino import GroundingDINO
from autodistill.detection import CaptionOntology

base_model = GroundingDINO(ontology=CaptionOntology({"milk bottle": "bottle", "milk bottle cap": "bottle cap"}))

base_model.label(
  input_folder="./images",
  output_folder="./dataset",
  sahi=True
)

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@tomgause tomgause added the bug Something isn't working label Dec 24, 2023
@tomgause tomgause changed the title Label with SAHI throws AttributeError DetectionBaseModel label method throws AttributeError when sahi True Dec 24, 2023
@capjamesg capjamesg mentioned this issue Dec 28, 2023
@capjamesg
Copy link
Member

I have a PR in the works to fix this bug. I will post here when the PR is merged and live in the autodistill package.

Please note that it will take a long time to run SAHI with Grounding DINO. This is because SAHI splits up an image into multiple frames and runs inference on each of them.

We recommend trying to run Grounding DINO without SAHI to label your images first. If you have a small dataset with a large number of small objects that Grounding DINO can identify, SAHI might be helpful!

@tomgause
Copy link
Author

Neat, thank you. I ended up making an edit in my local fork and did use SAHI to get some interesting results on my dataset with small objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants