Initial commit

This commit is contained in:
2020-10-17 15:44:27 +02:00
commit 39e08c139e
15 changed files with 1095 additions and 0 deletions
+109
View File
@@ -0,0 +1,109 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* File model_process.h
* Description: handle model process
*/
#pragma once
#include <iostream>
#include "utils.h"
#include "acl/acl.h"
/**
* ModelProcess
*/
class ModelProcess {
public:
/**
* @brief Constructor
*/
ModelProcess();
/**
* @brief Destructor
*/
~ModelProcess();
/**
* @brief load model from file with mem
* @param [in] modelPath: model path
* @return result
*/
Result LoadModelFromFileWithMem(const char *modelPath);
/**
* @brief unload model
*/
void Unload();
/**
* @brief create model desc
* @return result
*/
Result CreateDesc();
/**
* @brief destroy desc
*/
void DestroyDesc();
/**
* @brief create model input
* @param [in] inputDataBuffer: input buffer
* @param [in] bufferSize: input buffer size
* @return result
*/
Result CreateInput(void *inputDataBuffer, size_t bufferSize);
/**
* @brief destroy input resource
*/
void DestroyInput();
/**
* @brief create output buffer
* @return result
*/
Result CreateOutput();
/**
* @brief destroy output resource
*/
void DestroyOutput();
/**
* @brief model execute
* @return result
*/
Result Execute();
/**
* @brief get model output data
* @return output dataset
*/
aclmdlDataset *GetModelOutputData();
private:
bool loadFlag_; // model load flag
uint32_t modelId_;
void *modelMemPtr_;
size_t modelMemSize_;
void *modelWeightPtr_;
size_t modelWeightSize_;
aclmdlDesc *modelDesc_;
aclmdlDataset *input_;
aclmdlDataset *output_;
};
+71
View File
@@ -0,0 +1,71 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* File sample_process.h
* Description: handle acl resource
*/
#pragma once
#include "utils.h"
#include "acl/acl.h"
#include <memory>
template<class Type>
std::shared_ptr<Type> MakeSharedNoThrow() {
try {
return std::make_shared<Type>();
} catch (...) {
return nullptr;
}
}
#define MAKE_SHARED_NO_THROW(memory, memory_type) \
memory = MakeSharedNoThrow<memory_type>();
/**
* SampleProcess
*/
class SampleProcess {
public:
/**
* @brief Constructor
*/
SampleProcess();
/**
* @brief Destructor
*/
~SampleProcess();
/**
* @brief init reousce
* @return result
*/
Result InitResource();
/**
* @brief encode sample process
* @param [in] dvpptype: dvpp type
* @return result
*/
Result MainProcess(std::string input_path);
private:
void DestroyResource();
int32_t deviceId_;
aclrtContext context_;
aclrtStream stream_;
};
+82
View File
@@ -0,0 +1,82 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* File utils.h
* Description: handle file operations
*/
#pragma once
#include <iostream>
#include <vector>
#include "acl/acl.h"
#include <opencv2/opencv.hpp>
#include "opencv2/imgcodecs/legacy/constants_c.h"
#include "opencv2/imgproc/types_c.h"
#define INFO_LOG(fmt, args...) fprintf(stdout, "[INFO] " fmt "\n", ##args)
#define WARN_LOG(fmt, args...) fprintf(stdout, "[WARN] " fmt "\n", ##args)
#define ERROR_LOG(fmt, args...) fprintf(stdout, "[ERROR] " fmt "\n", ##args)
#define MODEL_INPUT_WIDTH 416
#define MODEL_INPUT_HEIGHT 416
typedef enum Result {
SUCCESS = 0,
FAILED = 1
} Result;
struct ConsoleParams {
uint32_t img_width = 0;
uint32_t img_height = 0;
int32_t size = 0;
std::string input_path = "";
std::shared_ptr<u_int8_t> data;
};
const std::string kImagePathSeparator = ",";
const int kStatSuccess = 0;
const std::string kFileSperator = "/";
const std::string kPathSeparator = "/";
// output image prefix
const std::string kOutputFilePrefix = "out_";
/**
* Utils
*/
class Utils {
public:
/**
* @brief create device buffer of pic
* @param [in] picDesc: pic desc
* @param [in] PicBufferSize: aligned pic size
* @return device buffer of pic
*/
static Result Postprocess(const std::string &path, aclmdlDataset *modelOutput);
static bool IsDirectory(const std::string &path);
static bool IsPathExist(const std::string &path);
static void SplitPath(const std::string &path, std::vector<std::string> &path_vec);
static void GetAllFiles(const std::string &path, std::vector<std::string> &file_vec);
static void GetPathFiles(const std::string &path, std::vector<std::string> &file_vec);
static bool Preprocess(std::shared_ptr<ConsoleParams> &image_path,
const std::string &path);
};