autodistill / autodistill-llava

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

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

Open Samuel5106 opened 4 months ago

Samuel5106 commented 4 months ago

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' Collecting transformers==4.38 Downloading transformers-4.38.0-py3-none-any.whl (8.5 MB) |████████████████████████████████| 8.5 MB 1.1 MB/s
Requirement already satisfied: huggingface-hub<1.0,>=0.19.3 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from transformers==4.38) (0.22.2) Requirement already satisfied: filelock in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from transformers==4.38) (3.14.0) Collecting tokenizers<0.19,>=0.14 Downloading tokenizers-0.15.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB) |████████████████████████████████| 3.6 MB 28.4 MB/s
Requirement already satisfied: tqdm>=4.27 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from transformers==4.38) (4.66.2) Requirement already satisfied: regex!=2019.12.17 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from transformers==4.38) (2024.4.28) Requirement already satisfied: packaging>=20.0 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from transformers==4.38) (24.0) Requirement already satisfied: requests in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from transformers==4.38) (2.31.0) Requirement already satisfied: safetensors>=0.4.1 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from transformers==4.38) (0.4.3) Requirement already satisfied: numpy>=1.17 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from transformers==4.38) (1.24.4) Requirement already satisfied: pyyaml>=5.1 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from transformers==4.38) (6.0.1) Requirement already satisfied: fsspec>=2023.5.0 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from huggingface-hub<1.0,>=0.19.3->transformers==4.38) (2024.3.1) Requirement already satisfied: typing-extensions>=3.7.4.3 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from huggingface-hub<1.0,>=0.19.3->transformers==4.38) (4.11.0) Requirement already satisfied: charset-normalizer<4,>=2 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from requests->transformers==4.38) (3.3.2) Requirement already satisfied: urllib3<3,>=1.21.1 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from requests->transformers==4.38) (1.26.18) Requirement already satisfied: certifi>=2017.4.17 in /home/aiteam/.pyenv/versions/3.8.0/lib/python3.8/site-packages (from requests->transformers==4.38) (2023.7.22) Requirement already sa

LLAVA_code_ss

Samuel5106 commented 4 months ago

can anyone help me with this issue

privvyledge commented 3 days ago

I just ran into a similar issue and it's due to line 97 in autodistill-llava (https://github.com/autodistill/autodistill-llava/blob/main/autodistill_llava/model.py#L97) Image.open(input) expecting a string/Path/byte object. However, autodistill's label method passes in a numpy.ndarray object which leads to the error. One solution is to overwrite autodistill's label method/function (https://github.com/autodistill/autodistill/blob/main/autodistill/detection/detection_base_model.py#L94) with yours and add a condition for llava and pass in images_map[f_path_short] = f_path instead of images_map[f_path_short] = image.copy()