This repository is for AnyLoc's release on Torch Hub.
Please see: anyloc.github.io or the main AnyLoc repository for the actual work.
Note: This is a work-in-progress (not ready for public release yet), mainly for internal use. Please don't use it if you're not in the AnyLoc team. Use
force_reload = Truewhile the API is unstable.
Please open issues about this work in AnyLoc/AnyLoc with label torch.hub
Install the following
pip install einops # Codebase uses this
pip install fast_pytorch_kmeans # For VLAD codebaseBasic usage (pass in the domain, backbone, and set the device to cuda for
using a GPU)
importtorchmodel=torch.hub.load("AnyLoc/DINO", "get_vlad_model", domain="indoor", backbone="DINOv2", device="cuda")
# Imagesimg=torch.rand(1, 3, 224, 224)
# Result: VLAD descriptors of shape [1, 49152]res=model(img)It also supports batching
# Imagesimg=torch.rand(16, 3, 224, 224)
# Result: VLAD descriptors of shape [16, 49152]res=model(img)You can get more help from
# List of functionsprint(torch.hub.list("AnyLoc/DINO"))
# Help about an individual function - like "get_vlad_model"r=torch.hub.help("AnyLoc/DINO", "get_vlad_model")
print(r)This is to use your own dataset for calculating the VLAD clusters
importeinopsasein# Load modelmodel=torch.hub.load("AnyLoc/DINO", "get_vlad_model", domain=None, backbone="DINOv2", device="cuda")
# Extract featuresimgs=torch.rand(16, 3, 224, 224) # Database imagesres=model.extract(imgs)
res_all=ein.rearrange(res, "B N D -> (B N) D")
# Fit VLAD (to get cluster centers)model.fit(res_all)
# Get the descriptorsimg=torch.rand(1, 3, 224, 224) # Inference imagesgd=model(img) # Global descriptors- AnyLoc-VLAD-DINOv2
- AnyLoc-VLAD-DINO
- AnyLoc-VLAD-DINOv2-PCA
- AnyLoc-VLAD-DINO-PCA