meerqat.image.embedding module#

Usage: embedding.py <dataset> [<config> –disable_caching –output=<path>]

Options: –disable_caching Disables Dataset caching (useless when using save_to_disk), see datasets.set_caching_enabled() –output=<path> Optionally save the resulting dataset there instead of overwriting the input dataset.

class meerqat.image.embedding.ImageEncoder(encoder, pool)[source]#

Bases: Module

Simply encode and pool the features

forward(x)[source]#

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

meerqat.image.embedding.get_nn_module(Class_name, *args, **kwargs)[source]#
meerqat.image.embedding.from_pretrained(model_name='resnet50', imagenet=True, pretrained_model_path=None, **kwargs)[source]#

Notes

For models trained on other dataset than imagenet, don’t forget to pass the right num_classes in kwargs

Examples

To load from a Places365 checkpoint, first process the state_dict as this: >>> checkpoint = torch.load(“resnet50_places365.pth.tar”, map_location=”cpu”) >>> state_dict = {str.replace(k,’module.’,’’): v for k,v in checkpoint[‘state_dict’].items()} >>> torch.save(state_dict, “resnet50_places365_state_dict.pth”)

meerqat.image.embedding.get_encoder(torchvision_model)[source]#

Keep only convolutional layers (i.e. remove final pooling and classification layers)

meerqat.image.embedding.get_torchvision_model(pretrained_kwargs={}, pool_kwargs={})[source]#

Get model pre-trained on ImageNet or Places365

meerqat.image.embedding.get_transform(resize_kwargs={'size': 224}, crop_size=224, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])[source]#
meerqat.image.embedding.get_model_and_transform(model_kwargs={}, transform_kwargs={})[source]#
meerqat.image.embedding.embed(batch, model, transform, save_as='image_embedding', image_key='image', call=None, pool=None)[source]#
meerqat.image.embedding.dataset_embed(dataset_path, map_kwargs={}, model_kwargs={}, transform_kwargs={}, output_path=None, keep_columns=None, processes=None, **fn_kwargs)[source]#