1. arivis Knowledge Hub
  2. Vision4D / arivis Pro
  3. Scripting and interaction with other programs

Converting Cellpose models for use in arivis

Instructions for the Cellpose to ONNX conversion script

Introduction

As of arivis Vision4D 4.1.1, Cellpose-like segmentation is supported natively in the analysis pipeline. However, arivis does not use the native Cellpose model format and instead uses the ONNX standard. Therefore, if we want to use custom Cellpose models in arivis these first need to be converted to the right format. The script linked below automatically converts all Cellpose models, including custom models, for use with arivis.

How to use the Cellpose to ONNX script

First, download the script file here:

Cellpose_to_onnx.py

Copy and paste the py file in the main folder of your cellpose python solution.

The script requires that the ONNX python libraries are installed. If these libraries are not yet installed, or you just want to make sure you have the latest:

  • Open a cmd in the same folder as python.exe which your environment uses as its interpreter (this ensures that you are installing ONNX module for the correct env)
  • Run  pip install onnx  to install ONNX module from official python packages

The script has two options:

  1. Convert all models: look for built-in and custom models where Cellpose saves them. Any custom change in Cellpose behaviour (where the models are saved, for example) is not guaranteed to work with this option.
  2. convert individual model: convert single model at the time, the user must provide the model full path and a mean_diameter

Convert all Cellpose models, built-in and custom-trained models, use:

command line: python cellpose_to_onnx

    * Script looks for the built-in and custom trained models in the folders where cellpose saves the models 
    * all models are converted to ONNX and saved in the same folder as original cellpose models under a subfolder "output"

Note: this is only possible if users don't move the models to different folders as cellpose initially saves them

Convert a single model:

command line: python cellpose_to_onnx.py --model_path [FULL_PATH_TO_THE_MODEL] --mean_diamter [30. or 17.]

* the model could be anywhere
* use this if you are not using cellpose folder structure

Change the output location

The script automatically outputs the converted model to the same folder as the input. To change the output folder, where the ONNX models are saved we need to ad --output to the command line.

command line: python cellpose_to_onnx.py --output_directory [DIRECTOY_TO_SAVE_ONNX_FILES]