Skip to content

Commit ae3f03a

Browse files
authored
Merge pull request #1285 from luxonis/v3_zoo02
use an env variable to specify where new zoo models are to be cached
2 parents c09f617 + e236c31 commit ae3f03a

26 files changed

+704
-436
lines changed

.github/workflows/zoo_helper.workflow.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ jobs:
4343
pip3 install jinja2
4444
4545
- name: Configure project
46-
run: cmake -S . -B build -DDEPTHAI_ENABLE_CURL=ON -DCMAKE_BUILD_TYPE=MinSizeRel
46+
run: |
47+
git config --global --add safe.directory $(pwd)
48+
cmake -S . -B build -DDEPTHAI_ENABLE_CURL=ON -DCMAKE_BUILD_TYPE=MinSizeRel
4749
4850
- name: Build zoo_helper
4951
run: cmake --build build --target zoo_helper --parallel 4
@@ -98,7 +100,9 @@ jobs:
98100
pip3 install ninja # ninja is needed for cmake on arm64
99101
100102
- name: Configure project
101-
run: cmake -S . -B build -DDEPTHAI_ENABLE_CURL=ON -DCMAKE_BUILD_TYPE=MinSizeRel
103+
run: |
104+
git config --global --add safe.directory $(pwd)
105+
cmake -S . -B build -DDEPTHAI_ENABLE_CURL=ON -DCMAKE_BUILD_TYPE=MinSizeRel
102106
103107
- name: Build zoo_helper
104108
run: cmake --build build --target zoo_helper --parallel 4

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ set(TARGET_CORE_SOURCES
462462
src/utility/ArchiveUtil.cpp
463463
src/nn_archive/NNArchive.cpp
464464
src/nn_archive/NNArchiveVersionedConfig.cpp
465-
src/modelzoo/NNModelDescription.cpp
466465
src/modelzoo/Zoo.cpp
467466
)
468467

@@ -527,7 +526,6 @@ find_package(yaml-cpp REQUIRED)
527526
set(ZOO_HELPER_SOURCES
528527
src/modelzoo/zoo_helper.cpp
529528
src/modelzoo/Zoo.cpp
530-
src/modelzoo/NNModelDescription.cpp
531529
src/utility/Environment.cpp
532530
src/utility/Logging.cpp
533531
)

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,11 @@ The following environment variables can be set to alter default behavior of the
189189
| DEPTHAI_CRASHDUMP | Directory in which to save the crash dump. |
190190
| DEPTHAI_CRASHDUMP_TIMEOUT | Specifies the duration in seconds to wait for device reboot when obtaining a crash dump. Crash dump retrieval disabled if 0. |
191191
| DEPTHAI_DISABLE_FEEDBACK | Disables crash dump and pipeline schema collection used to improve the library |
192-
| DEPTHAI_HUB_API_KEY | (Default) API key for the Luxonis Hub |
193-
| DEPTHAI_ZOO_INTERNET_CHECK | (Default) 1 - perform internet check, 0 - skip internet check |
192+
| DEPTHAI_HUB_API_KEY | API key for the Luxonis Hub |
193+
| DEPTHAI_ZOO_INTERNET_CHECK | (Default) 1 - perform internet check, if available, download the newest model version 0 - skip internet check and use cached model |
194194
| DEPTHAI_ZOO_INTERNET_CHECK_TIMEOUT | (Default) 1000 - timeout in milliseconds for the internet check |
195+
| DEPTHAI_ZOO_CACHE_PATH | (Default) .depthai_cached_models - Folder where cached zoo models are stored |
196+
| DEPTHAI_ZOO_MODELS_PATH | (Default) depthai_models - Folder where zoo model description files are stored |
195197
| DEPTHAI_RECORD | Enables holistic record to the specified directory. |
196198
| DEPTHAI_REPLAY | Replays holistic replay from the specified file or directory. |
197199

bindings/python/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ set(SOURCE_LIST
147147
src/capabilities/CapabilityRangeBindings.cpp
148148
src/capabilities/ImgFrameCapabilityBindings.cpp
149149

150-
src/modelzoo/NNModelDescriptionBindings.cpp
151150
src/modelzoo/ZooBindings.cpp
152151

153152
src/remote_connection/RemoteConnectionBindings.cpp

bindings/python/src/modelzoo/NNModelDescriptionBindings.cpp

Lines changed: 0 additions & 94 deletions
This file was deleted.

bindings/python/src/modelzoo/NNModelDescriptionBindings.hpp

Lines changed: 0 additions & 8 deletions
This file was deleted.

bindings/python/src/modelzoo/ZooBindings.cpp

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
void ZooBindings::bind(pybind11::module& m, void* pCallstack) {
77
using namespace dai;
88

9+
// modelzoo namespace
10+
py::module modelzoo = m.def_submodule("modelzoo", "Model Zoo");
11+
12+
// Type definitions
13+
py::class_<NNModelDescription> modelDescription(m, "NNModelDescription", DOC(dai, NNModelDescription));
14+
py::class_<SlugComponents> slugComponents(m, "SlugComponents", DOC(dai, SlugComponents));
15+
py::implicitly_convertible<std::string, NNModelDescription>();
16+
917
///////////////////////////////////////////////////////////////////////
1018
///////////////////////////////////////////////////////////////////////
1119
///////////////////////////////////////////////////////////////////////
@@ -22,14 +30,93 @@ void ZooBindings::bind(pybind11::module& m, void* pCallstack) {
2230
getModelFromZoo,
2331
py::arg("modelDescription"),
2432
py::arg("useCached") = true,
25-
py::arg("cacheDirectory") = MODEL_ZOO_DEFAULT_CACHE_DIRECTORY,
33+
py::arg("cacheDirectory") = "",
2634
py::arg("apiKey") = "",
2735
DOC(dai, getModelFromZoo));
2836

2937
m.def("downloadModelsFromZoo",
3038
downloadModelsFromZoo,
3139
py::arg("path"),
32-
py::arg("cacheDirectory") = MODEL_ZOO_DEFAULT_CACHE_DIRECTORY,
40+
py::arg("cacheDirectory") = "",
3341
py::arg("apiKey") = "",
3442
DOC(dai, downloadModelsFromZoo));
43+
44+
// Bind NNModelDescription
45+
modelDescription.def(py::init<>())
46+
.def(py::init([](const std::string& model,
47+
const std::string& platform,
48+
const std::string& optimizationLevel,
49+
const std::string& compressionLevel,
50+
const std::string& snpeVersion,
51+
const std::string& modelPrecisionType) {
52+
return NNModelDescription{model, platform, optimizationLevel, compressionLevel, snpeVersion, modelPrecisionType};
53+
}),
54+
py::arg("model"),
55+
py::arg("platform") = "",
56+
py::arg("optimizationLevel") = "",
57+
py::arg("compressionLevel") = "",
58+
py::arg("snpeVersion") = "",
59+
py::arg("modelPrecisionType") = "")
60+
61+
.def(py::init([](const std::string& modelSlug,
62+
const std::string& platform,
63+
const std::string& modelVersionSlug,
64+
const std::string& modelInstanceHash,
65+
const std::string& optimizationLevel,
66+
const std::string& compressionLevel,
67+
const std::string& teamName,
68+
const std::string& snpeVersion,
69+
const std::string& modelPrecisionType) {
70+
PyErr_WarnEx(PyExc_DeprecationWarning,
71+
"Constructor with split out model slug is deprecated, use NNModelDescription(model, platform, optimizationLevel, ...) instead.",
72+
1);
73+
SlugComponents slugComponents = SlugComponents{teamName, modelSlug, modelVersionSlug, modelInstanceHash};
74+
return NNModelDescription{slugComponents.merge(), platform, optimizationLevel, compressionLevel, snpeVersion, modelPrecisionType};
75+
}),
76+
py::arg("modelSlug"),
77+
py::arg("platform") = "",
78+
py::arg("modelVersionSlug") = "",
79+
py::arg("modelInstanceHash") = "",
80+
py::arg("optimizationLevel") = "",
81+
py::arg("compressionLevel") = "",
82+
py::arg("teamName") = "",
83+
py::arg("snpeVersion") = "",
84+
py::arg("modelPrecisionType") = "")
85+
86+
.def(py::init<>([](const std::string& model) { return NNModelDescription{model}; }), py::arg("model"))
87+
.def_static("fromYamlFile", &NNModelDescription::fromYamlFile, py::arg("yamlPath"), py::arg("modelsPath") = "", DOC(dai, NNModelDescription, fromYamlFile))
88+
.def("saveToYamlFile", &NNModelDescription::saveToYamlFile, py::arg("yamlPath"), DOC(dai, NNModelDescription, saveToYamlFile))
89+
.def("check", &NNModelDescription::check, DOC(dai, NNModelDescription, check))
90+
.def("toString", &NNModelDescription::toString, DOC(dai, NNModelDescription, toString))
91+
.def("__str__", &NNModelDescription::toString, DOC(dai, NNModelDescription, toString))
92+
.def_readwrite("model", &NNModelDescription::model, DOC(dai, NNModelDescription, model))
93+
.def_readwrite("platform", &NNModelDescription::platform, DOC(dai, NNModelDescription, platform))
94+
.def_readwrite("optimizationLevel", &NNModelDescription::optimizationLevel, DOC(dai, NNModelDescription, optimizationLevel))
95+
.def_readwrite("compressionLevel", &NNModelDescription::compressionLevel, DOC(dai, NNModelDescription, compressionLevel))
96+
.def_readwrite("snpeVersion", &NNModelDescription::snpeVersion, DOC(dai, NNModelDescription, snpeVersion))
97+
.def_readwrite("modelPrecisionType", &NNModelDescription::modelPrecisionType, DOC(dai, NNModelDescription, modelPrecisionType));
98+
99+
// Bind SlugComponents
100+
slugComponents.def(py::init<>())
101+
.def(py::init<const std::string&, const std::string&, const std::string&, const std::string&>(),
102+
py::arg("teamName") = "",
103+
py::arg("modelSlug") = "",
104+
py::arg("modelVariantSlug") = "",
105+
py::arg("modelRef") = "")
106+
.def("merge", &SlugComponents::merge, DOC(dai, SlugComponents, merge))
107+
.def_static("split", &SlugComponents::split, py::arg("slug"), DOC(dai, SlugComponents, split))
108+
.def_readwrite("teamName", &SlugComponents::teamName, DOC(dai, SlugComponents, teamName))
109+
.def_readwrite("modelSlug", &SlugComponents::modelSlug, DOC(dai, SlugComponents, modelSlug))
110+
.def_readwrite("modelVariantSlug", &SlugComponents::modelVariantSlug, DOC(dai, SlugComponents, modelVariantSlug))
111+
.def_readwrite("modelRef", &SlugComponents::modelRef, DOC(dai, SlugComponents, modelRef));
112+
113+
// endpoints
114+
modelzoo.def("setHealthEndpoint", &modelzoo::setHealthEndpoint, py::arg("endpoint"), DOC(dai, modelzoo, setHealthEndpoint));
115+
modelzoo.def("setDownloadEndpoint", &modelzoo::setDownloadEndpoint, py::arg("endpoint"), DOC(dai, modelzoo, setDownloadEndpoint));
116+
modelzoo.def("setDefaultCachePath", &modelzoo::setDefaultCachePath, py::arg("path"), DOC(dai, modelzoo, setDefaultCachePath));
117+
modelzoo.def("setDefaultModelsPath", &modelzoo::setDefaultModelsPath, py::arg("path"), DOC(dai, modelzoo, setDefaultModelsPath));
118+
modelzoo.def("getHealthEndpoint", &modelzoo::getHealthEndpoint, DOC(dai, modelzoo, getHealthEndpoint));
119+
modelzoo.def("getDownloadEndpoint", &modelzoo::getDownloadEndpoint, DOC(dai, modelzoo, getDownloadEndpoint));
120+
modelzoo.def("getDefaultCachePath", &modelzoo::getDefaultCachePath, DOC(dai, modelzoo, getDefaultCachePath));
121+
modelzoo.def("getDefaultModelsPath", &modelzoo::getDefaultModelsPath, DOC(dai, modelzoo, getDefaultModelsPath));
35122
}

bindings/python/src/pipeline/node/DetectionNetworkBindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "Common.hpp"
66
#include "NodeBindings.hpp"
7-
#include "depthai/modelzoo/NNModelDescription.hpp"
7+
#include "depthai/modelzoo/Zoo.hpp"
88
#include "depthai/pipeline/DeviceNodeGroup.hpp"
99
#include "depthai/pipeline/Node.hpp"
1010
#include "depthai/pipeline/NodeGroup.hpp"

bindings/python/src/py_bindings.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "common/ModelTypeBindings.hpp"
2828
#include "depthai/depthai.hpp"
2929
#include "log/LogBindings.hpp"
30-
#include "modelzoo/NNModelDescriptionBindings.hpp"
3130
#include "modelzoo/ZooBindings.hpp"
3231
#include "nn_archive/NNArchiveBindings.hpp"
3332
#include "openvino/OpenVINOBindings.hpp"
@@ -85,7 +84,6 @@ PYBIND11_MODULE(depthai, m)
8584
callstack.push_front(&DeviceBindings::bind);
8685
callstack.push_front(&DeviceBootloaderBindings::bind);
8786
callstack.push_front(&CalibrationHandlerBindings::bind);
88-
callstack.push_front(&NNModelDescriptionBindings::bind);
8987
callstack.push_front(&ZooBindings::bind);
9088
callstack.push_front(&EventsManagerBindings::bind);
9189
callstack.push_front(&RemoteConnectionBindings::bind);

ci/upload-artifactory-zoo-helper.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ echo "PATH_PREFIX: $PATH_PREFIX"
1616
echo "ZOO_HELPER_BINARY_LOCAL_PATH: $ZOO_HELPER_BINARY_LOCAL_PATH"
1717
echo "ZOO_HELPER_GIT_HASH: $ZOO_HELPER_GIT_HASH"
1818
echo "zoo_helper binary size: $(du -sh $ZOO_HELPER_BINARY_LOCAL_PATH)"
19+
echo "zoo_helper download url: https://artifacts.luxonis.com/artifactory/$PATH_PREFIX/$ZOO_HELPER_GIT_HASH/zoo_helper"
1920
echo "----------------------------------------"
2021

2122
# Upload binary to artifactory

0 commit comments

Comments
 (0)