blueye.sdk.cv_models
cv_models
Manage the computer vision model packages installed on the drone.
The Blueye X3 Ultra and X7 run CV model packages (an ONNX model plus a
model_meta.json, see the "Bundling CV models" documentation). This module wraps the
drone's HTTP API for managing those packages: listing, uploading, deleting,
downloading, configuring (autolaunch/device/rate), and pre-building inference engines.
The API is plain HTTP, so listing and downloading work on a Drone(auto_connect=False)
instance as well. The drone only picks up a change after a rescan, which is a control
message, so make changes from a Drone(connect_as_observer=True) instance: an observer
takes no control over the drone.
Classes:
-
CvModel–One CV model package installed on the drone.
-
CvModels–CV model package management on the drone.
CvModel
dataclass
CvModel(
name: str,
directory: str,
type: str,
output_format: str,
size_bytes: int,
labels: list[str],
enabled: bool,
raw: dict,
)
One CV model package installed on the drone.
Attributes:
-
name(str) –The human-readable model name from its model_meta.json.
-
directory(str) –The package's directory slug on the drone — this is the identifier the other methods take as
name. -
type(str) –"detection", "sot", or "unknown".
-
output_format(str) –The decoder format (e.g. "yolov8_flat").
-
size_bytes(int) –Size of the model weights file.
-
labels(list[str]) –Class labels.
-
enabled(bool) –Whether the model autolaunches on the drone (runtime.enabled).
-
raw(dict) –The verbatim API entry, including the optional preprocessing/detection/ sot/tracking/runtime blocks when present.
Methods:
-
from_json–Build a CvModel from one entry of the drone's API response.
from_json
classmethod
from_json(entry: dict) -> CvModel
Build a CvModel from one entry of the drone's API response.
Source code in blueye/sdk/cv_models.py
63 64 65 66 67 68 69 70 71 72 73 74 75 | |
CvModels
CvModels(parent_drone: 'blueye.sdk.Drone')
CV model package management on the drone.
Accessed through drone.cv_models, e.g.::
drone = blueye.sdk.Drone(auto_connect=False)
for model in drone.cv_models.list():
print(model.name, model.enabled)
All methods raise requests.exceptions.ConnectionError/ConnectTimeout when the
drone is unreachable, and requests.exceptions.HTTPError (with the drone's error
message included) when the drone rejects a request.
The listing and the changes go over HTTP and need no connection. The drone only picks
up a change after a rescan, which is a control message, so
upload,
delete and the set_* methods send one when
the drone is connected (an observer connection is enough) and log a warning when it is
not. rescan sends one on its own.
Methods:
-
delete–Delete a model package from the drone.
-
download–Download a model package from the drone as a zip.
-
list–List the model packages installed on the drone.
-
rescan–Ask the drone's vision pipeline to rescan the installed packages.
-
set_device–Set the execution provider a model runs on.
-
set_enabled–Enable or disable a model's autolaunch on the drone.
-
set_hz–Set a model's maximum inference rate.
-
upload–Upload a model package zip to the drone.
-
warmup–Pre-build the model's inference engine on the drone.
Source code in blueye/sdk/cv_models.py
99 100 | |
delete
delete(name: str, timeout: float = 5) -> None
Delete a model package from the drone.
Parameters:
-
name(str) –The package's directory slug (see CvModel.directory).
-
timeout(float, default:5) –Request timeout in seconds.
Source code in blueye/sdk/cv_models.py
159 160 161 162 163 164 165 166 167 | |
download
download(
name: str,
output_path: Path | str | None = None,
timeout: float = 60,
) -> Path
Download a model package from the drone as a zip.
Parameters:
-
name(str) –The package's directory slug.
-
output_path(Path | str | None, default:None) –Destination file or directory. Defaults to the filename the drone suggests (or
<name>.zip) in the current directory. -
timeout(float, default:60) –Request timeout in seconds.
Returns:
-
Path–The path the zip was written to.
Source code in blueye/sdk/cv_models.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
list
List the model packages installed on the drone.
Parameters:
-
timeout(float, default:5) –Request timeout in seconds.
Returns:
Source code in blueye/sdk/cv_models.py
121 122 123 124 125 126 127 128 129 130 131 132 | |
rescan
rescan(timeout: float | None = None) -> None
Ask the drone's vision pipeline to rescan the installed packages.
The request is the RescanCvModelsCtrl control message, so the drone has to be
connected; an observer connection is enough. The drone has no file watcher, so a
package uploaded, deleted or reconfigured stays as it was until a rescan or a reboot.
upload,
delete and the set_* methods send one
themselves while connected, so this is for changes made some other way. A rescan
restarts every running model, and models only run while a client in control pets the
watchdog.
Parameters:
-
timeout(float | None, default:None) –Ignored. The rescan used to be an HTTP request with a timeout; the argument stays so code written for 2.8.0 keeps working.
Raises:
-
ConnectionError–If the drone is not connected.
Source code in blueye/sdk/cv_models.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
set_device
set_device(
name: str, device: str, timeout: float = 5
) -> None
Set the execution provider a model runs on.
Parameters:
-
name(str) –The package's directory slug.
-
device(str) –One of :data:
VALID_DEVICES("cuda", "tensorrt", "tensorrt-dla0", "tensorrt-dla1"). -
timeout(float, default:5) –Request timeout in seconds.
Source code in blueye/sdk/cv_models.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
set_enabled
set_enabled(
name: str, enabled: bool, timeout: float = 5
) -> None
Enable or disable a model's autolaunch on the drone.
Parameters:
-
name(str) –The package's directory slug.
-
enabled(bool) –True to autolaunch the model, False to disable it.
-
timeout(float, default:5) –Request timeout in seconds.
Source code in blueye/sdk/cv_models.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
set_hz
set_hz(name: str, hz: int, timeout: float = 5) -> None
Set a model's maximum inference rate.
Parameters:
-
name(str) –The package's directory slug.
-
hz(int) –One of :data:
VALID_HZ(0, 5, 10, 15); 0 means unlimited. -
timeout(float, default:5) –Request timeout in seconds.
Source code in blueye/sdk/cv_models.py
228 229 230 231 232 233 234 235 236 237 | |
upload
upload(package: Path | str, timeout: float = 60) -> CvModel
Upload a model package zip to the drone.
The drone validates the archive (it must contain a valid model_meta.json and the model file it references) and installs it into a directory named after the slugified model name — an existing package with the same slug is replaced.
Parameters:
-
package(Path | str) –Path to the package zip (e.g. produced by
blueye bundle-model). -
timeout(float, default:60) –Request timeout in seconds; model files can be large.
Returns:
-
CvModel–The installed model as reported by the drone.
Source code in blueye/sdk/cv_models.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
warmup
warmup(name: str, timeout: float = 600) -> None
Pre-build the model's inference engine on the drone.
For TensorRT devices this compiles the engine, which can take several minutes — subsequent launches then start instantly. Only available on the drone itself (the API answers 503 elsewhere).
Parameters:
-
name(str) –The package's directory slug.
-
timeout(float, default:600) –Request timeout in seconds; engine builds are slow.
Source code in blueye/sdk/cv_models.py
239 240 241 242 243 244 245 246 247 248 249 250 | |