Skip to content

Commit 5b79c09

Browse files
committed
add json printing callback
1 parent b1a645a commit 5b79c09

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

include/depthai/modelzoo/Zoo.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ std::string getModelFromZoo(const NNModelDescription& modelDescription,
101101
* DEPTHAI_ZOO_CACHE_PATH environment variable and uses that if set, otherwise the default is used (see getDefaultCachePath).
102102
* @param apiKey: API key for the model zoo, default is "". If apiKey is set to "", this function checks the DEPTHAI_ZOO_API_KEY environment variable and uses
103103
* that if set. Otherwise, no API key is used.
104+
* @param format: Format to use for output (possible values: pretty, json), default is "pretty"
104105
* @return bool: True if all models were downloaded successfully, false otherwise
105106
*/
106-
bool downloadModelsFromZoo(const std::string& path, const std::string& cacheDirectory = "", const std::string& apiKey = "");
107+
bool downloadModelsFromZoo(const std::string& path, const std::string& cacheDirectory = "", const std::string& apiKey = "", const std::string& format = "pretty");
107108

108109
std::ostream& operator<<(std::ostream& os, const NNModelDescription& modelDescription);
109110

src/modelzoo/Zoo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ nlohmann::json ZooManager::fetchModelDownloadLinks() {
332332
throw std::runtime_error(generateErrorMessageHub(response));
333333
}
334334

335+
std::cout << "Response: " << response.text << std::endl;
336+
335337
// Extract download links from response
336338
nlohmann::json responseJson = nlohmann::json::parse(response.text);
337339
return responseJson;
@@ -582,7 +584,7 @@ struct JsonDownloadProgressManager {
582584
}
583585
};
584586

585-
bool downloadModelsFromZoo(const std::string& path, const std::string& cacheDirectory, const std::string& apiKey) {
587+
bool downloadModelsFromZoo(const std::string& path, const std::string& cacheDirectory, const std::string& apiKey, const std::string& format) {
586588
logger::info("Downloading models from zoo");
587589
// Make sure 'path' exists
588590
if(!std::filesystem::exists(path)) throw std::runtime_error("Path does not exist: " + path);

src/modelzoo/zoo_helper.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ int main(int argc, char* argv[]) {
3333
const std::string DEFAULT_DOWNLOAD_ENDPOINT = dai::modelzoo::getDownloadEndpoint();
3434
program.add_argument("--download_endpoint").default_value(DEFAULT_DOWNLOAD_ENDPOINT).help("Endpoint to use for downloading models");
3535

36+
const std::string FORMAT_DEFAULT = "pretty";
37+
program.add_argument("--format").default_value(FORMAT_DEFAULT).help("Format to use for output (possible values: pretty, json)");
38+
3639
program.add_argument("--verbose").default_value(false).implicit_value(true).help("Verbose output");
3740

3841
// Parse arguments
@@ -50,9 +53,10 @@ int main(int argc, char* argv[]) {
5053
auto apiKey = program.get<std::string>("--api_key");
5154
auto healthEndpoint = program.get<std::string>("--health_endpoint");
5255
auto downloadEndpoint = program.get<std::string>("--download_endpoint");
56+
auto format = program.get<std::string>("--format");
5357

5458
bool verbose = program.get<bool>("--verbose");
55-
if(!dai::utility::isEnvSet("DEPTHAI_LEVEL") && verbose) {
59+
if(!dai::utility::isEnvSet("DEPTHAI_LEVEL") && verbose && format == "pretty") {
5660
dai::Logging::getInstance().logger.set_level(spdlog::level::info);
5761
}
5862

@@ -61,10 +65,12 @@ int main(int argc, char* argv[]) {
6165
dai::modelzoo::setDownloadEndpoint(downloadEndpoint);
6266

6367
// Print arguments
64-
std::cout << "Downloading models defined in yaml files in folder: " << yamlFolder << std::endl;
65-
std::cout << "Downloading models into cache folder: " << cacheFolder << std::endl;
66-
if(!apiKey.empty()) {
67-
std::cout << "Using API key: " << apiKey << std::endl;
68+
if(format == "pretty") {
69+
std::cout << "Downloading models defined in yaml files in folder: " << yamlFolder << std::endl;
70+
std::cout << "Downloading models into cache folder: " << cacheFolder << std::endl;
71+
if(!apiKey.empty()) {
72+
std::cout << "Using API key: " << apiKey << std::endl;
73+
}
6874
}
6975

7076
// Download models
@@ -74,6 +80,8 @@ int main(int argc, char* argv[]) {
7480
return EXIT_FAILURE;
7581
}
7682

77-
std::cout << "Successfully downloaded all models from " << yamlFolder << std::endl;
83+
if(format == "pretty") {
84+
std::cout << "Successfully downloaded all models from " << yamlFolder << std::endl;
85+
}
7886
return EXIT_SUCCESS;
7987
}

0 commit comments

Comments
 (0)