-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 09c11eb
Showing
224 changed files
with
3,341 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: 373ba6f216484fb88d2f05752eeeb69a | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
API Reference | ||
------------- | ||
|
||
.. autoclass:: spotiflow.model.spotiflow.Spotiflow | ||
:members: from_pretrained, from_folder, predict, fit, save, load, optimize_threshold | ||
|
||
.. autoclass:: spotiflow.model.config.SpotiflowModelConfig | ||
:members: | ||
|
||
.. autoclass:: spotiflow.model.config.SpotiflowTrainingConfig | ||
:members: | ||
|
||
.. autoclass:: spotiflow.data.spots.SpotsDataset | ||
:members: | ||
|
||
.. automethod:: __init__ | ||
|
||
.. automodule:: spotiflow.utils | ||
:members: get_data, read_coords_csv, write_coords_csv, normalize | ||
|
||
.. automodule:: spotiflow.sample_data | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Fine-tuning a Spotiflow model on a custom dataset | ||
------------------------------------------------- | ||
|
||
Data format | ||
^^^^^^^^^^^ | ||
|
||
See :ref:`train:Data format`. | ||
|
||
Fine-tuning | ||
^^^^^^^^^^^ | ||
|
||
Finetuning a pre-trained model on a custom dataset is very easy. You can load the model very similarly to what you would normally do to predict on new images (you only need to add one extra parameter!): | ||
|
||
.. code-block:: python | ||
from spotiflow.model import Spotiflow | ||
from spotiflow.utils import get_data | ||
# Get the data | ||
train_imgs, train_spots, val_imgs, val_spots = get_data("/path/to/spots_data") | ||
# Initialize the model | ||
model = Spotiflow.from_pretrained( | ||
"general", | ||
inference_mode=False, | ||
) | ||
# Train and save the model | ||
model.fit( | ||
train_imgs, | ||
train_spots, | ||
val_imgs, | ||
val_spots, | ||
save_dir="/my/trained/model", | ||
) | ||
Of course, you can also fine-tune from a model you have trained before. In that case, use the ``from_folder()`` method instead of ``from_pretrained()`` (see :ref:`index:Predicting spots in an image`). | ||
All the information about training customization from :ref:`train:Customizing the training` applies here as well. However, note that you cannot change the model architecture when fine-tuning! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
:hero: Spotiflow: accurate and robust spot detection for fluorescence microscopy | ||
|
||
========= | ||
Spotiflow | ||
========= | ||
|
||
Spotiflow is a learning-based spot detection method for fluorescence microscopy images. For more information, please refer to our `paper <https://PLACEHOLDER/>`__. | ||
|
||
Getting Started | ||
--------------- | ||
|
||
Installation | ||
~~~~~~~~~~~~ | ||
|
||
|
||
First, create and activate a new conda environment. | ||
|
||
.. code-block:: console | ||
(base) $ conda create -n spotiflow python=3.9 | ||
(base) $ conda activate spotiflow | ||
Then, install Pytorch using ``conda``/ ``mamba``. Please follow the `official instructions for your system <https://pytorch.org/get-started/locally>`__. | ||
|
||
As an example, for MacOS: | ||
|
||
.. code-block:: console | ||
(spotiflow) $ conda install pytorch::pytorch torchvision -c pytorch | ||
For a linux system with CUDA (note that you should change the CUDA version to match the one installed on your system): | ||
|
||
.. code-block:: console | ||
(spotiflow) $ conda install pytorch torchvision pytorch-cuda=11.8 -c pytorch -c nvidia | ||
Finally, install ``spotiflow`` using ``pip``: | ||
|
||
.. code-block:: console | ||
(spotiflow) $ pip install spotiflow | ||
Predicting spots in an image | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The snippet below shows how to retrieve the spots from an image using one of the pretrained models: | ||
|
||
.. code-block:: python | ||
from skimage.io import imread | ||
from spotiflow.model import Spotiflow | ||
from spotiflow.utils import write_coords_csv | ||
# Load the desired image | ||
img = imread("/path/to/your/image") | ||
# Load a pretrained model | ||
model = Spotiflow.from_pretrained("general") | ||
# Predict spots | ||
spots, details = model.predict(img) # predict expects a numpy array | ||
# spots is a numpy array with shape (n_spots, 2) | ||
# details contains additional information about the prediction, like the predicted heatmap, the probability per spot, the flow field, etc. | ||
# Save the results to a CSV file | ||
write_coords_csv(spots, "/path/to/save/spots.csv") | ||
If a custom model is used, simply change the model loadings step to: | ||
|
||
.. code-block:: python | ||
# Load a custom model | ||
model = Spotiflow.from_folder("/path/to/model") | ||
Contents | ||
-------- | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
napari | ||
train | ||
finetune | ||
api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Predicting spots using the napari plugin | ||
---------------------------------------- | ||
|
||
The napari plugin can be used to predict spots in a napari viewer. First, you must install it in the environment containing Spotiflow: | ||
|
||
.. code-block:: console | ||
(spotiflow) $ pip install napari-spotiflow | ||
The plugin will then be available in the napari GUI under the name "Spotiflow widget". This is how the GUI looks like: | ||
|
||
.. image:: ./_static/spotiflow_napari_gui.png | ||
:width: 700 | ||
:align: center | ||
|
||
The plugin has two modes: for images (``2D``) and movies (``2D+t``), which can be toggled using the ``2D`` and ``2D+t`` buttons in the GUI. Other options can be tuned, `e.g.` rescaling the image. | ||
|
||
Upon pressing the button ``Run``, The plugin will create a ``Points`` layer containing the predicted spots: | ||
|
||
.. image:: ./_static/spotiflow_napari_preds.png | ||
:width: 700 | ||
:align: center | ||
|
||
If the option ``Show CNN output`` is checked, the plugin will also create an ``Image`` layer containing the heatmap output of the CNN. | ||
|
||
Finally, the plugin includes one sample image per dataset. These samples can be loaded from the ``File`` menu (``File -> Open sample -> napari-spotiflow``). You can try the plugin with these samples to get a better idea of how it works! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
Training a Spotiflow model on a custom dataset | ||
---------------------------------------------- | ||
|
||
Data format | ||
^^^^^^^^^^^ | ||
|
||
First of all, make sure that the data is organized in the following format: | ||
|
||
:: | ||
|
||
spots_data | ||
├── train | ||
│ ├── img_001.csv | ||
│ ├── img_001.tif | ||
| ... | ||
│ ├── img_XYZ.csv | ||
| └── img_XYZ.tif | ||
└── validation | ||
├── val_img_001.csv | ||
├── val_img_001.tif | ||
... | ||
├── val_img_XYZ.csv | ||
└── val_img_XYZ.tif | ||
|
||
The actual naming of the files is not important, but the ``.csv`` and ``.tif`` files corresponding to the same image **must** have the same name! The ``.csv`` files must contain the spot coordinates in the following format: | ||
|
||
.. code-block:: | ||
y,x | ||
42.3,24.24 | ||
252.99, 307.97 | ||
... | ||
The column names can also be `axis-0` (instead of `y`) and `axis-1` instead of `x`. | ||
|
||
|
||
Basic training | ||
^^^^^^^^^^^^^^ | ||
|
||
You can easily train a model using the default settings as follows and save it to the directory `/my/trained/model`: | ||
|
||
.. code-block:: python | ||
from spotiflow.model import Spotiflow | ||
from spotiflow.utils import get_data | ||
# Get the data | ||
train_imgs, train_spots, val_imgs, val_spots = get_data("/path/to/spots_data") | ||
# Initialize the model | ||
model = Spotiflow() | ||
# Train and save the model | ||
model.fit( | ||
train_imgs, | ||
train_spots, | ||
val_imgs, | ||
val_spots, | ||
save_dir="/my/trained/model", | ||
) | ||
You can then load it by simply calling: | ||
|
||
.. code-block:: python | ||
model = Spotiflow.from_folder("/my/trained/model") | ||
Customizing the training | ||
^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
You can also pass other parameters relevant for training to the `fit` method. For example, you can change the number of epochs, the batch size, the learning rate, etc. You can do that through the `` For more information on the arguments, see the documentation of :py:func:`spotiflow.model.spotiflow.Spotiflow.fit` method as well as :py:mod:`spotiflow.model.config.SpotiflowTrainingConfig`. As an example, let's change the number of epochs and the learning rate: | ||
|
||
.. code-block:: python | ||
train_config = { | ||
"num_epochs": 100, | ||
"learning_rate": 0.001, | ||
# other parameters | ||
} | ||
model.fit( | ||
train_imgs, | ||
train_spots, | ||
val_imgs, | ||
val_spots, | ||
save_dir="/my/trained/model", | ||
train_config=train_config, | ||
# other parameters | ||
) | ||
In order to change the model architecture (`e.g.` number of input/output channels, number of layers, variance for the heatmap generation, etc.), you can create a :py:mod:`spotiflow.model.config.SpotiflowModelConfig` object and populate it accordingly. Then you can pass it to the `Spotiflow` constructor. For example, if our image is RGB and we need the network to use 3 input channels, we can do the following: | ||
|
||
.. code-block:: python | ||
from spotiflow.model import SpotiflowModelConfig | ||
# Create the model config | ||
model_config = SpotiflowModelConfig( | ||
in_channels=3, | ||
# you can pass other arguments here | ||
) | ||
model = Spotiflow(model_config) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.