Initial commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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 "model_process.h"
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* ColorizeProcess
|
||||
*/
|
||||
class ColorizeProcess {
|
||||
public:
|
||||
ColorizeProcess(const char* modelPath, uint32_t modelWidth, uint32_t modelHeight);
|
||||
~ColorizeProcess();
|
||||
|
||||
Result Init();
|
||||
Result Preprocess(const string& imageFile);
|
||||
Result Inference(aclmdlDataset*& inferenceOutput);
|
||||
Result Postprocess(const string& origImageFile,
|
||||
aclmdlDataset* modelOutput);
|
||||
private:
|
||||
Result InitResource();
|
||||
Result InitModel(const char* omModelPath);
|
||||
|
||||
void* GetInferenceOutputItem(uint32_t& itemDataSize,
|
||||
aclmdlDataset* inferenceOutput);
|
||||
void SaveImage(const string& origImageFile, cv::Mat& image);
|
||||
void DestroyResource();
|
||||
|
||||
private:
|
||||
int32_t deviceId_;
|
||||
|
||||
ModelProcess model_;
|
||||
|
||||
const char* modelPath_;
|
||||
uint32_t modelWidth_;
|
||||
uint32_t modelHeight_;
|
||||
uint32_t inputDataSize_;
|
||||
void* inputBuf_;
|
||||
aclrtRunMode runMode_;
|
||||
|
||||
bool isInited_;
|
||||
};
|
||||
|
||||
@@ -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_;
|
||||
};
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* 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 RGBF32_CHAN_SIZE(width, height) ((width) * (height) * 4)
|
||||
|
||||
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) \
|
||||
do { \
|
||||
memory = MakeSharedNoThrow<memory_type>(); \
|
||||
}while(0);
|
||||
|
||||
typedef enum Result {
|
||||
SUCCESS = 0,
|
||||
FAILED = 1
|
||||
}Result;
|
||||
|
||||
struct ImageData {
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
int32_t size = 0;
|
||||
void* data;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 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 void* CopyDataDeviceToHost(void* deviceData, uint32_t dataSize);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user