Package: napari-deeplabcut
napari-deeplabcut: keypoint annotation for pose estimation📚Documentation|🛠️ DeepLabCut Installation|🌎 Home Page|A napari plugin for keypoint annotation, also used within DeepLabCut!InstallationIf you installed DeepLabCut[gui], this plugin is already installed. However, you can also use this as a stand-alone keypoint annotator without using DeepLabCut. Instructions below!Start by installing PySide6 withpip install "pyside6<6.3.2"; this is the library we now use to build GUIs.You can then installnapari-deeplabcutviapip:pip install napari-deeplabcutAlternatively, to install the latest development version, run:pip install git+https://github.com/DeepLabCut/napari-deeplabcut.gitUsageTo use the plugin, please run:napariThen, activate the plugin in Plugins > napari-deeplabcut: Keypoint controls.All accepted files (config.yaml, images, h5 data files) can be loaded
either by dropping them directly onto the canvas or via the File menu.The easiest way to get started is to drop a folder (typically a folder from within a DeepLabCut'slabeled-datadirectory), and, if labeling from scratch, drop the correspondingconfig.yamlto automatically add aPoints layerand populate the dropdown menus.🎥 DEMOTools & shortcuts are:2and3, to easily switch between labeling and selection mode4, to enable pan & zoom (which is achieved using the mouse wheel or finger scrolling on the Trackpad)M, to cycle through regular (sequential), quick, and cycle annotation mode (see the descriptionhere)E, to enable edge coloring (by default, if using this in refinement GUI mode, points with a confidence lower than 0.6 are marked
in red)F, to toggle between animal and body part color scheme.V, to toggle visibility of the selected layer.backspaceto delete a point.Check the box "display text" to show the label names on the canvas.To move to another folder, be sure to save (Ctrl+S), then delete the layers, and re-drag/drop the next folder.Save LayersAnnotations and segmentations are saved withFile > Save Selected Layer(s)...(or its shortcutCtrl+S).
Only when saving segmentation masks does a save file dialog pop up to name the destination folder;
keypoint annotations are otherwise automatically saved in the corresponding folder asCollectedData_<ScorerName>.h5.As a reminder, DLC will only use the H5 file; so be sure if you open already labeled images you save/overwrite the H5.Note, before saving a layer, make sure the points layer is selected. If the user clicked on the image(s) layer first, doesSave As, then closes the window, any labeling work during that session will be lost!Modifying and then saving points in amachinelabels...layer will add to or overwrite the existingCollectedDatalayer and willnotsave to themachinelabelsfile.Video frame extraction and prediction refinementSince v0.0.4, videos can be viewed in the GUI.Since v0.0.5, trailing points can be visualized; e.g., helping in the identification
of swaps or outlier, jittery predictions.Loading a video (and its corresponding output h5 file) will enable the video actions
at the top of the dock widget: they offer the option to manually extract video
frames from the GUI, or to define cropping coordinates.
Note that keypoints can be displaced and saved, as when annotating individual frames.WorkflowSuggested workflows, depending on the image folder contents:Labeling from scratch– the image folder does not containCollectedData_<ScorerName>.h5file.Opennaparias described inUsageand open an image folder together with the DeepLabCut project'sconfig.yaml.
The image folder creates animage layerwith the images to label.
Supported image formats are:jpg,jpeg,png.
Theconfig.yamlfile creates aPoints layer, which holds metadata (such as keypoints read from the config file) necessary for labeling.
Select thePoints layerin the layer list (lower left pane on the GUI) and click on the+-symbol in the layer controls menu (upper left pane) to start labeling.
The current keypoint can be viewed/selected in the keypoints dropdown menu (right pane).
The slider below the displayed image (or the left/right arrow keys) allows selecting the image to label.To save the labeling progress refer toSave Layers.Data successfully savedshould be shown in the status bar, and the image folder should now contain aCollectedData_<ScorerName>.h5file.
(Note: For convenience, a CSV file with the same name is also saved.)Resuming labeling– the image folder contains aCollectedData_<ScorerName>.h5file.Opennapariand open an image folder (which needs to contain aCollectedData_<ScorerName>.h5file).
In this case, it is not necessary to open the DLC project'sconfig.yamlfile, as all necessary metadata is read from theh5data file.Saving works as described in1.Note that if a new body part has been added to theconfig.yamlfile after having started to label, loading the config in the GUI is necessary to update the dropdown menus and other metadata.Asviridisisnapari-deeplabcutdefault colormap, loading the config in the GUI is also needed to update the color scheme.Refining labels– the image folder contains amachinelabels-iter<#>.h5file.The process is analog to2.
Opennapariand open an image folder.
If the video was originally labeled,andhad outliers extracted it will contain aCollectedData_<ScorerName>.h5file and amachinelabels-iter<#>.h5file. In this case, select themachinelabelslayer in the GUI, and typeeto show edges. Red indicates likelihood < 0.6. As you navigate through frames, images with labels with edges will need to be refined (moved, deleted, etc). Images with labels without edges will be on theCollectedData(previous manual annotations) layer and shouldn't need refining. However, you can switch to that layer and fix errors. You can also right-click on theCollectedDatalayer and selecttoggle visibilityto hide that layer. Select themachinelabelslayer before saving which will append your refined annotations toCollectedData.If the folder only had outliers extracted and wasn't originally labeled, it will not have aCollectedDatalayer. Work with themachinelabelslayer selected to refine annotation positions, then save.In this case, it is not necessary to open the DLC project'sconfig.yamlfile, as all necessary metadata is read from theh5data file.Saving works as described in1.Drawing segmentation masksDrop an image folder as in1, manually add ashapes layer. Then select therectanglein the layer controls (top left pane),
and start drawing rectangles over the images. Masks and rectangle vertices are saved as described inSave Layers.
Note that masks can be reloaded and edited at a later stage by dropping thevertices.csvfile onto the canvas.Workflow flowchart%%{init: {"flowchart": {"htmlLabels": false}} }%%
graph TD
  id1[What stage of labeling?]
  id2[deeplabcut.label_frames]
  id3[deeplabcut.refine_labels]
  id4[Add labels to, or modify in, \n `CollectedData...` layer and save that layer]
  id5[Modify labels in `machinelabels` layer and save \n which will create a `CollectedData...` file]
  id6[Have you refined some labels from the most recent iteration and saved already?]
  id7["All extracted frames are already saved in `CollectedData...`.
1. Hide or trash all `machinelabels` layers.
2. Then modify in and save `CollectedData`"]
  id8["
1. hide or trash all `machinelabels` layers except for the most recent.
2. Select most recent `machinelabels` and hit `e` to show edges.
3. Modify only in `machinelabels` and skip frames with labels without edges shown.
4. Save `machinelabels` layer, which will add data to `CollectedData`.
	- If you need to revisit this video later, ignore `machinelabels` and work only in `CollectedData`"]

  id1 -->|I need to manually label new frames \n or fix my labels|id2
  id1 ---->|I need to refine outlier frames \nfrom analyzed videos|id3
  id2 -->id4
  id3 -->|I only have a `machinelabels...` file|id5
  id3 ---->|I have both `machinelabels` and `CollectedData` files|id6
  id6 -->|yes|id7
  id6 ---->|no, I just extracted outliers|id8Labeling multiple image foldersLabeling multiple image folders has to be done in sequence; i.e., only one image folder can be opened at a time.
After labeling the images of a particular folder is done and the associatedPoints layerhas been saved,alllayers should be removed from the layers list (lower left pane on the GUI) by selecting them and clicking on the trashcan icon.
Now, another image folder can be labeled, following the process described in1,2, or3, depending on the particular image folder.Defining cropping coordinatesPrior to defining cropping coordinates, two elements should be loaded in the GUI:
a video and the DLC project'sconfig.yamlfile (into which the crop dimensions will be stored).
Then it suffices to add aShapes layer, draw arectanglein it with the desired area,
and hit the buttonStore crop coordinates; coordinates are automatically written to the configuration file.ContributingContributions are very welcome. Tests can be run withtox, please ensure
the coverage at least stays the same before you submit a pull request.To locally install the code, please git clone the repo and then runpip install -e .LicenseDistributed under the terms of theBSD-3license,
"napari-deeplabcut" is free and open source software.IssuesIf you encounter any problems, pleasefile an issuealong with a detailed description.AcknowledgementsThisnapariplugin was generated withCookiecutterusing@napari'scookiecutter-napari-plugintemplate. We thank the Chan Zuckerberg Initiative (CZI) for funding the initial development of this work!