idealo / imagededup

😎 Finding duplicate images made easy!
https://idealo.github.io/imagededup/
Apache License 2.0
5.18k stars 459 forks source link

Skip model download on import #200

Open bogdan-galileo opened 1 year ago

bogdan-galileo commented 1 year ago

Importing PHash causes the import of the CNN class and triggers the download of the Mobilenet model from torchvision.

Screenshot 2023-07-26 at 3 25 33 PM

Although very small, it's just and extra log that can be distracting in applications.

Can I get rid of it ? This was just introduced in the PR https://github.com/idealo/imagededup/pull/190

It seems to be caused by the import of the class CNN from imagededup.methods.cnn, which downloads the model as part as evaluating the default argument of __init__.

nibnahzuh commented 3 weeks ago

You can do as follow:

def __init__(
    self,
    verbose: bool = True,
    model_config: CustomModel = CustomModel()

    # model_config: CustomModel = CustomModel(
    #     model=MobilenetV3(), transform=MobilenetV3.transform, name=MobilenetV3.name
    # ),

And manually select the downloaded model like: https://github.com/idealo/imagededup/blob/master/examples/use_custom_model.ipynb