Skip to content

bbuchsbaum/imfeatures

Repository files navigation

imfeatures

R-CMD-check Codecov coverage

The goal of imfeatures is to …

Get started

Install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("bbuchsbaum/imfeatures")

Cookbook

This is a basic example which shows you how to solve a common problem:

library(imfeatures)
## basic example code
im1 = "testdata/1_A_1.jpeg"
im2 = "testdata/1_B_1.jpeg"

im_feature_sim(c(im1,im2), layers=c(1,2,3))
#> [========================================================================================] 100%
#> $layer_1
#>            1_A_1.jpeg 1_B_1.jpeg
#> 1_A_1.jpeg  0.0000000  0.3326229
#> 1_B_1.jpeg  0.3326229  0.0000000
#> 
#> $layer_2
#>            1_A_1.jpeg 1_B_1.jpeg
#> 1_A_1.jpeg    0.00000    0.37037
#> 1_B_1.jpeg    0.37037    0.00000
#> 
#> $layer_3
#>            1_A_1.jpeg 1_B_1.jpeg
#> 1_A_1.jpeg  0.0000000  0.4695186
#> 1_B_1.jpeg  0.4695186  0.0000000

HPC Quickstart (single recommended path)

On HPC systems, avoid automatic Conda setup and use an existing Python instead.

  1. Disable auto Python setup during load (recommended on HPC):
Sys.setenv(IMFEATURES_SKIP_PYTHON = "TRUE")

To make this permanent, add IMFEATURES_SKIP_PYTHON=TRUE to ~/.Renviron.

  1. Create or choose a Python environment (module + venv is typical):
# Example using your cluster's Python module
module load python/3.10             # if applicable (3.9/3.10 recommended)
python -m venv $WORK/venvs/imfeatures
source $WORK/venvs/imfeatures/bin/activate
pip install --upgrade pip wheel setuptools

# Minimal required packages
pip install Pillow numpy

# Optional packages for full functionality
pip install thingsvision resmem open-clip-torch

# PyTorch: use your cluster's module if available, otherwise pick one index
# CPU only:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
# or CUDA-specific (example):
# pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118

Note on Python versions: some optional packages (e.g., thingsvision via numba)
currently do not support Python 3.11+. Prefer Python 3.9 or 3.10 when you plan
to use these features.
  1. Tell imfeatures to use that Python:
library(imfeatures)
use_existing_python("$WORK/venvs/imfeatures/bin/python")

Alternatively, set once in ~/.Renviron and it will be auto-detected:

RETICULATE_PYTHON=$WORK/venvs/imfeatures/bin/python
IMFEATURES_SKIP_PYTHON=TRUE
  1. Verify:
reticulate::py_config()

Troubleshooting:

  • If you see a Conda error like “bad interpreter” during library(imfeatures), it’s usually a broken R-miniconda on shared filesystems. Use the HPC Quickstart above or set IMFEATURES_SKIP_PYTHON=TRUE and call use_existing_python().
  • To force virtualenv instead of Conda during imfeatures_config(), set IMFEATURES_METHOD=virtualenv before calling it.

About

image feature representations from neural network models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •