Explore and label data#

This notebook uses the napari-easy-augment-batch-dl widget to explore and label the data. If we have a model trained we can also predict using that model.

import os
import numpy as np
import napari
from napari_easy_augment_batch_dl import easy_augment_batch_dl

Label the Image with a Napari widget#

Here we call the napari-easy-augment-batch-dl widget in label_only mode so we can label the images. Optionally if a model has already been trained we can pass it to the Widget. Then we can make predictions and correct them.

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, 'ladybugs1')
model_path = os.path.join(parent_path, 'models')

batch_dl.load_image_directory(parent_path)

model_name = None
model_name = 'stardist_for_ladybugs'
#model_name = 'cellpose_for_ladybugs'


if model_name == 'stardist_for_ladybugs':
    model_type = "Stardist Model"
    batch_dl.network_architecture_drop_down.setCurrentText(model_type)
    batch_dl.deep_learning_project.set_pretrained_model(os.path.join(model_path, model_name), model_type)
elif model_name == 'cellpose_for_ladybugs':
    model_type = "CellPose Instance Model"
    batch_dl.network_architecture_drop_down.setCurrentText(model_type)
    batch_dl.deep_learning_project.set_pretrained_model(os.path.join(model_path, model_name), model_type)

    
    model = batch_dl.deep_learning_project.models[model_type]
    model.prob_thresh = -1
    model.flow_thresh = 0.4
    model.chan_segment = 0 
    model.chan2 = 1

    widget = batch_dl.param_widgets[model_type]
    widget.sync_with_model()
No module named 'segment_everything'
found class  StardistInstanceModel
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.