deeplabcut-docker 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- deeplabcut_docker-0.1.0.dist-info/METADATA +140 -0
- deeplabcut_docker-0.1.0.dist-info/RECORD +7 -0
- deeplabcut_docker-0.1.0.dist-info/WHEEL +5 -0
- deeplabcut_docker-0.1.0.dist-info/entry_points.txt +2 -0
- deeplabcut_docker-0.1.0.dist-info/licenses/LICENSE +165 -0
- deeplabcut_docker-0.1.0.dist-info/top_level.txt +1 -0
- deeplabcut_docker.py +216 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: deeplabcut-docker
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A helper package to launch DeepLabCut docker images
|
|
5
|
+
Author-email: M-Lab of Adaptive Intelligence <mackenzie@deeplabcut.org>, Mathis Group for Computational Neuroscience and AI <alexander@deeplabcut.org>
|
|
6
|
+
License-Expression: LGPL-3.0-or-later
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/DeepLabCut/DeepLabCut/issues
|
|
8
|
+
Project-URL: Homepage, https://github.com/DeepLabCut/DeepLabCut/tree/main/docker
|
|
9
|
+
Classifier: Operating System :: MacOS
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Utilities
|
|
16
|
+
Requires-Python: <3.13,>=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
deeplabcut:
|
|
23
|
+
last_content_updated: '2025-04-15'
|
|
24
|
+
last_metadata_updated: '2026-03-06'
|
|
25
|
+
ignore: false
|
|
26
|
+
---
|
|
27
|
+
(docker-containers)=
|
|
28
|
+
# DeepLabCut Docker containers
|
|
29
|
+
|
|
30
|
+
For DeepLabCut 2.2.0.2 and onwards, we provide container containers on [DockerHub](
|
|
31
|
+
https://hub.docker.com/r/deeplabcut/deeplabcut). Using Docker is an alternative approach
|
|
32
|
+
to using DeepLabCut, which only requires the user to install [Docker](
|
|
33
|
+
https://www.docker.com/) on your machine, vs. following the step-by-step installation
|
|
34
|
+
guide for a Anaconda setup. All dependencies needed to run DeepLabCut in the terminal or
|
|
35
|
+
running Jupyter notebooks with DeepLabCut pre-installed are shipped with the provided
|
|
36
|
+
Docker images.
|
|
37
|
+
|
|
38
|
+
The [`napari-deeplabcut` labelling GUI](
|
|
39
|
+
https://deeplabcut.github.io/DeepLabCut/docs/gui/napari_GUI.html) can be used to label
|
|
40
|
+
your data, but it cannot be run in a Docker container: it should be installed as
|
|
41
|
+
documented in the link above: `pip install napari-deeplabcut` (checkout the [workflow](
|
|
42
|
+
https://deeplabcut.github.io/DeepLabCut/docs/gui/napari_GUI.html#workflow) as well!).
|
|
43
|
+
|
|
44
|
+
Advanced users can directly head to [DockerHub](https://hub.docker.com/r/deeplabcut/deeplabcut) and use the provided images there. To get started with using the images, we however also provide a helper tool, `deeplabcut-docker`, which makes the transition to docker images particularly convenient; to install the tool, run
|
|
45
|
+
|
|
46
|
+
``` bash
|
|
47
|
+
$ pip install deeplabcut-docker
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
on your machine (potentially in a virtual environment, or an existing Anaconda environment).
|
|
51
|
+
Note that this will *not* disprupt or install Tensorflow, or any other DeepLabCut dependencies on your computer---the Docker containers are completely isolated from your existing software installation!
|
|
52
|
+
|
|
53
|
+
## Usage modes
|
|
54
|
+
|
|
55
|
+
With `deeplabcut-docker`, you can use the images in two modes.
|
|
56
|
+
|
|
57
|
+
- *Note 1: When running any of the following commands first, it can take some time to complete (a few minutes, depending on your internet connection), since it downloads the Docker image in the background. If you do not see any errors in your terminal, assume that everything is working fine! Subsequent runs of the command will be faster.*
|
|
58
|
+
- *Note 2: The labelling GUI cannot be used through the Docker images. However, you can install [`napari-deeplabcut`](https://github.com/DeepLabCut/napari-deeplabcut/tree/main?tab=readme-ov-file#napari-deeplabcut-keypoint-annotation-for-pose-estimation) in a conda environment to do the labelling!*
|
|
59
|
+
- *Note 3: For any mode below, you might want to set which directory is the base, namely, so you can have read/write (or read-only access). Here is how to do so:
|
|
60
|
+
If you want to mount the whole directory could e.g., pass*
|
|
61
|
+
|
|
62
|
+
`deeplabcut-docker bash -v /home/mackenzie/DEEPLABCUT:/home/mackenzie/DEEPLABCUT`
|
|
63
|
+
|
|
64
|
+
(which will mount the full directory into the container in read/write mode)
|
|
65
|
+
|
|
66
|
+
If read-only access is enough, `deeplabcut-docker bash -v /home/mackenzie/DEEPLABCUT:/home/mackenzie/DEEPLABCUT:ro`
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
### Terminal mode
|
|
70
|
+
|
|
71
|
+
You can run the light version of DeepLabCut and open a terminal by running
|
|
72
|
+
|
|
73
|
+
``` bash
|
|
74
|
+
$ deeplabcut-docker bash
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Important:** if have GPUs on your machine and want to use them to train models, you
|
|
78
|
+
need to pass the `--gpus all` argument to `deeplabcut-docker`:
|
|
79
|
+
|
|
80
|
+
``` bash
|
|
81
|
+
$ deeplabcut-docker bash --gpus all
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Inside the terminal, you can confirm that DeepLabCut is correctly installed by running and noting which version installs.
|
|
85
|
+
|
|
86
|
+
``` bash
|
|
87
|
+
$ ipython
|
|
88
|
+
>>> import deeplabcut
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Jupyter Notebook mode
|
|
92
|
+
|
|
93
|
+
You can run DeepLabCut by starting a jupyter notebook server. The corresponding image can be pulled and started by running
|
|
94
|
+
|
|
95
|
+
``` bash
|
|
96
|
+
$ deeplabcut-docker notebook
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
which will start a Jupyter notebook server. Follow the terminal instructions to open the notebook, by entering `http://127.0.0.1:8888` in your favorite browser. When prompted for a password, use `deeplabcut`, which is the pre-set option in the container.
|
|
100
|
+
|
|
101
|
+
The DeepLabCut version in this container is equivalent to the one you install with `pip install deeplabcut[gui]`. This means that you can start the DeepLabCut GUI with the appropriate commands in your notebook!
|
|
102
|
+
|
|
103
|
+
### Advanced usage
|
|
104
|
+
|
|
105
|
+
Advanced users and developers can visit the [`/docker` subdirectory](https://github.com/DeepLabCut/DeepLabCut/tree/main/docker) in the DeepLabCut codebase on Github. We provide Dockerfiles for all images, along with build instructions there.
|
|
106
|
+
|
|
107
|
+
## Prerequisites (if you don't have Docker installed already)
|
|
108
|
+
|
|
109
|
+
**(1)** Install Docker. See https://docs.docker.com/install/ & for Ubuntu: https://docs.docker.com/install/linux/docker-ce/ubuntu/
|
|
110
|
+
Test docker:
|
|
111
|
+
|
|
112
|
+
$ sudo docker run hello-world
|
|
113
|
+
|
|
114
|
+
The output should be: ``Hello from Docker! This message shows that your installation appears to be working correctly.``
|
|
115
|
+
|
|
116
|
+
*if you get the error ``docker: Error response from daemon: Unknown runtime specified nvidia.`` just simply restart docker:
|
|
117
|
+
|
|
118
|
+
$ sudo systemctl daemon-reload
|
|
119
|
+
$ sudo systemctl restart docker
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
**(2)** Add your user to the docker group (https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user)
|
|
123
|
+
Quick guide to create the docker group and add your user:
|
|
124
|
+
Create the docker group.
|
|
125
|
+
|
|
126
|
+
$ sudo groupadd docker
|
|
127
|
+
Add your user to the docker group.
|
|
128
|
+
|
|
129
|
+
$ sudo usermod -aG docker $USER
|
|
130
|
+
|
|
131
|
+
(perhaps restart your computer (best) or (at min) open a new terminal to make sure that you are added from now on)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
## Notes and troubleshooting
|
|
135
|
+
|
|
136
|
+
We dropped GUI support in 2.3.5+ due to too many numerous issues supporting them. Also please note these are tested on unix systems.
|
|
137
|
+
|
|
138
|
+
When running containers on Linux, in some systems it might be necessary to run `host +local:docker` before starting the image via `deeplabcut-docker`.
|
|
139
|
+
|
|
140
|
+
If you encounter errors while using the images, please open an issue in the DeepLabCut repo---especially the `deeplabcut-docker` is still in its alpha version, and we appreciate user feedback to make the tool robust to use across many operating systems!
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
deeplabcut_docker.py,sha256=sMY-pm1LrFij6EEf69h8bjKDXO8BKkvsDghxe9Ge5R0,7737
|
|
2
|
+
deeplabcut_docker-0.1.0.dist-info/licenses/LICENSE,sha256=2n6rt7r999OuXp8iOqW9we7ORaxWncIbOwN1ILRGR2g,7651
|
|
3
|
+
deeplabcut_docker-0.1.0.dist-info/METADATA,sha256=jjNGpjWguMywWaJ4n8SzO__NXfmz4ywJIsaEh-AYyN8,6864
|
|
4
|
+
deeplabcut_docker-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
+
deeplabcut_docker-0.1.0.dist-info/entry_points.txt,sha256=zMq6qIlrtYQ4-mUqZQofn8WztWXJD63krZraym56NuU,61
|
|
6
|
+
deeplabcut_docker-0.1.0.dist-info/top_level.txt,sha256=wLEcuyI_Jtrla3mnY5KFE4mM4JWZy8zbWDVkM5UTzAE,18
|
|
7
|
+
deeplabcut_docker-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
deeplabcut_docker
|
deeplabcut_docker.py
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Helper CLI to run DeepLabCut Docker images (LGPL-3.0)."""
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import grp
|
|
6
|
+
import os
|
|
7
|
+
import platform
|
|
8
|
+
import pwd
|
|
9
|
+
import shlex
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
from datetime import datetime, timezone
|
|
13
|
+
|
|
14
|
+
__version__ = "0.1.0"
|
|
15
|
+
|
|
16
|
+
_IMAGE = "deeplabcut/deeplabcut"
|
|
17
|
+
_DEFAULT_CUDA = "12.4"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _docker() -> list[str]:
|
|
21
|
+
"""Return the docker CLI argv prefix (from DOCKER env or `docker`)."""
|
|
22
|
+
return shlex.split(os.environ.get("DOCKER", "docker"))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _log(msg: str) -> None:
|
|
26
|
+
"""Log a timestamped message to stderr."""
|
|
27
|
+
ts = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S%z")
|
|
28
|
+
print(f"[{ts}]: {msg}", file=sys.stderr)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _check_system() -> None:
|
|
32
|
+
"""Verify docker group membership on Linux; warn on macOS."""
|
|
33
|
+
if platform.system() == "Linux":
|
|
34
|
+
if os.environ.get("DOCKER", "docker").strip() == "sudo docker":
|
|
35
|
+
return
|
|
36
|
+
if os.geteuid() == 0:
|
|
37
|
+
return
|
|
38
|
+
try:
|
|
39
|
+
docker_gid = grp.getgrnam("docker").gr_gid
|
|
40
|
+
except KeyError:
|
|
41
|
+
return
|
|
42
|
+
if docker_gid not in os.getgroups():
|
|
43
|
+
_log(f'The current user {os.getuid()} is not in the "docker" group.')
|
|
44
|
+
_log('Use DOCKER="sudo docker" (with care) or add your user to "docker".')
|
|
45
|
+
sys.exit(1)
|
|
46
|
+
elif platform.system() == "Darwin":
|
|
47
|
+
_log("macOS support is experimental; report issues at")
|
|
48
|
+
_log("https://github.com/DeepLabCut/DeepLabCut/issues")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _remote_tag(mode: str) -> str:
|
|
52
|
+
"""Get the DockerHub image tag from DLC_VERSION and CUDA_VERSION env vars."""
|
|
53
|
+
cuda = os.environ.get("CUDA_VERSION", _DEFAULT_CUDA)
|
|
54
|
+
ver = os.environ.get("DLC_VERSION", "").strip()
|
|
55
|
+
if mode == "notebook":
|
|
56
|
+
if ver:
|
|
57
|
+
return f"{_IMAGE}:{ver}-jupyter-cuda{cuda}"
|
|
58
|
+
return f"{_IMAGE}:latest-jupyter"
|
|
59
|
+
if ver:
|
|
60
|
+
return f"{_IMAGE}:{ver}-core-cuda{cuda}"
|
|
61
|
+
return f"{_IMAGE}:latest"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _warn_if_not_jupyter_image(ref: str) -> None:
|
|
65
|
+
"""Warn if the image does not appear to have a Jupyter entrypoint."""
|
|
66
|
+
r = subprocess.run(
|
|
67
|
+
_docker()
|
|
68
|
+
+ [
|
|
69
|
+
"image",
|
|
70
|
+
"inspect",
|
|
71
|
+
ref,
|
|
72
|
+
"--format",
|
|
73
|
+
"{{json .Config.Entrypoint}} {{json .Config.Cmd}}",
|
|
74
|
+
],
|
|
75
|
+
capture_output=True,
|
|
76
|
+
text=True,
|
|
77
|
+
)
|
|
78
|
+
if r.returncode != 0:
|
|
79
|
+
sys.exit(f"Could not inspect image {ref!r} after pull.\n{r.stderr.strip()}")
|
|
80
|
+
blob = (r.stdout or "").lower()
|
|
81
|
+
if "jupyter" not in blob:
|
|
82
|
+
_log(
|
|
83
|
+
f"Warning: image {ref!r} does not appear to have a Jupyter entrypoint. "
|
|
84
|
+
"Proceeding anyway — if the server fails to start, ensure the image "
|
|
85
|
+
"exposes a Jupyter-compatible entrypoint on port 8888."
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _build_user_image(remote: str, local: str) -> None:
|
|
90
|
+
"""Build a small local image on top of remote with the current UID/GID user."""
|
|
91
|
+
try:
|
|
92
|
+
uid, gid = os.getuid(), os.getgid()
|
|
93
|
+
except AttributeError:
|
|
94
|
+
sys.exit("deeplabcut-docker requires a POSIX system (Linux or macOS).")
|
|
95
|
+
user = pwd.getpwuid(uid).pw_name
|
|
96
|
+
group = grp.getgrgid(gid).gr_name
|
|
97
|
+
_log(f"Configuring a local image for user {user} ({uid}) in group {group} ({gid})")
|
|
98
|
+
dockerfile = (
|
|
99
|
+
"\n".join(
|
|
100
|
+
(
|
|
101
|
+
f"FROM {remote}",
|
|
102
|
+
f"RUN mkdir -p /home/{user} /app",
|
|
103
|
+
f"RUN groupadd -g {gid} {group} || groupmod -o -g {gid} {group}",
|
|
104
|
+
f"RUN useradd -d /home/{user} -s /bin/bash -u {uid} -g {gid} {user}",
|
|
105
|
+
f"RUN chown -R {user}:{group} /home/{user} /app",
|
|
106
|
+
f"USER {user}",
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
+ "\n"
|
|
110
|
+
)
|
|
111
|
+
subprocess.run(
|
|
112
|
+
_docker() + ["build", "-q", "-t", local, "-"],
|
|
113
|
+
input=dockerfile.encode(),
|
|
114
|
+
check=True,
|
|
115
|
+
)
|
|
116
|
+
_log("Build succeeded")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _supplementary_group_args() -> list[str]:
|
|
120
|
+
"""Return --group-add flags for each supplementary group of the current user."""
|
|
121
|
+
primary_gid = os.getgid()
|
|
122
|
+
args = []
|
|
123
|
+
for gid in os.getgroups():
|
|
124
|
+
if gid != primary_gid:
|
|
125
|
+
args += ["--group-add", str(gid)]
|
|
126
|
+
return args
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _parse_args() -> tuple[argparse.Namespace, list[str]]:
|
|
130
|
+
"""Parse CLI args and return (namespace, extra args for docker run)."""
|
|
131
|
+
parser = argparse.ArgumentParser(
|
|
132
|
+
prog="deeplabcut-docker",
|
|
133
|
+
description=(
|
|
134
|
+
"Launch DeepLabCut Docker containers. The current directory is mounted "
|
|
135
|
+
"at /app and used as the working directory. Additional arguments are "
|
|
136
|
+
"passed through to `docker run` (see "
|
|
137
|
+
"https://docs.docker.com/engine/reference/commandline/cli/)."
|
|
138
|
+
),
|
|
139
|
+
)
|
|
140
|
+
parser.add_argument(
|
|
141
|
+
"container",
|
|
142
|
+
choices=("notebook", "bash"),
|
|
143
|
+
help=(
|
|
144
|
+
"notebook: Jupyter server; bash: interactive shell. "
|
|
145
|
+
"Image tags: https://hub.docker.com/r/deeplabcut/deeplabcut/tags — "
|
|
146
|
+
"use DLC_VERSION and CUDA_VERSION to select a versioned tag; unset "
|
|
147
|
+
"DLC_VERSION uses latest / latest-jupyter."
|
|
148
|
+
),
|
|
149
|
+
)
|
|
150
|
+
parser.add_argument(
|
|
151
|
+
"--image",
|
|
152
|
+
metavar="REF",
|
|
153
|
+
help=(
|
|
154
|
+
"Use this image (name:tag or digest) instead of the default from "
|
|
155
|
+
"DLC_VERSION / CUDA_VERSION. For notebook, the image is checked for "
|
|
156
|
+
"a Jupyter Notebook entrypoint after pull."
|
|
157
|
+
),
|
|
158
|
+
)
|
|
159
|
+
return parser.parse_known_args()
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _pull_image(remote: str, *, skip_if_local: bool = True) -> None:
|
|
163
|
+
"""Pull the image; skip the pull if it already exists locally and skip_if_local is True."""
|
|
164
|
+
if skip_if_local:
|
|
165
|
+
r = subprocess.run(
|
|
166
|
+
_docker() + ["image", "inspect", remote],
|
|
167
|
+
capture_output=True,
|
|
168
|
+
text=True,
|
|
169
|
+
)
|
|
170
|
+
if r.returncode == 0:
|
|
171
|
+
_log(f"Using local image {remote!r} (skipping pull)")
|
|
172
|
+
return
|
|
173
|
+
if r.stderr:
|
|
174
|
+
_log(f"`docker image inspect` stderr: {r.stderr.strip()}")
|
|
175
|
+
_log(f"Pulling image {remote!r}...")
|
|
176
|
+
try:
|
|
177
|
+
subprocess.run(_docker() + ["pull", remote], check=True)
|
|
178
|
+
except subprocess.CalledProcessError as e:
|
|
179
|
+
_log(f"Failed to pull image {remote!r}. Verify the image name/tag and that Docker is running and accessible.")
|
|
180
|
+
sys.exit(e.returncode)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def main() -> None:
|
|
184
|
+
"""Entry point: pull, user-layer build, and run the container."""
|
|
185
|
+
_check_system()
|
|
186
|
+
args, docker_run_args = _parse_args()
|
|
187
|
+
mode = args.container
|
|
188
|
+
|
|
189
|
+
remote = args.image or _remote_tag(mode)
|
|
190
|
+
local = f"deeplabcut-local-{mode}"
|
|
191
|
+
try_local_image = bool(args.image or os.environ.get("DLC_VERSION", "").strip())
|
|
192
|
+
_pull_image(remote, skip_if_local=try_local_image)
|
|
193
|
+
if mode == "notebook":
|
|
194
|
+
_warn_if_not_jupyter_image(remote)
|
|
195
|
+
_build_user_image(remote, local)
|
|
196
|
+
|
|
197
|
+
run = _docker() + ["run", "-it", "--rm", "-v", f"{os.getcwd()}:/app", "-w", "/app"]
|
|
198
|
+
run += _supplementary_group_args()
|
|
199
|
+
if mode == "notebook":
|
|
200
|
+
port = os.environ.get("DLC_NOTEBOOK_PORT", "8888")
|
|
201
|
+
token = os.environ.get("NOTEBOOK_TOKEN", "deeplabcut")
|
|
202
|
+
_log("Starting the notebook server.")
|
|
203
|
+
_log(f"Open your browser at http://127.0.0.1:{port}")
|
|
204
|
+
if token == "":
|
|
205
|
+
_log("Warning: NOTEBOOK_TOKEN is empty — Jupyter token authentication is disabled.")
|
|
206
|
+
elif token == "deeplabcut":
|
|
207
|
+
_log(f"If prompted for a token, enter {token!r}.")
|
|
208
|
+
else:
|
|
209
|
+
_log("If prompted for a token, enter the value of NOTEBOOK_TOKEN.")
|
|
210
|
+
run += ["-p", f"127.0.0.1:{port}:8888", "-e", f"NOTEBOOK_TOKEN={token}"]
|
|
211
|
+
run += docker_run_args + [local] + ([] if mode == "notebook" else ["bash"])
|
|
212
|
+
sys.exit(subprocess.run(run).returncode)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
if __name__ == "__main__":
|
|
216
|
+
main()
|