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.24k stars 359 forks source link

[BUG] No masks found after training #947

Open jzeng22 opened 1 month ago

jzeng22 commented 1 month ago

Hi,

I've been trying to do human-in-the-loop model training on the GUI. When I run the untrained cyto3 model on one of my images (changing the diameter to 10 pixels and the upper normalization percentage to 99.99 to account for the sparsity in my image), it works fine, and masks are found. Here is an example of the output of the model (example_mask.zip). However, after training (by going to "Models" and then clicking on "Train new model with image+masks in folder" and using the default training parameters), no masks are found. I've tried training on multiple (4) images (running the untrained cyto3 model on multiple images and then training), but the issue remains.

Attached are my images (images.zip) and the terminal output (terminal_output.txt).

Thank you!

lsxucsf commented 3 weeks ago

Any resolution to this issue? I'm having the same problem- with cellpose 3.0.7. Rolling back to cellpose 2 returned the human-in-the-loop functionality as before.

MathieuVigneau commented 3 weeks ago

Same issue for me. No mask found after human-in-the-loop training. Waiting for the resolution

carsen-stringer commented 3 weeks ago

sorry I think I found the bug here, the cellpose3 GUI was only using 8 images per epoch during training with human-in-the-loop, can you please install the latest version and try it out? Install command: pip install git+ https://github.com/mouseland/cellpose.git

On Wed, Jun 5, 2024 at 2:53 AM Math7914 @.***> wrote:

Same issue for me. No mask found after human-in-the-loop training. Waiting for the resolution

— Reply to this email directly, view it on GitHub https://github.com/MouseLand/cellpose/issues/947#issuecomment-2149016495, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADS6TFL2DSP5TZD2TTM2J5DZF2YVHAVCNFSM6AAAAABICMNDCWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBZGAYTMNBZGU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

lsxucsf commented 3 weeks ago

That fixed it for me. Thanks Carsen

jzeng22 commented 3 weeks ago

I'm still getting 0 masks after training. Notably, when I use images downloaded from the cellpose website, the training process works fine (this was also true prior to installing the latest version as suggested), so I am wondering if this issue may be specific to the types of images I'm using (my images are of synaptosomes, not cells, and are more sparsely populated).

I've also tried training in a script (see below), but have the same problem (using the original untrained cyto3 model produces masks but using the trained model gives me 0 masks).

# training and testing directories
train_dir = "train_dir"
test_dir = "test_dir"

from cellpose import io, models, train
io.logger_setup()

# loading data
output = io.load_train_test_data(train_dir, test_dir, image_filter="_img", mask_filter="_seg.npy", look_one_level_down=False)
images, labels, image_names, test_images, test_labels, image_names_test = output

# normalizing the image
def normalize(img):
    X = img
    x01 = np.percentile(X,1)
    x99 = np.percentile(X, 99.99)
    X = (X - x01) / (x99 - x01)
    return X

images = [normalize(image) for image in images]
test_images = [normalize(test_image) for test_image in test_images]

model = models.CellposeModel(gpu=False, model_type='cyto3')

print("\nRunning cellpose training")
cellposeStartTime = time.time()

model_path = train.train_seg(model.net, train_data=images, train_labels=labels,
                             channels=[0,0], normalize=False,
                             test_data=test_images, test_labels=test_labels,
                             weight_decay=1e-4, SGD=True, learning_rate=0.1,
                             n_epochs=300, model_name="my_new_model5")
viditagr commented 1 week ago

Hey @jzeng22, are you still having the same problem or was it resolved because I think I am also facing the same issues. I am getting an info message saying no cell pixels found which I believe is equivalent to saying no masks found. I am also trying to use the exact same workflow, also tried to update it as suggested but it did not fix it! Any help would be appreciated!