MouseLand / cellpose

a generalist algorithm for cellular segmentation with human-in-the-loop capabilities
https://www.cellpose.org/
BSD 3-Clause "New" or "Revised" License
1.4k stars 403 forks source link

[BUG]Value Error when training Cellpose3 #1064

Open SelinaHhan opened 5 days ago

SelinaHhan commented 5 days ago

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.