MouseLand/cellpose

[BUG]Value Error when training Cellpose3

Closed this issue · 1 comments

Value Error when training Cellpose3: train data and label not same length.

I have 10 image.tif in my training folder and masks folder which contain 10 corresponding masks. Then I store data = {
"train_files": images,
"train_labels": masks,
} to probs_generalist.npy. Finally, I use the command line from the paper to train the model. However, It has 'ValueError: train data and labels not same length.'

import numpy as np

# # Specify the directories for images and masks
image_dir = "/Users/selinahan/Desktop/training"
mask_dir = "/Users/selinahan/Desktop/training/masks"

 # Get all image and mask file paths
 # Assuming the filenames match (e.g., image1.tif → masks/image1_mask.tif)
images = sorted([os.path.join(image_dir, f) for f in os.listdir(image_dir) if f.endswith(".tif")])
masks = sorted([os.path.join(mask_dir, f) for f in os.listdir(mask_dir) if f.endswith(".tif")])

# Ensure matching filenames
if len(images) != len(masks):
    raise ValueError("Number of images and masks do not match!")

# Create the dictionary
data = {
    "train_files": images,
    "train_labels": masks,
}

# Save as .npy file
np.save("/Users/selinahan/Desktop/training/probs_generalist.npy", data)

Command line shown in screenshots:
Screen Shot 2024-11-24 at 19 49 07

Can anyone help me to debug this issue? Thanks in advance.

ah we currently do not support training masks that are in a separate folder for the file loading method, so the code didn't find any labels files and errored. you need to put the masks in the same folder with _masks.tif appended, or train in a notebook. I will close this for now but will reopen if there are more requests for this.