Navigation
System Requirements
Contents:
Computer
MATLAB
Toolboxes
-------------------- Optional --------------------
Bio-Formats
BMxD filters
DipLib library
Edge Enhancing Coherence Filter
Fiji
Frangi Filter
Imaris
Membrane Click Tracker
Omero Server
Random Forest Classifier
Read NRRD
Segment-anything model
Supervoxels/Graphcut
Volume Rendering

Contents

General information
Segment-anything model (SAM) is developed by Meta AI Research, FAIR research team. It can be used to segment individual objects or the whole image using a single mouse click. Details of the research is available here: https://segment-anything.com
Implementation of SAM in MIB is done via utilization of an external Python interpreter, please follow the following steps to configure local python environment to work in MIB.
Important! even though SAM can work on CPU, GPU is highly recommended as it is x30-60 faster.

Reference
  • Alexander Kirillov, Eric Mintun, Nikhila Ravi, Hanzi Mao, Chloe Rolland, Laura Gustafson, Tete Xiao, Spencer Whitehead, Alexander C. Berg, Wan-Yen Lo, Piotr Dollar, Ross Girshick
    Segment Anything
    arXiv:2304.02643, https://doi.org/10.48550/arXiv.2304.02643

Requirements
  • MATLAB R2022a or newer (tested on R2022a, R2022b, R2023a)
  • Python 3.8, 3.9, 3.10; tested on 3.9
  • List of Python versions compatible with various MATLAB releases
  • CUDA-compatible GPU is highly recommended, CPU can also be used but it is significantly slower

Installation on Linux
SAM can also be used under Linux, for details please check the dedicated page:
https://mib.helsinki.fi/downloads_systemreq_sam_linux.html

Python installation
  • Install Miniconda
    (tested on python 3.9, version 23.1.0, Miniconda3-py39_23.1.0-1-Windows-x86_64.exe)
    https://docs.conda.io/en/latest/miniconda.html
    Archive of miniconda releases: https://repo.anaconda.com/miniconda/

    If you have admin account, you can install Python for all users, otherwise it is possible to install Python only for the current user.

  • With Admin rights
    Example of the installation directory: D:\Python\Miniconda39\
    Installation for all users
    Installation for all users
    Installation for all users
    Miniconda configuration

    Optional note!
    If installation was done for All Users, change permission of Miniconda's envs directory (e.g. d:\Python\Miniconda39\envs\) or the whole Miniconda39 directory to be accessible for all users.
    This makes things a bit more organized, otherwise the python environment will be created in C:\Users\[USERNAME]\.conda\envs\
    Installation for all users
    Set permissions to python directory
    Installation for all users
    Set permissions to python directory


  • Without Admin rights
    Example of the installation directory: C:\Users\[USERNAME]\AppData\Local\miniconda39\
    Installation for the current user
    Installation for the current user
    Installation for the current user
    Miniconda installation directory
    Installation for the current user
    Miniconda configuration


Install segment-anything model


Install required python packages
  • Create a new environment for Python with SAM
    • Start "Anaconda Prompt"
      Start->Miniconda3->Anaconda prompt (Miniconda39)
    • Create a new environment, specify location for the environment and the version of Python:
      >> conda create --prefix d:\Python\Miniconda39\envs\sam4mib python=3.9

  • Activate the environment:
    >> activate sam4mib
  • The code requires python>=3.8, as well as pytorch>=1.7 and torchvision>=0.8. the instructions here to install both PyTorch and TorchVision dependencies:
    https://pytorch.org/get-started/locally
    The forked distribution has "requirements.txt" that can be used to install required dependencies at once for Windows with CUDA 11.8 supported GPU:
    • Make sure the the environment is created and activated (steps above)
    • In the terminal/anaconda prompt run the command to install required packages (make sure that the correct path to requirements.txt is specified):
      >> pip3 install -r requirements.txt
      or
      >> pip3 install -r d:\Python\Examples\segment-anything_230414\requirements.txt
    • Proceed to the MIB configuration section below
    • using the possible options configure the command to install the packages: Configure pytorch
      Configure pytorch
    • In the command window type the generated command to install pytorch; the tested command:
      >> pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

  • The following dependencies are necessary for mask post-processing, saving masks in COCO format, the example notebooks, and exporting the model in ONNX format:
    >> pip3 install opencv-python matplotlib onnxruntime onnx
    >> pip3 install pycocotools
    if there is an error see below
  • Install "onnxruntime-gpu" to make prediction on GPU:
    >> pip3 install onnxruntime-gpu==1.14.1
  • Optionally, install Jupyter notebook:
    >> pip install notebook


MIB configuration
  • Start MIB
  • Define path of python.exe installed in the specified environment (sam4mib):
    Menu->File->Preferences->External directories->Python installation path
    For example:
    - D:\Python\Miniconda39\envs\sam4mib\python.exe
    - C:\Users\[USERNAME]\.conda\envs\sam4mib\python.exe
  • Define directory to store network architectures for DeepMIB;
    this location will be used to download checkpoints and onnx models.
  • Open SAM settings:
    Segmentation panel->Segment-anything model->Settings

    SAM Settings
    SAM Settings
  • Select the backbone:
    - vit_b (0.4Gb), fastest (x1) but gives less precise results
    - vit_l (1.2Gb), moderate speed (~x1.4 slower), better predictions
    - vit_h (2.5Gb), slowest (x2.0), best predictions
  • Define location where segment-anything package was unzipped:
    if you check Check to select path to segment-anything a directory selection dialog will be shown
  • Set correct execution environment, please note that CPU is 30-60 times slower than CUDA


Troubleshooting

error: Microsoft Visual C++ 14.0 or greater is required
This error may appear during
>> pip install opencv-python pycocotools matplotlib onnxruntime onnx

Solution 1:
  • Try to solve the issue by installing the required package via conda using this command:
    >> conda install -c conda-forge pycocotools

Solution 2:


Remove sam4mib environment
If you do not need mib4sam environment, you can follow the following steps to uninstall it from your system.
  • Start "Anaconda Prompt"
    Start->Miniconda3->Anaconda prompt (Miniconda39)
  • List the environments installed on your system by running the command:
    >> conda env list
  • Remove sam4mib environment:
    >> conda remove --name sam4mib --all


Main page >> Downloads >> System Requirements
Back to the main page Main page of the University of Helsinki Main page of the University of Helsinki Main page of the Institute of Biotechnology Main page of the Electron Microscopy Unit Back to the main page