Datasets - aspect ratio grouping & get_get_height_and_width

In the TorchVision Finetuning tutorial, it was mentioned that ‘’‘get_height_and_width’’’ method should be implemented as part of the PyTorch dataset, when aspect-ratio grouping is implemented. I’ve searched the web for examples of such datasets with that method, but could not find any. Do you have an example of such datasets implementations? I wish to see how to aspect ration grouping and the get_height_and_width are commonly implemented.

thanks

3 Likes

Hello @HyamsG ,
(Sorry for bumping an old thread.)
I came across the same question today. I used the fine-tuning tutorial with my own custom dataset and saw a prompt asking me to implement get_height_and_width.
The structure of the get_height_and_width function can be inferred from the tutorial’s group_by_aspect_ratio.py, in particular its _compute_aspect_ratios_custom_dataset() where it reads height, width = dataset.get_height_and_width(i).
In my case, I simply implemented like so:

    def get_height_and_width(self,idx):
        return self.img_data[idx]['height'],self.img_data[idx]['width']

which works for me so far.

Can’t answer on benefits of aspect ratio grouping and whether it’s commonly used.