Explore and label the ‘sparse labels’ Data

Explore and label the ‘sparse labels’ Data#

This notebook uses the napari-easy-augment-batch-dl widget to explore and label the data. We point the plugin to the ‘ladybugs_sparse’ directory which contains 3 highly clustered lady bug images, and we use the ‘ladybug_sparse’ model which has been pretrained on the sparse labels.

Take home point: The model does pretty predicting ladybugs that were not labeled on the same images that were partially labeled. However not so good on the image which did not have any data labeled. More training images are likely needed to get a good lady bug model… the good news is we probably don’t have to label every single ladybug on all images, we can sparsely label several images to accelerate the process.

import os
import numpy as np
import napari
from napari_easy_augment_batch_dl import easy_augment_batch_dl
try:
    from napari_easy_augment_batch_dl.frameworks.stardist_instance_framework import StardistInstanceFramework
except:
    print('StardistInstanceFramework not loaded')
raster_geometry not imported.  This is only needed for the ellipsoid rendering in apply_stardist
Albumentations is not installed. Please install it using pip install albumentations.
No module named 'segment_everything'
viewer = napari.Viewer()

batch_dl = easy_augment_batch_dl.NapariEasyAugmentBatchDL(viewer, label_only = False)

viewer.window.add_dock_widget(
    batch_dl
)

data_path = r'../../data'
parent_path = os.path.join(data_path, 'ladybugs_sparse')
model_path = os.path.join(parent_path, 'models')

model_name = 'ladybug_sparse'
model_type = "Stardist Model"
batch_dl.load_image_directory(parent_path)


if model_name is not None:

    # set the drop down to the StardistInstanceFramework
    batch_dl.network_architecture_drop_down.setCurrentText(StardistInstanceFramework.descriptor)

    # get the stardist widget
    widget = batch_dl.deep_learning_widgets[StardistInstanceFramework.descriptor]

    # load model
    widget.load_model_from_path(os.path.join(model_path, model_name))
persistent_dict.py (52): Unable to import recommended hash 'siphash24.siphash13', falling back to 'hashlib.sha256'. Run 'python3 -m pip install siphash24' to install the recommended hash.
Assistant skips harvesting pyclesperanto as it's not installed.
PytorchSemanticFramework not loaded
CellPoseInstanceFramework not loaded
No module named 'segment_everything'
found framework is  StardistInstanceFramework
Created new Zarr store.
Created new Zarr store.
error creating ml_labels: 'Random Forest Model'
Loading network weights from 'weights_best.h5'.
Couldn't load thresholds from 'thresholds.json', using default values. (Call 'optimize_thresholds' to change that.)
Using default values: prob_thresh=0.5, nms_thresh=0.4.