Skip to content

Processor num_crops=0 causing "ValueError: height and width must be > 0" #105

@hm-ca

Description

@hm-ca

Hi Team,

When I set num_crops=0 I get the error: "ValueError: height and width must be > 0". Full error is below....
my images are square and small (less than 336x336) already and I don't want to crop them any further for training in order to keep the memory footprint in check and to be able to pack as many together in my batch as possible.

Anyway, I feel that num_crops=0 should be an acceptable value.

Moreover, I noticed while displaying the crops returned by the processor that for num_crops=1, the returned crop is always blank which almost double the memory requirements per sample/batch for no good reason. (double because the processor returns the original image and the blank crop)

Also, based on additional and limited testing, only values like num_crops = 4 and 16 appear to return actual non blank crops!

What am I missing?

Thanks!

=================================
Full error is here:
File "/home/ubuntu/content/mycode-finetune-phi3v.py", line 669, in call
inputs = self.processor(prompt, frames, return_tensors='pt')
File "/home/ubuntu/.cache/huggingface/modules/transformers_modules/microsoft/Phi-3-vision-128k-instruct/866d1691437a49af79d5f3ad4a34c1750e08d163/processing_phi3_v.py", line 113, in call
image_inputs = self.image_processor(images, return_tensors=return_tensors)
File "/home/ubuntu/.local/lib/python3.10/site-packages/transformers/image_processing_utils.py", line 551, in call
return self.preprocess(images, **kwargs)
File "/home/ubuntu/.cache/huggingface/modules/transformers_modules/microsoft/Phi-3-vision-128k-instruct/866d1691437a49af79d5f3ad4a34c1750e08d163/image_processing_phi3_v.py", line 245, in preprocess
elems = [HD_transform(im, hd_num = self.num_crops) for im in images]
File "/home/ubuntu/.cache/huggingface/modules/transformers_modules/microsoft/Phi-3-vision-128k-instruct/866d1691437a49af79d5f3ad4a34c1750e08d163/image_processing_phi3_v.py", line 245, in
elems = [HD_transform(im, hd_num = self.num_crops) for im in images]
File "/home/ubuntu/.cache/huggingface/modules/transformers_modules/microsoft/Phi-3-vision-128k-instruct/866d1691437a49af79d5f3ad4a34c1750e08d163/image_processing_phi3_v.py", line 82, in HD_transform
img = torchvision.transforms.functional.resize(img, [new_h, new_w],)
File "/home/ubuntu/.local/lib/python3.10/site-packages/torchvision/transforms/functional.py", line 490, in resize
return F_pil.resize(img, size=output_size, interpolation=pil_interpolation)
File "/home/ubuntu/.local/lib/python3.10/site-packages/torchvision/transforms/_functional_pil.py", line 250, in resize
return img.resize(tuple(size[::-1]), interpolation)
File "/home/ubuntu/.local/lib/python3.10/site-packages/PIL/Image.py", line 2008, in resize
return self._new(self.im.resize(size, resample, box))
ValueError: height and width must be > 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions