Package: run-stardist
Run StardistA complete training and inference pipeline for 3D StarDist with an example on 3D biological (ovules) datasets. Please submit an issue if you encountered errors or if you have any questions or suggestions.ModelsModel informationTraining data stats and linksInstallationInstall Anaconda/Miniconda pythonInstall this repo using Conda without GitInstall this repo using Conda with GitUsageExample configuration file for both training and inferenceTrainingPredictionSpecifying a Graphic Card (GPU)ModelsA 3D nucleus segmentation model is available for download from Bioimage.IO and ready to be used directly for segmenting your nuclei. The model is trained on a 3D confocal ovule dataset fromArabidopsis thaliana.Model informationModel weights and related files can be found at:https://zenodo.org/doi/10.5281/zenodo.8421755.After downloading the model, put it in yourPATH_TO_MODEL_DIRand specify the model name asMY_MODEL_NAMEin the configuration file (see below). Then you can runpredict.pyin this repository and use the model for inference (see below).Training data stats and linksThe training data is publicly available on Zenodo at[LINK](to be published after paper submission). Some key information about the training data is listed below:original_voxel_size={# z, y, x1135:[0.28371836501901143,0.12678642066720086,0.12678642066720086],# validation1136:[0.2837183895131086,0.12756971653115998,0.12756971653115998],# training1137:[0.2837183895131086,0.1266211463645486,0.1266211463645486],# training1139:[0.2799036917562724,0.12674335484590543,0.12674335484590543],# training1170:[0.27799632231404964,0.12698523961670266,0.12698522349145364],# training}# [0.2837, 0.1268, 0.1268] is taken as the medianoriginal_median_extents={# z, y, x1135:[16,32,33],# validation1136:[16,32,32],# training1137:[16,32,32],# training1139:[16,32,33],# training1170:[16,29,30],# training'average':}# [16, 32, 32] is taken as the medianInstallationInstall Anaconda/Miniconda pythonFirst step required to use the pipeline is installing Miniconda. If you already have a working Anaconda setup you can go directly to the next step. Anaconda can be downloaded for all platforms fromhere. We suggest to use Miniconda, because it is lighter and install fewer unnecessary packages.To download Miniconda, open a terminal and type:$wgethttps://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.shThen install by typing:$bash./Miniconda3-latest-Linux-x86_64.shInstall this repo using Conda without GitDownloadand unzip this repository into your machine if you haven't done soGo into the StarDist subdirectory:$cdovules-instance-segmentation-main/stardist/Create the environment from the environment.yml file:$condaenvcreate-fenvironment.ymlActivate the environment:$condaactivatestardistInstall this repo using Conda with GitClone this repository into your machine if you haven't done so:$gitclonegit@github.com:qin-yu/ovules-instance-segmentation.gitGo into the StarDist subdirectory:$cdovules-instance-segmentation/stardist/Create the environment from the environment.yml file:$condaenvcreate-fenvironment.ymlActivate the environment:$condaactivatestardistUsageExample configuration file for both training and inferenceThe original configuration file used for training the final ResNet StarDist model published on Bioimage.IO for wide applicability can be found atstardist/configs/final_resnet_model_config.yml, which can used for both training and inference (note that the inference output is only used for illustration in this repository because it's segmenting the training data).The generic template is shown below. A configuration template with more guidelines can be found atstardist/configs/train_and_infer.yml.wandb:# optional, remove this part if not using W&Bproject:ovules-instance-segmentationname:final-stardist-modeldata:# Rescale outside StarDistrescale_factor:Null# Training (ignored in inference config file)training:-PATH_TO_INPUT_DIR_1 or PATH_TO_INPUT_FILE_1-PATH_TO_INPUT_DIR_2 or PATH_TO_INPUT_FILE_2validation:-PATH_TO_INPUT_DIR_3 or PATH_TO_INPUT_FILE_3raw_name:raw/noisy# only required if HDF5label_name:label/gold# only required if HDF5# Inference (ignored in training config file)prediction:-PATH_TO_INPUT_DIR_4 or PATH_TO_INPUT_FILE_4-PATH_TO_INPUT_DIR_5 or PATH_TO_INPUT_FILE_5format:tiff# only 'hdf5' or 'tiff'name:raw/nuclei# dataset name of the raw image in HDF5 files, only required if format is `hdf5`output_dir:MY_OUTPUT_DIRoutput_dtype:uint16# `uint8`, `uint16`, or `float32` are recommendedresize_to_original:True# output should be of he same shape as inputtarget_voxel_size:Null# the desired voxel size to rescale to during inference, null if rescale factor is setsave_probability_map:Truestardist:model_dir:PATH_TO_MODEL_DIRmodel_name:MY_MODEL_NAMEmodel_type:StarDist3Dmodel_config:# model configuration should stay identical for training and inferencebackbone:resnetn_rays:96grid:[2,4,4]use_gpu:Falsen_channel_in:1patch_size:[96,96,96]# multiple of 16 preferedtrain_batch_size:8train_n_val_patches:16steps_per_epoch:400epochs:1000augmenter:name:defaultTraining$train-stardist--configCONFIG_PATHwhere CONFIG_PATH is the path to the YAML configuration file. For example, if you want to train the model with the example configuration fileconfigs/train_and_infer.yml:$cdovules-instance-segmentation/stardist/
$train-stardist--configconfigs/train_and_infer.ymlPrediction$predict-stardist--configCONFIG_PATHwhere CONFIG_PATH is the path to the YAML configuration file. For example, if you want to use the model with the example configuration fileconfigs/train_and_infer.yml:$cdovules-instance-segmentation/stardist/
$predict-stardist--configconfigs/train_and_infer.ymlPreprocessing:For the publishedStarDist Plant Nuclei 3D ResNetthe median size of nuclei in training data is[16, 32, 32]. To achieve the best segmentation result, the input 3D images should be rescaled so that your nucleus size in ZYX matches the training data. For example, if the median nucleus size of your data is[32, 32, 32], thenrescale_factorshould be[0.5, 1., 1.]; if it's[15, 33, 31], then it does not have to be rescaled. You may also choose to leaverescale_factorasNulland rescale your images with Fiji or other tools before running the pipeline. Ifresize_to_originalisTruethen the output will have the original size of the input image.Specifying a Graphic Card (GPU)If you need to specify a graphic card, for example to use the No. 7 card, do:$CUDA_VISIBLE_DEVICES=7predict-stardist--configconfigs/train_and_infer.yml