Label and Predict#
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
try:
from napari_easy_augment_batch_dl.frameworks.cellpose_instance_framework import CellPoseInstanceFramework
except:
print('CellPoseInstanceFramework not loaded')
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_series')
model_path = os.path.join(parent_path, 'models')
model_name = 'cellpose_ladybugs_scale2'
#mod = models.Cellpose(gpu=True, model_type="cyto3")
model_type = "CellPose Instance Model"
batch_dl.load_image_directory(parent_path)
if model_name is not None:
# set the drop down to the CellPoseInstanceFramework
batch_dl.network_architecture_drop_down.setCurrentText(CellPoseInstanceFramework.descriptor)
# get the cellpose widget
widget = batch_dl.deep_learning_widgets[CellPoseInstanceFramework.descriptor]
# load model
widget.load_model_from_path(os.path.join(model_path, model_name))
# get the framework object
framework = batch_dl.deep_learning_project.frameworks[CellPoseInstanceFramework.descriptor]
# set the parameters for the cellpose framework
framework.prob_thresh = -1
framework.flow_thresh = 0.4
framework.chan_segment = 0
framework.chan2 = 1
# sync parameters on the widget after this we should see the widget in Napari synced with the parameters we set on the framework
widget.sync_with_framework()
VIT checkpoint loaded successfully
found framework is MobileSAMFramework
found framework is YoloSAMFramework
found framework is RandomForestFramework
found framework is PytorchSemanticFramework
found framework is CellPoseInstanceFramework
creating new log file
2025-02-13 18:54:19,541 [INFO] WRITING LOG OUTPUT TO C:\Users\bnort\.cellpose\run.log
2025-02-13 18:54:19,542 [INFO]
cellpose version: 3.1.0
platform: win32
python version: 3.10.14
torch version: 2.2.2+cu118
Zarr store already up-to-date.
Zarr store already up-to-date.
2025-02-13 18:54:22,297 [INFO] ** TORCH CUDA version installed and working. **
2025-02-13 18:54:22,298 [INFO] >>>> using GPU (CUDA)
2025-02-13 18:54:22,420 [INFO] >>>> loading model ../../data\ladybugs_series\models\cellpose_ladybugs_scale2
2025-02-13 18:54:22,620 [INFO] >>>> model diam_mean = 30.000 (ROIs rescaled to this size during training)
2025-02-13 18:54:22,622 [INFO] >>>> model diam_labels = 181.358 (mean diameter of training ROIs)
'QCheckBox' object has no attribute 'setValue'