Class SpotiflowBuilder

java.lang.Object
qupath.ext.biop.spotiflow.SpotiflowBuilder

public class SpotiflowBuilder extends Object
Spot detection based on the following method:
   Albert Dominguez Mantes et al.
     "Spotiflow: accurate and efficient spot detection for fluorescence microscopy with deep stereographic flow regression"
   Cold Spring Harbor Laboratory - bioRxiv, 2024. doi: 10.1101/2024.02.01.578426
 
See the main repo at https://github.com/weigertlab/spotiflow

Very much inspired by qupath-extension-cellpose at https://github.com/BIOP/qupath-extension-cellpose

  • Constructor Details

    • SpotiflowBuilder

      protected SpotiflowBuilder()
      Build a spotiflow model
    • SpotiflowBuilder

      protected SpotiflowBuilder(File builderFile)
      can create a spotiflow builder from a serialized JSON version of this builder.
      Parameters:
      builderFile - the path to a serialized JSON builder made with saveBuilder(String)
  • Method Details

    • setPretrainedModelName

      public SpotiflowBuilder setPretrainedModelName(String modelName)
      Set pre-trained model to use for prediction
      Parameters:
      modelName - name of the pre-trained model
      Returns:
      this builder
    • setProbabilityThreshold

      public SpotiflowBuilder setProbabilityThreshold(double probabilityThreshold)
      Set probability threshold for peak detection
      Parameters:
      probabilityThreshold -
      Returns:
      this builder
    • setMinDistance

      public SpotiflowBuilder setMinDistance(double minDistance)
      Set minimum distance between spots for NMS
      Parameters:
      minDistance -
      Returns:
      this builder
    • setModelDir

      public SpotiflowBuilder setModelDir(File modelDir)
      Set model directory to use for prediction
      Parameters:
      modelDir - path to the custom model
      Returns:
      this builder
    • clearAllChildObjects

      public SpotiflowBuilder clearAllChildObjects()
      Remove all child objects (i.e. previous points) from the parent shapes
      Returns:
      this builder
    • setClass

      public SpotiflowBuilder setClass(String pathClass)
      Allows to go subpixel resolution
      Returns:
      this builder
    • clearChildObjectsBelongingToCurrentChannels

      public SpotiflowBuilder clearChildObjectsBelongingToCurrentChannels()
      Remove child objects (i.e. previous points) from the parent shapes which belongs to the current selected channel(s) i.e. which have the same class as the channel name. Should be used together with setClassChannelName() to have the desired effect.
      Returns:
      this builder
    • doSubpixel

      public SpotiflowBuilder doSubpixel(boolean doSubpixel)
      Allows to go subpixel resolution
      Parameters:
      doSubpixel - override doSubpixel
      Returns:
      this builder
    • setClassChannelName

      public SpotiflowBuilder setClassChannelName()
      Allows to go subpixel resolution
      Returns:
      this builder
    • setTrainingOutputDir

      public SpotiflowBuilder setTrainingOutputDir(File outputDir)
      Set output folder to save a new model
      Parameters:
      outputDir - path to the training input dir
      Returns:
      this builder
    • setModelToFineTune

      public SpotiflowBuilder setModelToFineTune(String pretrainedModelName)
      Set the name of the pre-trained model to fine-tune
      Parameters:
      pretrainedModelName - name of the pre-trained model
      Returns:
      this builder
    • doNotApplyDataAugmentation

      public SpotiflowBuilder doNotApplyDataAugmentation()
      Force to not apply data augmentation on images during the training
      Returns:
      this builder
    • nEpochs

      public SpotiflowBuilder nEpochs(int nEpochs)
      Set the number of epochs for the training
      Parameters:
      nEpochs - number of epochs
      Returns:
      this builder
    • setLearningRate

      public SpotiflowBuilder setLearningRate(double learningRate)
      Set the learning rate of the model for the training
      Parameters:
      learningRate -
      Returns:
      this builder
    • includeNegatives

      public SpotiflowBuilder includeNegatives()
      Set the learning rate of the model for the training
      Returns:
      this builder
    • setPointClass

      public SpotiflowBuilder setPointClass(String... classes)
      Specify the class(es) of point to use for the training. By default, if no class is specified, all points within the rectangle annotation will be used for the training.
      Parameters:
      classes - array of Path class names used to filter points
      Returns:
      this builder
    • createAnnotations

      public SpotiflowBuilder createAnnotations()
      Create annotations rather than detections (the default).
      Returns:
      this builder
    • nThreads

      public SpotiflowBuilder nThreads(int nThreads)
      Specify the number of threads to use for processing. If you encounter problems, setting this to 1 may help to resolve them by preventing multithreading.
      Parameters:
      nThreads - the number of threads to use
      Returns:
      this builder
    • disableGPU

      public SpotiflowBuilder disableGPU()
      Forces using CPU instead of GPU
      Returns:
      this builder
    • zPositions

      public SpotiflowBuilder zPositions(int start, int end)
      Set a substack for 3D training / prediction. ONLY works if process3d() is called in the builder too.
      Parameters:
      start - first slice to include
      end - last slice to include
      Returns:
      this builder
    • process3d

      @Deprecated public SpotiflowBuilder process3d(boolean process3d)
      Deprecated.
      use process3d() instead
      Allows to process all slices
      Parameters:
      process3d - override process3d
      Returns:
      this builder
    • process3d

      public SpotiflowBuilder process3d()
      Allows to process all slices of 3D stack. Has to be used together with a 3D-model (custom or pre-trained)
      Returns:
      this builder
    • tempDirectory

      public SpotiflowBuilder tempDirectory(File inputDir)
      Set input folder to predict spots
      Parameters:
      inputDir - path to prediction input dir
      Returns:
      this builder
    • savePredictionImages

      @Deprecated public SpotiflowBuilder savePredictionImages(boolean savePredictionImages)
      Deprecated.
      use cleanTempDir() instead
      Set input folder to predict spots
      Parameters:
      savePredictionImages - overwrite variable
      Returns:
      this builder
    • cleanTempDir

      public SpotiflowBuilder cleanTempDir()
      clear all files in the temp directory
      Returns:
      this builder
    • cleanTrainingDir

      public SpotiflowBuilder cleanTrainingDir()
      clear all files in the training directories
      Returns:
      this builder
    • channels

      public SpotiflowBuilder channels(int... channels)
      Specify channels. Useful for detecting nuclei for one channel within a multi-channel image, or potentially for trained models that support multi-channel input.
      Parameters:
      channels - 0-based indices of the channels to use
      Returns:
      this builder
    • channels

      public SpotiflowBuilder channels(String... channels)
      Specify channels by name. Useful for detecting nuclei for one channel within a multichannel image, or potentially for trained models that support multichannel input.
      Parameters:
      channels - channels names to use
      Returns:
      this builder
    • saveBuilder

      public SpotiflowBuilder saveBuilder(String name)
      Save this builder as a JSON file in order to be able to reuse it in place
      Parameters:
      name - A name to append to the JSON file. Keep it meaningful for your needs
      Returns:
      this builder
    • saveTempImagesAsOmeZarr

      public SpotiflowBuilder saveTempImagesAsOmeZarr()
      True to save images in the temp folder as OME-Zarr files. Otherwise, saved as OME-TIFF WARNING : OME-Zarr option is only available from spotiflow >= 0.5.8
      Returns:
      this builder
    • addParameter

      public SpotiflowBuilder addParameter(String flagName, String flagValue)
      Generic means of adding a spotiflow parameter
      Parameters:
      flagName - the name of the flag, e.g. "save_every"
      flagValue - the value that is linked to the flag, e.g. "20". Can be an empty string or null if it is not needed
      Returns:
      this builder
    • addParameter

      public SpotiflowBuilder addParameter(String flagName)
      Generic means of adding a spotiflow parameter
      Parameters:
      flagName - the name of the flag, e.g. "save_every"
      Returns:
      this builder
    • build

      public Spotiflow build()
      Create a Spotiflow, all ready for detection.
      Returns:
      a new Spotiflow instance