Deci-AI / data-gradients

Computer Vision dataset analysis
Apache License 2.0
293 stars 33 forks source link

Feature/sg 953 simplify iterator logic #132

Closed Louis-Dupont closed 1 year ago

Louis-Dupont commented 1 year ago

What this PR is about

MergingImageLabelFilesIterator and ImageLabelConfigIterator into ImageLabelFilesIterator. I did nothing but merging the two classes. Eventually ImageLabelFilesIterator will work similarly to ImageLabelConfigIterator, except that if config_path is None, it will still work as it used to previously.

Motivation

When implementing new datasets, I realized that in lots of cases I wrote the following code:

        if config_path is None:
            self.image_label_tuples = ImageLabelFilesIterator(
                images_dir=os.path.join(root_dir, images_subdir),
                labels_dir=os.path.join(root_dir, labels_subdir),
                image_extensions=image_extensions,
                label_extensions=label_extensions,
                verbose=verbose,
            )
        else:
            self.image_label_tuples = ImageLabelConfigIterator(
                images_dir=os.path.join(root_dir, images_subdir),
                labels_dir=os.path.join(root_dir, labels_subdir),
                config_path=os.path.join(root_dir, config_path),
                image_extensions=image_extensions,
                label_extensions=label_extensions,
                verbose=verbose,
            )

So I realized that we should not have two classes for this, but just one.

            self.image_label_tuples = ImageLabelFilesIterator(
                images_dir=os.path.join(root_dir, images_subdir),
                labels_dir=os.path.join(root_dir, labels_subdir),
                config_path=os.path.join(root_dir, config_path) if config_path is not None else None,
                image_extensions=image_extensions,
                label_extensions=label_extensions,
                verbose=verbose,
            )