autodistill / autodistill-llava

LLaVA base model for use with Autodistill.
https://docs.autodistill.com
Apache License 2.0
6 stars 2 forks source link

xyxy coordinates are not absolute #5

Open egnerfl opened 7 months ago

egnerfl commented 7 months ago

First of all, thanks for creating the repo!

While playing around with autodistill I noticed that llava always returns relative coordinates which can't be displayed by supervision out of the box. I guess these just need to be converted to absolute values.

This should do the job:

image = Image.open(SAMPLE_IMAGE)

# # Transform detection bounding boxes from percentage to absolute coordinates
# for detection in results.xyxy:
#     detection[0] *= image.width
#     detection[1] *= image.height
#     detection[2] *= image.width
#     detection[3] *= image.height
Samuel5106 commented 3 months ago

First of all, thanks for creating the repo!

While playing around with autodistill I noticed that llava always returns relative coordinates which can't be displayed by supervision out of the box. I guess these just need to be converted to absolute values.

This should do the job:

image = Image.open(SAMPLE_IMAGE)

# # Transform detection bounding boxes from percentage to absolute coordinates
# for detection in results.xyxy:
#     detection[0] *= image.width
#     detection[1] *= image.height
#     detection[2] *= image.width
#     detection[3] *= image.height

Hi, @egnerfl is the llava (autodstill code is working) I am facing an error while I am passing the images folder can you help me with this?

AttributeError Traceback (most recent call last) File ~/.pyenv/versions/3.8.0/lib/python3.8/site-packages/PIL/Image.py:3222, in open(fp, mode, formats) 3221 try: -> 3222 fp.seek(0) 3223 except (AttributeError, io.UnsupportedOperation):

AttributeError: 'numpy.ndarray' object has no attribute 'seek'

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last) Cell In[2], line 18 8 base_model = LLaVA( 9 ontology=CaptionOntology( 10 { (...) 13 ) 14 ) 16 # base_model.label("/home/aiteam/data1/samuel/test_images_for_each_model/may2_test_images_for_ilava", extension=".jpg") ---> 18 base_model.label(input_folder="/home/aiteam/data1/samuel/test_images_for_each_model/may2_test_images_for_ilava", extension=".jpg")

File ~/.pyenv/versions/3.8.0/lib/python3.8/site-packages/autodistill/detection/detection_base_model.py:99, in DetectionBaseModel.label(self, input_folder, extension, output_folder, human_in_the_loop, roboflow_project, roboflow_tags, sahi, record_confidence, nms_settings) 97 detections = slicer(image) 98 else: ---> 99 detections = self.predict(image) 101 if nms_settings == NmsSetting.CLASS_SPECIFIC: 102 detections = detections.with_nms()

File ~/.pyenv/versions/3.8.0/lib/python3.8/site-packages/autodistill_llava/model.py:97, in LLaVA.predict(self, input) 96 def predict(self, input: str) -> sv.Detections: ---> 97 image = Image.open(input) 99 # image = Image.fromarray(input) 101 ImageInfo = namedtuple('ImageInfo', ['image_aspect_ratio'])

File ~/.pyenv/versions/3.8.0/lib/python3.8/site-packages/PIL/Image.py:3224, in open(fp, mode, formats) 3222 fp.seek(0) 3223 except (AttributeError, io.UnsupportedOperation): -> 3224 fp = io.BytesIO(fp.read()) 3225 exclusive_fp = True 3227 prefix = fp.read(16)

AttributeError: 'numpy.ndarray' object has no attribute 'read'