Deci-AI / data-gradients

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

Introduction of `InitAwareRepr` Mixin for Enhanced Object Representations #188

Closed Louis-Dupont closed 1 year ago

Louis-Dupont commented 1 year ago

Description

This PR introduces a new mixin, InitAwareRepr, aimed at providing more informative and concise string representations (__repr__) of objects. I only used it for FeatureExtractor because this is the original target of such a feature.

Motivation

When debugging or logging, it's often useful to know an object's initialization parameters. The default __repr__ might not always capture these details, making it harder to understand an object's state at a glance.

This is especially useful when we print the features that are used for the analysis, at the beginning. I think it increase transparency of what we are doing, and how it could be modified. This could also be added to the logs to know how the features were initialized.

Features

Example Usage

class ExampleClass(InitAwareRepr):
    def __init__(self, x, y):
        self.x = x
        self.y = y

e = ExampleClass(1, 2)
print(e)  # Outputs: ExampleClass(x=1, y=2)

This ensures that whenever we print or log instances of classes using the InitAwareRepr mixin, we get a clearer view of their state based on their initialization parameters.

Notes

What do you think? Feel free to be harsh on such a feature, I want a honest opinion