Uses Python's open_clip through reticulate. You do not need to install
anything in Python yourself: the first call sets up a private Python with
the packages dimoose needs (torch, open_clip_torch, pillow, numpy)
and reuses it afterwards. That first call downloads them, which takes a
few minutes. This needs reticulate 1.41 or later.
Arguments
- weights
Local checkpoint file: OpenAI's
ViT-B-32.pt, or an open_clip checkpoint for the architecturename. IfNULL, the weights are downloaded.- name
The model: an open_clip architecture name,
"bioclip","bioclip-2","hf-hub:<organisation>/<model>"or"local-dir:<folder>"(see below).- pretrained
open_clip's tag for the weights to download for an architecture
name; not used for the other kinds ofname.- python
Optional path to the Python executable to use (passed to
reticulate::use_python()).
Value
An object of class dimooseVisionModel with py (the Python model)
and spec (library, architecture, weights SHA-256, image size, ...).
Details
To use a Python of your own instead, give its path in python, or select
it with reticulate::use_python(), reticulate::use_virtualenv() or the
RETICULATE_PYTHON environment variable before the first call, and install
the packages there with
reticulate::py_install(c("torch", "open_clip_torch", "pillow", "numpy")).
Other models, including BioCLIP
Any open_clip model whose image side is a vision transformer works. The key builders only see its embeddings, so nothing else changes.
visionModel(name = "bioclip")loads BioCLIP andvisionModel(name = "bioclip-2")BioCLIP 2, models trained on images of organisms, from the Hugging Face Hub. They are downloaded on first use.name = "hf-hub:<organisation>/<model>"loads any other open_clip model on the Hub, andname = "local-dir:<folder>"a copy you have downloaded (the folder holds the model'sopen_clip_config.jsonand weights file).nameandpretrainedtogether select one of open_clip's built-in models, e.g.name = "ViT-B-16", pretrained = "laion2b_s34b_b88k".
A key can only be followed with the model it was built with: use the same
model for embedImages() and later for scoreImages().
BioCLIP's text side was trained on names of organisms, not on descriptions
of what they look like. It suits sniglets (discoverSniglets()), which use
images only, better than vocabulary questions (keyFromClusters()).