Skip to content

Generate Training Data for Cell Classification

Create high‑quality training datasets from your annotated images using the Compute pickles widget. Export standardized per‑cell crops and targets ready for model training.


✨ What You’ll Build

You will export: - Class_source.p — list of per‑cell crops (100×100 for 1 channel, 100×200 for 2 channels) - Class_target.p — list of class ids (same length as source)

The corresponds to the class you assign (e.g., "1", "2"). These files plug directly into the training notebook.


✅ Prerequisites

  • mAIcrobe installed and running
  • A Labels layer with segmented cells (e.g., from Compute label)
  • One or two Image layers (the channels used for classification)

🧭 Workflow Overview

1) Prepare layers: Images, Labels, and a Points layer per class 2) Open Plugins → mAIcrobe → Compute pickles 3) Select labels, points, channels, and output folder 4) Save Pickle 5) Repeat for each class


🧰 Step-by-Step

1) Launch napari and load your data - Load images and a Labels layer

2) Segment cells (if needed) - Use Compute label (Isodata or CellPose cyto3) if you don’t have a Labels layer

Loaded data

3) Create a Points layer per class and annotate cells - Create a Points layer and rename it to a positive integer class id (e.g., "1") - Add exactly one point inside each labeled cell that belongs to this class - Repeat with additional Points layers for other classes ("2", "3", ...)

Points layers

4) Open the Compute pickles widget - Plugins → mAIcrobe → Compute pickles

5) Configure the export - Labels layer: select your Labels layer - Points layer: select one class Points layer (e.g., "1") - Number of channels: choose 1 or 2 and select the image layers - Output path: choose an empty or dedicated folder - Click Save Pickle

Compute pickles widget

What happens - Finds the label under each point - Crops with a margin, masks by cell, pads to square, resizes to 100×100 - If two channels, concatenates side‑by‑side to 100×200 - Rescales intensities to [0, 1]

6) Repeat for all classes - Switch to the next Points layer (e.g., "2") and Save Pickle again

Final state


📦 Understanding the Outputs

  • Class__source.p: list of NumPy arrays
    • One channel → shape (100, 100)
    • Two channels → shape (100, 200)
  • Class__target.p: list of integers equal to the class id

Quick check in Python

import pickle, os
path = "/path/to/output"
X = pickle.load(open(os.path.join(path, "Class_1_source.p"), "rb"))
y = pickle.load(open(os.path.join(path, "Class_1_target.p"), "rb"))
print(len(X), len(y), X[0].shape, y[:5])


✅ Best Practices

  • Balance classes across annotations
  • One point per labeled cell
  • Place points well inside the cell
  • Keep imaging conditions consistent

🚀 Next Steps