Skip to content

Commit cb48702

Browse files
authored
Merge pull request #1299 from luxonis/v3_zoo03
Fix zoo compilation for DEPTHAI_ENABLE_CURL=OFF
2 parents ae3f03a + 24a5a93 commit cb48702

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

src/modelzoo/Zoo.cpp

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,6 @@ class ZooManager {
141141
*/
142142
static bool connectionToZooAvailable();
143143

144-
/**
145-
* @brief Get path to yaml file.
146-
* If name is a relative path (e.g. ./yolo.yaml), it is returned as is.
147-
* If name is a full path (e.g. /home/user/models/yolo.yaml), it is returned as is.
148-
* If name is a model name (e.g. yolo) or a model yaml file (e.g. yolo.yaml),
149-
* the function will use modelsPath if provided or the DEPTHAI_ZOO_MODELS_PATH environment variable and return a path to the yaml file.
150-
* For instance, yolo -> ./depthai_models/yolo.yaml (if modelsPath or DEPTHAI_ZOO_MODELS_PATH are ./depthai_models)
151-
*
152-
* @param name: Name of the yaml file
153-
* @param modelsPath: Path to the models folder, use environment variable DEPTHAI_ZOO_MODELS_PATH if not provided
154-
* @return std::string: Path to yaml file
155-
*/
156-
static std::string getYamlFilePath(const std::string& name, const std::string& modelsPath = "");
157-
158144
private:
159145
// Description of the model
160146
NNModelDescription modelDescription;
@@ -166,6 +152,25 @@ class ZooManager {
166152
std::string cacheDirectory;
167153
};
168154

155+
#endif
156+
157+
/**
158+
* @brief Get path to yaml file.
159+
* If name is a relative path (e.g. ./yolo.yaml), it is returned as is.
160+
* If name is a full path (e.g. /home/user/models/yolo.yaml), it is returned as is.
161+
* If name is a model name (e.g. yolo) or a model yaml file (e.g. yolo.yaml),
162+
* the function will use modelsPath if provided or the DEPTHAI_ZOO_MODELS_PATH environment variable and return a path to the yaml file.
163+
* For instance, yolo -> ./depthai_models/yolo.yaml (if modelsPath or DEPTHAI_ZOO_MODELS_PATH are ./depthai_models)
164+
*
165+
* @param name: Name of the yaml file
166+
* @param modelsPath: Path to the models folder, use environment variable DEPTHAI_ZOO_MODELS_PATH if not provided
167+
* @return std::string: Path to yaml file
168+
*/
169+
std::string getYamlFilePath(const std::string& name, const std::string& modelsPath = "");
170+
171+
std::string combinePaths(const std::string& path1, const std::string& path2);
172+
173+
#ifdef DEPTHAI_ENABLE_CURL
169174
std::string generateErrorMessageHub(const cpr::Response& response) {
170175
std::string errorMessage;
171176
errorMessage += "There was an error while sending a request to the Hub\n";
@@ -189,10 +194,6 @@ std::string generateErrorMessageModelDownload(const cpr::Response& response) {
189194
return errorMessage;
190195
}
191196

192-
std::string combinePaths(const std::string& path1, const std::string& path2) {
193-
return std::filesystem::path(path1).append(path2).string();
194-
}
195-
196197
bool checkIsErrorHub(const cpr::Response& response) {
197198
// Check if response is an HTTP error
198199
if(response.status_code != cpr::status::HTTP_OK) return true;
@@ -535,7 +536,38 @@ bool ZooManager::connectionToZooAvailable() {
535536
return connected;
536537
}
537538

538-
std::string ZooManager::getYamlFilePath(const std::string& name, const std::string& modelsPath) {
539+
std::string ZooManager::getMetadataFilePath() const {
540+
return combinePaths(getModelCacheFolderPath(cacheDirectory), "metadata.yaml");
541+
}
542+
543+
std::string ZooManager::getGlobalMetadataFilePath() const {
544+
return combinePaths(cacheDirectory, "metadata.yaml");
545+
}
546+
547+
#else
548+
549+
std::string getModelFromZoo(const NNModelDescription& modelDescription, bool useCached, const std::string& cacheDirectory, const std::string& apiKey) {
550+
(void)modelDescription;
551+
(void)useCached;
552+
(void)cacheDirectory;
553+
(void)apiKey;
554+
throw std::runtime_error("getModelFromZoo requires libcurl to be enabled. Please recompile DepthAI with libcurl enabled.");
555+
}
556+
557+
bool downloadModelsFromZoo(const std::string& path, const std::string& cacheDirectory, const std::string& apiKey) {
558+
(void)path;
559+
(void)cacheDirectory;
560+
(void)apiKey;
561+
throw std::runtime_error("downloadModelsFromZoo requires libcurl to be enabled. Please recompile DepthAI with libcurl enabled.");
562+
}
563+
564+
#endif
565+
566+
std::string combinePaths(const std::string& path1, const std::string& path2) {
567+
return std::filesystem::path(path1).append(path2).string();
568+
}
569+
570+
std::string getYamlFilePath(const std::string& name, const std::string& modelsPath) {
539571
// No empty names allowed
540572
if(name.empty()) {
541573
throw std::runtime_error("name cannot be empty!");
@@ -570,33 +602,6 @@ std::string ZooManager::getYamlFilePath(const std::string& name, const std::stri
570602
return name;
571603
}
572604

573-
std::string ZooManager::getMetadataFilePath() const {
574-
return combinePaths(getModelCacheFolderPath(cacheDirectory), "metadata.yaml");
575-
}
576-
577-
std::string ZooManager::getGlobalMetadataFilePath() const {
578-
return combinePaths(cacheDirectory, "metadata.yaml");
579-
}
580-
581-
#else
582-
583-
std::string getModelFromZoo(const NNModelDescription& modelDescription, bool useCached, const std::string& cacheDirectory, const std::string& apiKey) {
584-
(void)modelDescription;
585-
(void)useCached;
586-
(void)cacheDirectory;
587-
(void)apiKey;
588-
throw std::runtime_error("getModelFromZoo requires libcurl to be enabled. Please recompile DepthAI with libcurl enabled.");
589-
}
590-
591-
void downloadModelsFromZoo(const std::string& path, const std::string& cacheDirectory, const std::string& apiKey) {
592-
(void)path;
593-
(void)cacheDirectory;
594-
(void)apiKey;
595-
throw std::runtime_error("downloadModelsFromZoo requires libcurl to be enabled. Please recompile DepthAI with libcurl enabled.");
596-
}
597-
598-
#endif
599-
600605
std::string SlugComponents::merge() const {
601606
std::ostringstream oss;
602607
if(!teamName.empty()) {
@@ -640,7 +645,7 @@ SlugComponents SlugComponents::split(const std::string& slug) {
640645
}
641646

642647
NNModelDescription NNModelDescription::fromYamlFile(const std::string& modelName, const std::string& modelsPath) {
643-
std::string yamlPath = ZooManager::getYamlFilePath(modelName, modelsPath);
648+
std::string yamlPath = getYamlFilePath(modelName, modelsPath);
644649
if(!std::filesystem::exists(yamlPath)) {
645650
throw std::runtime_error("Model file not found: `" + yamlPath + "` | If you meant to use a relative path, prefix with ./ (e.g. `./" + modelName
646651
+ "`) | Also, make sure the file exists. Read the documentation for more information.");

0 commit comments

Comments
 (0)