Sam4MIB Mac Tutorial

Sam4MIB Mac TutorialSam4MIB Mac TutorialSam4MIB Mac Tutorial

Sam4MIB Mac Tutorial

Sam4MIB Mac TutorialSam4MIB Mac TutorialSam4MIB Mac Tutorial
  • Home
  • Windows VS Linux VS Mac
  • More
    • Home
    • Windows VS Linux VS Mac
  • Home
  • Windows VS Linux VS Mac

Windows VS Linux VS Mac

Windows

Windows

Windows

 

Windows

Requirement: 

  • 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

Tutorial:

  1. Python Installation:

Install Miniconda
(tested on python 3.9,

 

Windows

Requirement: 

  • 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

Tutorial:

  1. 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 an 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\

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\

Without admin rights:

Example of the installation directory: C:\Users\[USERNAME]\AppData\Local\miniconda39\

  1. Install segment anything model:

Download segment-anything-model from:

- forked distibution tested with MIB

- facebookresearch github

Unzip "segment-anything-main.zip", for example to d:\Python\Examples\segment-anything\

  1. Install required Python package:

  • Create a new environment for Python with SAM

  1. Start "Anaconda Prompt"
    Start->Miniconda3->Anaconda prompt (Miniconda39)

  2. 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
  3. 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
  • using the possible options configure the command to install the packages:

PyTorch Build: Stable (2.4.1)

Your OS: Windows

Package: Pip

Language: Python

Compute Platform: CUDA 11.8

  • 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

  1. MIB Configuration:

  • Start MIB
  • Open MIB preferences:
    Menu->File->Preferences
  • Define path of python.exe installed in the specified environment (sam4mib):
    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.
  • Select "Segment-anything model" tool in the Segmentation panel
  • Open SAM settings:
    Segmentation panel->Segment-anything model->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

  1. How to 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

Linux

Windows

Windows

 

Linux

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
  • Pytorch 1.10.0, (newer versions may not be compatible with Matlab installation)
  • CUDA compatible GPU (CUDA 11.1) is highly recommended, CPU can also be used but it is 

 

Linux

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
  • Pytorch 1.10.0, (newer versions may not be compatible with Matlab installation)
  • CUDA compatible GPU (CUDA 11.1) is highly recommended, CPU can also be used but it is significantly slower

Tutorial: 

  1. Python Installation:

  • Start Terminal
  • mkdir -p ~/miniconda3
  • Pick a suitable miniconda installation from https://repo.anaconda.com/miniconda
  • Type of the following command by replacing with the corresponding link with the desired one(Tested on Miniconda3-py39_23.11.0-2-Linux-x86_64.sh:

>> wget https://repo.anaconda.com/miniconda/Miniconda3-py39_23.11.0-2-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh

>> bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3

>> rm -rf ~/miniconda3/miniconda.sh

  • Initialize for bash shell:
    >> ~/miniconda3/bin/conda init bash
  • Close and reopen terminal after this operation
  • Create a new environment for Python with SAM (replace python version with the installed)
    >> conda create --prefix ~/miniconda3/envs/sam4mib python=3.9
  • Activate the environment
    >> conda activate ~/miniconda3/envs/sam4mib

  1. Install required python package:

note:SAM requires python>=3.8, as well as pytorch>=1.7 and torchvision>=0.8;

SAM installation was tested with Pytorch 1.10.0 and CUDA version 11.1, the newer version may not be compatible.

The list of Pytorch installation option is available from https://pytorch.org/get-started/locally

  • Install pytorch:
    (sam4mib)>> pip3 install torch==1.10.0+cu111 torchvision==0.11.0+cu111 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html
  • The following dependencies are necessary for mask post-processing, saving masks in COCO format, the example notebooks, and exporting the model in ONNX format

(sam4mib)>> pip3 install opencv-python matplotlib onnxruntime onnx

(sam4mib)>> pip3 install pycocotools

  • Install "onnxruntime-gpu" to make prediction on GPU
    (sam4mib)>> pip3 install onnxruntime-gpu

  1. Install Segment-anything model from one of the two options:

  • Forked distibution tested with MIB:
    (sam4mib)>> pip3 install git+https://github.com/Ajaxels/segment-anything.git
  • Distribution available on facebookresearch:
    (sam4mib)>> pip3 install git+https://github.com/facebookresearch/segment-anything.git

Note: 

Segment-anything will be installed to "~/miniconda3/envs/sam4mib/lib/python3.9/site-packages"

  1. MIB configuration:

MIB configuration steps are similar to the SAM installation under Windows with the only difference in paths.

  1. Define path of python3 installed in the specified environment (sam4mib):
    Menu->File->Preferences->External directories->Python installation path
    For example:
    - ~/miniconda3/envs/sam4mib/bin/python3
  2. Define directory to store network architectures for DeepMIB;
    this location will be used to download checkpoints and onnx models.
  3. Open SAM settings:
    Segmentation panel->Segment-anything model->Settings

  4. Define location where segment-anything package was installed:
    "~/miniconda3/envs/sam4mib/lib/python3.9/site-packages"
  5. Testing sam4MIB environment

You can optionally test installation of SAM and sam4mib environment.

  1. Check installation of pytorch in linux terminal:
    (sam4mib)>> python -c "import torch; print(torch.__version__)"
  2. SAM distribution has amg.py under scripts subfolder, it can be used to test the installation under python.

    1. Copy amg.py and notebook1.png (or any other png image) from SAM distribution into directory with the downloaded checkpoint (e.g. "sam_vit_b_01ec64.pth")
    2. Start terminal in that directory and activate sam4mib environment
      >> conda activate ~/miniconda3/envs/sam4mib
    3. Run the following command:
      (sam4mib)>> python amg.py --input notebook1.png --model-type 'vit_b' --output notebook2.png --checkpoint sam_vit_b_01ec64.pth
      to load the checkpoint file and do segmentation of the image, the results are placed to notebook2.png subfolder

  3. Checksum test in terminal:
    >> md5sum sam_vit_b_01ec64.pth
  4. How to remove sam4mib environment:

If you do not need mib4sam environment, you can follow the following steps to uninstall it from your system.

  1. Start terminal
  2. List the environments installed on your system by running the command:
    >> conda env list
  3. Remove sam4mib environment:
    >> conda remove --name sam4mib --all
  4. You can also remove miniconda completely:
    >> rm -rf ~/miniconda3

MAC

Windows

MAC

 

Mac

Requirements: 

  • MATLAB R2022a or newer (tested on R2022a and R2024a,)
  • Python 3.8, 3.9, 3.10; tested on 3.9
  • List of Python versions compatible with various MATLAB releases
  • Pytorch 1.10.0, (newer versions may not be compatible with Matlab installation)
  • CUDA compatible GPU is highly recommended, CPU can also be used but it is significantly slo

 

Mac

Requirements: 

  • MATLAB R2022a or newer (tested on R2022a and R2024a,)
  • Python 3.8, 3.9, 3.10; tested on 3.9
  • List of Python versions compatible with various MATLAB releases
  • Pytorch 1.10.0, (newer versions may not be compatible with Matlab installation)
  • CUDA compatible GPU is highly recommended, CPU can also be used but it is significantly slower

Tutorial:

  1. Python Installation:

  • Start Terminal
  • >> mkdir -p miniconda3
  • Pick a suitable miniconda installation from https://repo.anaconda.com/miniconda
  • Type of the following command by replacing with the corresponding link with the desired one:

>> wget https://repo.anaconda.com/miniconda/”corresponding link”

>> bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3

>> rm -rf ~/miniconda3/miniconda.sh

  • Initialize for bash shell:
    >> ~/miniconda3/bin/conda init bash
  • Close and reopen terminal after this operation
  • Create a new environment for Python with SAM (replace python version with the installed)
    >> conda create miniconda3/envs/sam4mib python=3.9
  • Activate the environment
    >> conda activate miniconda3/envs/sam4mib

  1. Install Segment-anything model from one of the two options:

  • Forked distibution tested with MIB:
    (sam4mib)>> pip3 install git+https://github.com/Ajaxels/segment-anything.git
  • Distribution available on facebookresearch:
    (sam4mib)>> pip3 install git+https://github.com/facebookresearch/segment-anything.git

Note: 

Segment-anything will be installed to "miniconda3/envs/sam4mib/lib/python3.9/site-packages"

  1. Install required python package:

  • 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
  • using the possible options configure the command to install the packages:

PyTorch Build: Stable (2.4.1)

Your OS: Mac

Package: Pip

Language: Python

Compute Platform: Default

  • In the command window type the generated command to install pytorch; the tested command:
    >> pip3 install torch torchvision torchaudio
  • 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

  1. MIB configuration:

  • Start MIB
  • Open MIB preferences:
    Menu->File->Preferences
  • Define path of python.exe installed in the specified environment (sam4mib):
    External directories->Python installation path
    For example:

Applications/miniconda3/envs/sam4mib/bin/python3

  • Define directory to store network architectures for DeepMIB;this location will be used to download checkpoints and onnx models.
  • Select "Segment-anything model" tool in the Segmentation panel
  • Open SAM settings:
    Segmentation panel->Segment-anything model->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

  1. How to remove sam4mib environment:

  • If you do not need sam4mib 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

Copyright © 2024 Sam4MIB Mac Tutorial - All Rights Reserved.


Powered by

This website uses cookies.

We use cookies to analyze website traffic and optimize your website experience. By accepting our use of cookies, your data will be aggregated with all other user data.

Accept