diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_VOC_detection_picture/objectdetection_yolov3pb.iml b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_VOC_detection_picture/objectdetection_yolov3pb.iml
deleted file mode 100755
index b6553c63c9b451c139f89936949d065830f369e0..0000000000000000000000000000000000000000
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_VOC_detection_picture/objectdetection_yolov3pb.iml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_VOC_detection_picture/src/acl.json b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_VOC_detection_picture/src/acl.json
deleted file mode 100755
index 0967ef424bce6791893e9a57bb952f80fd536e93..0000000000000000000000000000000000000000
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_VOC_detection_picture/src/acl.json
+++ /dev/null
@@ -1 +0,0 @@
-{}
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteError.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteError.h
old mode 100755
new mode 100644
index 254498708002d505acc4e5c9674eba032285e6c2..888087ba312e3a4a042d685c3a2b185d0c1ddf90
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteError.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteError.h
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,10 +12,11 @@
* 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
*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITEERROR_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITEERROR_H
+
#pragma once
#include
@@ -39,24 +40,24 @@ const int ACLLITE_ERROR_THREAD_ABNORMAL = 14;
const int ACLLITE_ERROR_START_THREAD = 15;
const int ACLLITE_ERROR_ADD_THREAD = 16;
-//malloc or new memory failed
+// malloc or new memory failed
const int ACLLITE_ERROR_MALLOC = 101;
-//aclrtMalloc failed
+// aclrtMalloc failed
const int ACLLITE_ERROR_MALLOC_DEVICE = 102;
const int ACLLITE_ERROR_MALLOC_DVPP = 103;
-//access file failed
+// access file failed
const int ACLLITE_ERROR_ACCESS_FILE = 201;
-//the file is invalid
+// the file is invalid
const int ACLLITE_ERROR_INVALID_FILE = 202;
-//open file failed
+// open file failed
const int ACLLITE_ERROR_OPEN_FILE = 203;
-//load model repeated
+// load model repeated
const int ACLLITE_ERROR_LOAD_MODEL_REPEATED = 301;
const int ACLLITE_ERROR_NO_MODEL_DESC = 302;
-//load mode by acl failed
+// load mode by acl failed
const int ACLLITE_ERROR_LOAD_MODEL = 303;
const int ACLLITE_ERROR_CREATE_MODEL_DESC = 304;
@@ -91,7 +92,7 @@ const int ACLLITE_ERROR_UNSURPPORT_PROPERTY = 404;
const int ACLLITE_ERROR_INVALID_PROPERTY_VALUE = 405;
-const int ACLLITE_ERROR_UNSURPPORT_VIDEO_CAPTURE =406;
+const int ACLLITE_ERROR_UNSURPPORT_VIDEO_CAPTURE = 406;
const int ACLLITE_ERROR_CREATE_DVPP_CHANNEL_DESC = 501;
@@ -189,4 +190,6 @@ const int ACLLITE_ERROR_VENC_CREATE_FRAME_CONFIG = 708;
const int ACLLITE_ERROR_VENC_SEND_FRAME = 709;
-const int ACLLITE_ERROR_SUBSCRIBE_REPORT = 710;
\ No newline at end of file
+const int ACLLITE_ERROR_SUBSCRIBE_REPORT = 710;
+
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteImageProc.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteImageProc.h
old mode 100755
new mode 100644
index ed573e209f40e8871cdefb38cd6fb8d2b37588b9..aefcb1eff5ac832a9ef53b7f536651a9d15ce789
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteImageProc.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteImageProc.h
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,9 +12,11 @@
* 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 AclLiteImageProc.h
*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITEIMAGEPROC_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITEIMAGEPROC_H
+
#pragma once
#include
#include "AclLiteUtils.h"
@@ -33,7 +35,7 @@ public:
~AclLiteImageProc();
AclLiteError Init();
- AclLiteError Resize(ImageData& dest,ImageData& src,
+ AclLiteError Resize(ImageData& dest, ImageData& src,
uint32_t width, uint32_t height);
AclLiteError JpegD(ImageData& destYuv, ImageData& srcJpeg);
AclLiteError Crop(ImageData& dest, ImageData& src,
@@ -42,12 +44,14 @@ public:
AclLiteError CropPaste(ImageData& dest, ImageData& src,
uint32_t width, uint32_t height,
uint32_t ltHorz, uint32_t ltVert,
- uint32_t rbHorz, uint32_t rbVert);
+ uint32_t rbHorz, uint32_t rbVert);
void DestroyResource();
protected:
- bool isReleased_;
- aclrtStream stream_;
- acldvppChannelDesc *dvppChannelDesc_;
- int isInitOk_;
-};
\ No newline at end of file
+ bool g_isReleased_;
+ aclrtStream g_stream_;
+ acldvppChannelDesc *g_dvppChannelDesc_;
+ int g_isInitOk_;
+};
+
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteModel.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteModel.h
old mode 100755
new mode 100644
index 62e6c23384d1f7082f1abf7bb308b35ced980eb7..3a2033a9ea737e34b8082c154dcb3baf22402f99
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteModel.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteModel.h
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,10 +12,11 @@
* 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
*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITEMODEL_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITEMODEL_H
+
#pragma once
#include
#include "AclLiteUtils.h"
@@ -29,11 +30,11 @@ public:
AclLiteError Init();
void DestroyResource();
- AclLiteError CreateInput(void *input, uint32_t inputsize);
- AclLiteError CreateInput(void *input1, uint32_t input1size,
- void* input2, uint32_t input2size);
+ AclLiteError CreateInput(void *input, uint32_t inputSize);
+ AclLiteError CreateInput(void *input1, uint32_t input1Size,
+ void* input2, uint32_t input2Size);
AclLiteError CreateInput(std::vector& inputData);
- AclLiteError Execute(std::vector& inferOutputs,
+ AclLiteError Execute(std::vector& inferOutputs,
void *data, uint32_t size);
AclLiteError Execute(std::vector& inferOutputs);
void DestroyInput();
@@ -42,28 +43,30 @@ private:
AclLiteError LoadModelFromFile(const std::string& modelPath);
AclLiteError SetDesc();
AclLiteError CreateOutput();
- AclLiteError AddDatasetBuffer(aclmdlDataset* dataset,
+ AclLiteError AddDatasetBuffer(aclmdlDataset* dataset,
void* buffer, uint32_t bufferSize);
AclLiteError GetOutputItem(InferenceOutput& out,
uint32_t idx);
- void Unload();
+ void Unload();
void DestroyDesc();
void DestroyOutput();
private:
- bool loadFlag_; // model load flag
- bool isReleased_; // model release flag
- uint32_t modelId_; //modelid
- size_t outputsNum_;
- size_t modelMemSize_;
- size_t modelWorkSize_;
- size_t modelWeightSize_;
- aclrtRunMode runMode_;
- void *modelMemPtr_;
- void *modelWorkPtr_;
- void *modelWeightPtr_;
- aclmdlDesc *modelDesc_;
- aclmdlDataset *input_; //input dataset
- aclmdlDataset *output_; //output dataset
- std::string modelPath_; //model path
-};
\ No newline at end of file
+ bool g_loadFlag_; // model load flag
+ bool g_isReleased_; // model release flag
+ uint32_t g_modelId_; // modelid
+ size_t g_outputsNum_;
+ size_t g_modelMemSize_;
+ size_t g_modelWorkSize_;
+ size_t g_modelWeightSize_;
+ aclrtRunMode g_runMode_;
+ void *g_modelMemPtr_;
+ void *g_modelWorkPtr_;
+ void *g_modelWeightPtr_;
+ aclmdlDesc *g_modelDesc_;
+ aclmdlDataset *g_input_; // input dataset
+ aclmdlDataset *g_output_; // output dataset
+ std::string g_modelPath_; // model path
+};
+
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteResource.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteResource.h
old mode 100755
new mode 100644
index 9e3386b363e5c11b232e0ba73bda6d126f627487..6e7cdbbd8238aa0fa3131b8db2492242f7a0e23b
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteResource.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteResource.h
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,10 +12,11 @@
* 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 AclLiteResource.h
-* Description: handle AclLiteResource operations
*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITERESOURCE_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITERESOURCE_H
+
#pragma once
#include
@@ -25,17 +26,19 @@
class AclLiteResource {
public:
- AclLiteResource();
+ AclLiteResource();
~AclLiteResource();
AclLiteError Init();
void Release();
private:
- bool isReleased_;
- bool useDefaultCtx_;
- int32_t deviceId_;
- aclrtRunMode runMode_;
- aclrtContext context_;
- std::string aclConfig_;
+ bool g_isReleased_;
+ bool g_useDefaultCtx_;
+ int32_t g_deviceId_;
+ aclrtRunMode g_runMode_;
+ aclrtContext g_context_;
+ std::string g_aclConfig_;
};
+
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteType.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteType.h
old mode 100755
new mode 100644
index d69254f642e68dcc3d34d31042e4d1b5e80423ae..30b885f68476d2021cff4594bc62a1efa620a5bd
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteType.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteType.h
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,10 +12,11 @@
* 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
*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITETYPE_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITETYPE_H
+
#pragma once
#include
@@ -27,7 +28,7 @@ enum MemoryType {
MEMORY_NORMAL = 0,
MEMORY_HOST,
MEMORY_DEVICE,
- MEMORY_DVPP,
+ MEMORY_DVPP,
MEMORY_INVALID_TYPE
};
@@ -110,4 +111,6 @@ struct DataInfo {
struct InferenceOutput {
std::shared_ptr data = nullptr;
uint32_t size;
-};
\ No newline at end of file
+};
+
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteUtils.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteUtils.h
old mode 100755
new mode 100644
index f23d8b90afe5e2ab0fe8ae1eb487120f89a66aff..3b0e50c131a13717b546d6716cb4dc7c61ce6411
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteUtils.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/AclLiteUtils.h
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,10 +12,11 @@
* 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
*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITEUTILS_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_ACLLITEUTILS_H
+
#pragma once
#include
@@ -63,7 +64,7 @@
/**
* @brief calculate aligned number
* @param [in]: num: the original number that to aligned
- * @param [in]: align: the align factor
+ * @param [in]: align: the align factor
* @return the number after aligned
*/
#define ALIGN_UP(num, align) (((num) + (align) - 1) & ~((align) - 1))
@@ -82,6 +83,13 @@
*/
#define ALIGN_UP16(num) ALIGN_UP(num, 16)
+/**
+ * @brief calculate number align with 64
+ * @param [in]: num: the original number that to aligned
+ * @return the number after aligned
+ */
+#define ALIGN_UP64(num) ALIGN_UP(num, 64)
+
/**
* @brief calculate number align with 128
* @param [in]: num: the original number that to aligned
@@ -95,8 +103,8 @@
* @return none
*/
#define ACLLITE_LOG_ERROR(fmt, ...) \
- do{aclAppLog(ACL_ERROR, __FUNCTION__, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
- fprintf(stdout, "[ERROR] " fmt "\n", ##__VA_ARGS__);}while(0)
+ do {aclAppLog(ACL_ERROR, __FUNCTION__, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
+ fprintf(stdout, "[ERROR] " fmt "\n", ##__VA_ARGS__);}while (0)
/**
* @brief Write acl info level log to host log
@@ -130,10 +138,10 @@ bool IsDirectory(const std::string &path);
* @param [in]: curRunMode: The run mode, get by aclrtGetRunMode,
* Atlas200DK is ACL_DEVICE, Atlas300 is ACL_HOST
* @param [in]: memType: The dest memory type:MEMORY_NORMAL(in Atlas200DK),
- * MEMORY_DEVICE, MEMORY_DVPP
+ * MEMORY_DEVICE, MEMORY_DVPP
* @return void* The dest memory pointer
*/
-void* CopyDataToDevice(const void* data, uint32_t size,
+void* CopyDataToDevice(const void* data, uint32_t size,
aclrtRunMode curRunMode, MemoryType memType);
/**
@@ -144,11 +152,11 @@ void* CopyDataToDevice(const void* data, uint32_t size,
* @param [in]: srcSize: The data bytes size
* @param [in]: curRunMode: The run mode, get by aclrtGetRunMode,
* Atlas200DK is ACL_DEVICE, Atlas300 is ACL_HOST
- * @return AclLiteError ACLLITE_OK: copy success
+ * @return AclLiteError ACLLITE_OK: copy success
* others: copy failed
*/
-AclLiteError CopyDataToDeviceEx(void* dest, uint32_t destSize,
- const void* src, uint32_t srcSize,
+AclLiteError CopyDataToDeviceEx(void* dest, uint32_t destSize,
+ const void* src, uint32_t srcSize,
aclrtRunMode runMode);
/**
@@ -160,7 +168,7 @@ AclLiteError CopyDataToDeviceEx(void* dest, uint32_t destSize,
* @param [in]: memType: The dest memory type:MEMORY_NORMAL, MEMORY_HOST
* @return void* The dest memory pointer
*/
-void* CopyDataToHost(const void* data, uint32_t size,
+void* CopyDataToHost(const void* data, uint32_t size,
aclrtRunMode curRunMode, MemoryType memType);
/**
@@ -169,66 +177,68 @@ void* CopyDataToHost(const void* data, uint32_t size,
* @param [in]: size: The data bytes size
* @param [in]: policy: the kind of sync,
* typedef enum aclrtMemcpyKind {
- * ACL_MEMCPY_HOST_TO_HOST, // Memory copy from Host to Host
- * ACL_MEMCPY_HOST_TO_DEVICE, // Memory copy from Host to Device
- * ACL_MEMCPY_DEVICE_TO_HOST, // Memory copy from Device to Host
- * ACL_MEMCPY_DEVICE_TO_DEVICE, // Memory copy from Device to Device
+ * ACL_MEMCPY_HOST_TO_HOST, // Memory copy from Host to Host
+ * ACL_MEMCPY_HOST_TO_DEVICE, // Memory copy from Host to Device
+ * ACL_MEMCPY_DEVICE_TO_HOST, // Memory copy from Device to Host
+ * ACL_MEMCPY_DEVICE_TO_DEVICE, // Memory copy from Device to Device
* } aclrtMemcpyKind;
* @param [in]: memType: The dest memory type
* @return void* The dest memory pointer
*/
-void* CopyData(const void* data, uint32_t size,
+void* CopyData(const void* data, uint32_t size,
aclrtMemcpyKind policy, MemoryType memType);
/**
* @brief Read jpeg image file. Only support baseline, not support progressive
- * @param [out]: image: image data read from file.
+ * @param [out]: image: image data read from file.
* @param [in]: fileName: The data bytes size
- * @return AclLiteError ACLLITE_OK: read success
+ * @return AclLiteError ACLLITE_OK: read success
* others: read failed
*/
AclLiteError ReadJpeg(ImageData& image, const std::string& fileName);
/**
* @brief Get all files from file list string
- * @param [in]: pathList: files list string, seperate by ',',
- * the element could be file path or directory
+ * @param [in]: pathList: files list string, seperate by ',',
+ * the element could be file path or directory
* @param [in]: fileVec: The data bytes size
- * @return AclLiteError ACLLITE_OK: read success
+ * @return AclLiteError ACLLITE_OK: read success
* others: read failed
*/
-void GetAllFiles(const std::string &pathList,
+void GetAllFiles(const std::string &pathList,
std::vector &fileVec);
/**
* @brief Read binary file to buffer
* @param [in]: filename: binary file name with path
- * @param [in]: data: buffer
+ * @param [in]: data: buffer
* @param [in]: size: buffer size
- * @return AclLiteError ACLLITE_OK: read success
+ * @return AclLiteError ACLLITE_OK: read success
* others: read failed
*/
-AclLiteError ReadBinFile(const std::string& filename,
+AclLiteError ReadBinFile(const std::string& fileName,
void*& data, uint32_t& size);
/**
* @brief Copy image to acl device
* @param [out]: destImage: The image after copy
- * @param [in]: srcImage: The image to copy
+ * @param [in]: srcImage: The image to copy
* @param [in]: curRunMode: The run mode, get by aclrtGetRunMode,
* Atlas200DK is ACL_DEVICE, Atlas300 is ACL_HOST
- * @param [in]: memType: memory type, dvpp is MEMORY_DVPP,
- * device is MEMPRY_DEVICE
- * @return AclLiteError ACLLITE_OK: read success
+ * @param [in]: memType: memory type, dvpp is MEMORY_DVPP,
+ * device is MEMPRY_DEVICE
+ * @return AclLiteError ACLLITE_OK: read success
* others: read failed
- */
-AclLiteError CopyImageToDevice(ImageData& destImage, ImageData& srcImage,
+ */
+AclLiteError CopyImageToDevice(ImageData& destImage, ImageData& srcImage,
aclrtRunMode curRunMode, MemoryType memType);
/**
* @brief Test file path is exist or not
- * @param [in]: path: file path
+ * @param [in]: path: file path
* @return bool true: file path is exist
* false: is not exist
- */
-bool IsPathExist(const std::string &path);
\ No newline at end of file
+ */
+bool IsPathExist(const std::string &path);
+
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/CropAndPasteHelper.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/CropAndPasteHelper.h
old mode 100755
new mode 100644
index 03dc90e505f0850d72b775eaaaa2bee2ed3c8f96..feb896fa5b41067d13426a115881cfedd61a198b
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/CropAndPasteHelper.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/CropAndPasteHelper.h
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,10 +12,11 @@
* 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 AclLiteImageProc.h
-* Description: handle dvpp process
*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_CROPANDPASTEHELPER_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_CROPANDPASTEHELPER_H
+
#pragma once
#include
@@ -23,7 +24,7 @@
#include "acl/ops/acl_dvpp.h"
class CropAndPasteHelper {
- public:
+public:
/**
* @brief Constructor
* @param [in] stream: stream
@@ -38,7 +39,7 @@ class CropAndPasteHelper {
*/
CropAndPasteHelper(aclrtStream &stream, acldvppChannelDesc *dvppChannelDesc,
uint32_t width, uint32_t height,
- uint32_t lt_horz, uint32_t lt_vert,
+ uint32_t lt_horz, uint32_t lt_vert,
uint32_t rb_horz, uint32_t rb_vert);
/**
@@ -75,20 +76,22 @@ private:
void DestroyCropAndPasteResource();
private:
- aclrtStream stream_;
- void *vpcOutBufferDev_;
- acldvppRoiConfig *cropArea_;
- acldvppRoiConfig *pasteArea_;
- acldvppPicDesc *vpcInputDesc_;
- acldvppPicDesc *vpcOutputDesc_;
- acldvppChannelDesc *dvppChannelDesc_;
-
- uint32_t ltHorz_;
- uint32_t rbHorz_;
- uint32_t ltVert_;
- uint32_t rbVert_;
- uint32_t vpcOutBufferSize_;
- uint32_t originalImageWidth_ = 0;
- uint32_t originalImageHeight_ = 0;
- Resolution size_;
-};
\ No newline at end of file
+ aclrtStream g_stream_;
+ void *g_vpcOutBufferDev_;
+ acldvppRoiConfig *g_cropArea_;
+ acldvppRoiConfig *g_pasteArea_;
+ acldvppPicDesc *g_vpcInputDesc_;
+ acldvppPicDesc *g_vpcOutputDesc_;
+ acldvppChannelDesc *g_dvppChannelDesc_;
+
+ uint32_t g_ltHorz_;
+ uint32_t g_rbHorz_;
+ uint32_t g_ltVert_;
+ uint32_t g_rbVert_;
+ uint32_t g_vpcOutBufferSize_;
+ uint32_t g_originalImageWidth_ = 0;
+ uint32_t g_originalImageHeight_ = 0;
+ Resolution g_size_;
+};
+
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/JpegDHelper.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/JpegDHelper.h
old mode 100755
new mode 100644
index 9f1e231d8ce9d2724458ee260b4cbc8f9c675f9c..5179c6d2335ef3bed90ed850652badc762b97401
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/JpegDHelper.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/JpegDHelper.h
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,10 +12,11 @@
* 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 AclLiteImageProc.h
-* Description: handle dvpp process
*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_JPEGDHELPER_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_JPEGDHELPER_H
+
#pragma once
#include
@@ -57,7 +58,7 @@ public:
* @param [in] inputWidth:width of pic
* @param [in] inputHeight:height of pic
*/
- void SetInput4JpegD(uint8_t* inDevBuffer, int inDevBufferSize,
+ void SetInput4JpegD(uint8_t* inDevBuffer, int inDevBufferSize,
int inputWidth, int inputHeight);
AclLiteError InitDecodeOutputDesc(ImageData& inputImage);
/**
@@ -78,8 +79,10 @@ private:
void DestroyOutputPara();
private:
- aclrtStream stream_;
- void* decodeOutBufferDev_; // decode output buffer
- acldvppPicDesc *decodeOutputDesc_; //decode output desc
- acldvppChannelDesc *dvppChannelDesc_;
-};
\ No newline at end of file
+ aclrtStream g_stream_;
+ void* g_decodeOutBufferDev_; // decode output buffer
+ acldvppPicDesc *g_decodeOutputDesc_; // decode output desc
+ acldvppChannelDesc *g_dvppChannelDesc_;
+};
+
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/ResizeHelper.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/ResizeHelper.h
old mode 100755
new mode 100644
index 28854f5de78b787137f1b740944b1e84932f08ff..4f161de2e23871d27f94413f68936f8b50152b3b
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/ResizeHelper.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/ResizeHelper.h
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,10 +12,11 @@
* 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 AclLiteImageProc.h
-* Description: handle dvpp process
*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_RESIZEHELPER_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_RESIZEHELPER_H
+
#pragma once
#include
@@ -73,14 +74,16 @@ private:
void DestroyResource();
void DestroyOutputPara();
- aclrtStream stream_;
- void *vpcOutBufferDev_; // vpc output buffer
- acldvppPicDesc *vpcInputDesc_; // vpc input desc
- acldvppPicDesc *vpcOutputDesc_; // vpc output desc
- acldvppResizeConfig *resizeConfig_;
- acldvppChannelDesc *dvppChannelDesc_;
+ aclrtStream g_stream_;
+ void *g_vpcOutBufferDev_; // vpc output buffer
+ acldvppPicDesc *g_vpcInputDesc_; // vpc input desc
+ acldvppPicDesc *g_vpcOutputDesc_; // vpc output desc
+ acldvppResizeConfig *g_resizeConfig_;
+ acldvppChannelDesc *g_dvppChannelDesc_;
+
+ uint8_t *g_inDevBuffer_; // input pic dev buffer
+ uint32_t g_vpcOutBufferSize_; // vpc output size
+ Resolution g_size_;
+};
- uint8_t *inDevBuffer_; // input pic dev buffer
- uint32_t vpcOutBufferSize_; // vpc output size
- Resolution size_;
-};
\ No newline at end of file
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/color_classify.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/color_classify.h
index 26fff6765b996bbc3482e7cfe2ad4363d35ba313..ade135a5f9a25878e68e8f31ad3ab4c13a24212f 100644
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/color_classify.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/color_classify.h
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,13 +12,14 @@
* 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
*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_COLOR_CLASSIFY_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_COLOR_CLASSIFY_H
+
#pragma once
-#include "acl/acl.h"
#include
+#include "acl/acl.h"
#include "AclLiteModel.h"
#include "AclLiteImageProc.h"
#include "object_detect.h"
@@ -31,29 +32,31 @@ public:
ColorClassify();
~ColorClassify();
AclLiteError Init();
- AclLiteError Preprocess(ImageData& srcImage, std::vector &carImgs, int& flag);
+ AclLiteError PreProcess(ImageData& srcImage, std::vector &carImgs, int& flag);
AclLiteError Inference(std::vector &carImgs, std::vector& inferenceOutput);
- AclLiteError Postprocess(std::vector& inferenceOutput,
+ AclLiteError PostProcess(std::vector& inferenceOutput,
std::vector& carInfo, const std::string& origImagePath);
private:
AclLiteError InitModelInput();
AclLiteError Crop(std::vector &carImgs, ImageData &orgImg);
AclLiteError Resize(std::vector &carImgs);
- int CopyOneBatchImages(uint8_t* buffer, uint32_t bufferSize,
+ int CopyOneBatchImages(uint8_t* buffer, uint32_t bufferSize,
std::vector &carImgs, int batchIdx);
int CopyImageData(uint8_t *buffer, uint32_t bufferSize, ImageData& image);
void DrawResult(std::vector& carInfo, const std::string& origImagePath);
void DestroyResource();
private:
- AclLiteModel model_;
- const char* modelPath_;
- AclLiteImageProc dvpp_;
- aclrtRunMode runMode_;
- bool isInited_;
- bool isReleased_;
-
- int32_t batchSize_;
- uint32_t inputSize_;
- uint8_t* inputBuf_;
-};
\ No newline at end of file
+ AclLiteModel g_model_;
+ const char* g_modelPath_;
+ AclLiteImageProc g_dvpp_;
+ aclrtRunMode g_runMode_;
+ bool g_isInited_;
+ bool g_isReleased_;
+
+ int32_t g_batchSize_;
+ uint32_t g_inputSize_;
+ uint8_t* g_inputBuf_;
+};
+
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/object_detect.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/object_detect.h
index 626a4422ac515ac30bf1207136e38033363a1cd7..cf282021eb8ca173e17e0d2699674eabc736aef6 100644
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/object_detect.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/object_detect.h
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,20 +12,21 @@
* 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
*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_OBJECT_DETECT_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_OBJECT_DETECT_H
+
#pragma once
-#include "acl/acl.h"
#include
+#include
+#include "acl/acl.h"
#include "AclLiteModel.h"
#include "AclLiteImageProc.h"
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/core/types_c.h"
#include "opencv2/imgproc/types_c.h"
-#include
#include "params.h"
/**
@@ -36,23 +37,23 @@ public:
ObjectDetect();
~ObjectDetect();
AclLiteError Init();
- AclLiteError Preprocess(ImageData& resizedImage, ImageData& srcImage, ImageData& yuvImage);
+ AclLiteError PreProcess(ImageData& resizedImage, ImageData& srcImage, ImageData& yuvImage);
AclLiteError Inference(std::vector& inferenceOutput, ImageData& resizedImage);
- AclLiteError Postprocess(ImageData& image, std::vector& inferenceOutput,
+ AclLiteError PostProcess(ImageData& image, std::vector& inferenceOutput,
std::vector& carData);
- // void DrawCarBoxToImage(std::vector& detectionResults,
- // const std::string& origImagePath);
private:
void DestroyResource();
AclLiteError InitModelInput();
private:
- uint32_t imageInfoSize_;
- void* imageInfoBuf_;
- AclLiteModel model_;
- const char* modelPath_;
- AclLiteImageProc dvpp_;
- aclrtRunMode runMode_;
- bool isInited_;
- bool isReleased_;
+ uint32_t g_imageInfoSize_;
+ void* g_imageInfoBuf_;
+ AclLiteModel g_model_;
+ const char* g_modelPath_;
+ AclLiteImageProc g_dvpp_;
+ aclrtRunMode g_runMode_;
+ bool g_isInited_;
+ bool g_isReleased_;
};
+
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/params.h b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/params.h
index 599ed4a2b5c01b95ba5a55b0757f54c85b9c3291..1ea5208ef07d0dff62a413691f4df74bf1831ab9 100644
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/params.h
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/inc/params.h
@@ -1,12 +1,31 @@
-#include "acl/acl.h"
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
+*
+* 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.
+*/
+
+#ifndef YOLOV3_CARCOLOR_SAMPLE_INC_PARAMS_H
+#define YOLOV3_CARCOLOR_SAMPLE_INC_PARAMS_H
+
#include
+#include
+#include "acl/acl.h"
#include "AclLiteModel.h"
#include "AclLiteImageProc.h"
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/core/types_c.h"
#include "opencv2/imgproc/types_c.h"
-#include
struct Rectangle {
cv::Point lt; // left top
@@ -15,9 +34,11 @@ struct Rectangle {
struct CarInfo {
ImageData cropedImgs; // cropped image from original image
- ImageData resizedImgs; //resized image for inference
- Rectangle rectangle;
- std::string text; //类别
- std::string carColor_result; //颜色
- float confidence; //颜色
-};
\ No newline at end of file
+ ImageData resizedImgs; // resized image for inference
+ Rectangle rectangle;
+ std::string text; // 类别
+ std::string carColor_result; // 颜色
+ float confidence; // 颜色
+};
+
+#endif
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteImageProc.cpp b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteImageProc.cpp
old mode 100755
new mode 100644
index b6b39bd8d9812548a9a2f0e843fb91955db121f1..a12508f78db66bebed133022e642f05a4196ec7c
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteImageProc.cpp
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteImageProc.cpp
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,10 +12,8 @@
* 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 AclLiteImageProc.cpp
-* Description: handle dvpp process
*/
+
#include
#include "acl/acl.h"
#include "ResizeHelper.h"
@@ -25,85 +23,92 @@
using namespace std;
-AclLiteImageProc::AclLiteImageProc():
- isReleased_(false),
- stream_(nullptr),
- dvppChannelDesc_(nullptr),
- isInitOk_(false) {
+AclLiteImageProc::AclLiteImageProc()
+ : g_isReleased_(false),
+ g_stream_(nullptr),
+ g_dvppChannelDesc_(nullptr),
+ g_isInitOk_(false)
+{
}
-AclLiteImageProc::~AclLiteImageProc() {
+AclLiteImageProc::~AclLiteImageProc()
+{
DestroyResource();
}
-void AclLiteImageProc::DestroyResource() {
- if (isReleased_) {
+void AclLiteImageProc::DestroyResource()
+{
+ if (g_isReleased_) {
return;
}
aclError aclRet;
- if (dvppChannelDesc_ != nullptr) {
- aclRet = acldvppDestroyChannel(dvppChannelDesc_);
+ if (g_dvppChannelDesc_ != nullptr) {
+ aclRet = acldvppDestroyChannel(g_dvppChannelDesc_);
if (aclRet != ACL_SUCCESS) {
ACLLITE_LOG_ERROR("Destroy dvpp channel error: %d", aclRet);
}
- (void)acldvppDestroyChannelDesc(dvppChannelDesc_);
- dvppChannelDesc_ = nullptr;
+ (void)acldvppDestroyChannelDesc(g_dvppChannelDesc_);
+ g_dvppChannelDesc_ = nullptr;
}
- if (stream_ != nullptr) {
- aclRet = aclrtDestroyStream(stream_);
+ if (g_stream_ != nullptr) {
+ aclRet = aclrtDestroyStream(g_stream_);
if (aclRet != ACL_SUCCESS) {
ACLLITE_LOG_ERROR("Vdec destroy stream failed, error %d", aclRet);
}
- stream_ = nullptr;
+ g_stream_ = nullptr;
}
- isReleased_ = true;
+ g_isReleased_ = true;
}
-AclLiteError AclLiteImageProc::Init() {
- aclError aclRet = aclrtCreateStream(&stream_);
+AclLiteError AclLiteImageProc::Init()
+{
+ aclError aclRet = aclrtCreateStream(&g_stream_);
if (aclRet != ACL_SUCCESS) {
ACLLITE_LOG_ERROR("Create venc stream failed, error %d", aclRet);
return ACLLITE_ERROR_CREATE_STREAM;
}
- dvppChannelDesc_ = acldvppCreateChannelDesc();
- if (dvppChannelDesc_ == nullptr) {
+ g_dvppChannelDesc_ = acldvppCreateChannelDesc();
+ if (g_dvppChannelDesc_ == nullptr) {
ACLLITE_LOG_ERROR("Create dvpp channel desc failed");
return ACLLITE_ERROR_CREATE_DVPP_CHANNEL_DESC;
}
- aclRet = acldvppCreateChannel(dvppChannelDesc_);
+ aclRet = acldvppCreateChannel(g_dvppChannelDesc_);
if (aclRet != ACL_SUCCESS) {
ACLLITE_LOG_ERROR("acldvppCreateChannel failed, aclRet = %d", aclRet);
return ACLLITE_ERRROR_CREATE_DVPP_CHANNEL;
}
- isInitOk_ = true;
+ g_isInitOk_ = true;
ACLLITE_LOG_INFO("dvpp init resource ok");
return ACLLITE_OK;
}
AclLiteError AclLiteImageProc::Resize(ImageData& dest, ImageData& src,
- uint32_t width, uint32_t height) {
- ResizeHelper resizeOp(stream_, dvppChannelDesc_, width, height);
+ uint32_t width, uint32_t height)
+{
+ ResizeHelper resizeOp(g_stream_, g_dvppChannelDesc_, width, height);
return resizeOp.Process(dest, src);
}
-AclLiteError AclLiteImageProc::JpegD(ImageData& dest, ImageData& src) {
- JpegDHelper jpegD(stream_, dvppChannelDesc_);
+AclLiteError AclLiteImageProc::JpegD(ImageData& dest, ImageData& src)
+{
+ JpegDHelper jpegD(g_stream_, g_dvppChannelDesc_);
return jpegD.Process(dest, src);
}
AclLiteError AclLiteImageProc::Crop(ImageData& dest, ImageData& src,
uint32_t ltHorz, uint32_t ltVert,
- uint32_t rbHorz, uint32_t rbVert) {
- CropAndPasteHelper crop(stream_, dvppChannelDesc_,
+ uint32_t rbHorz, uint32_t rbVert)
+{
+ CropAndPasteHelper crop(g_stream_, g_dvppChannelDesc_,
ltHorz, ltVert, rbHorz, rbVert);
return crop.Process(dest, src);
}
@@ -111,9 +116,10 @@ AclLiteError AclLiteImageProc::Crop(ImageData& dest, ImageData& src,
AclLiteError AclLiteImageProc::CropPaste(ImageData& dest, ImageData& src,
uint32_t width, uint32_t height,
uint32_t ltHorz, uint32_t ltVert,
- uint32_t rbHorz, uint32_t rbVert) {
- CropAndPasteHelper crop(stream_, dvppChannelDesc_,
- width, height, ltHorz,
+ uint32_t rbHorz, uint32_t rbVert)
+{
+ CropAndPasteHelper crop(g_stream_, g_dvppChannelDesc_,
+ width, height, ltHorz,
ltVert, rbHorz, rbVert);
return crop.ProcessCropPaste(dest, src);
}
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteModel.cpp b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteModel.cpp
old mode 100755
new mode 100644
index 9887de360ecd894224b7bed0c7ae7e4380132a1f..53b02addb685ac131a95214f6a99f573fb652a04
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteModel.cpp
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteModel.cpp
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,38 +12,39 @@
* 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.cpp
-* Description: handle model process
*/
-#include "AclLiteModel.h"
+
#include
+#include "AclLiteModel.h"
#include "AclLiteUtils.h"
using namespace std;
-AclLiteModel::AclLiteModel(const string& modelPath):
- loadFlag_(false),
- isReleased_(false),
- modelId_(0),
- outputsNum_(0),
- modelMemSize_(0),
- modelWorkSize_(0),
- modelWeightSize_(0),
- modelMemPtr_(nullptr),
- modelWorkPtr_(nullptr),
- modelWeightPtr_(nullptr),
- modelDesc_(nullptr),
- input_(nullptr),
- output_(nullptr),
- modelPath_(modelPath) {
+AclLiteModel::AclLiteModel(const string& modelPath)
+ : g_loadFlag_(false),
+ g_isReleased_(false),
+ g_modelId_(0),
+ g_outputsNum_(0),
+ g_modelMemSize_(0),
+ g_modelWorkSize_(0),
+ g_modelWeightSize_(0),
+ g_modelMemPtr_(nullptr),
+ g_modelWorkPtr_(nullptr),
+ g_modelWeightPtr_(nullptr),
+ g_modelDesc_(nullptr),
+ g_input_(nullptr),
+ g_output_(nullptr),
+ g_modelPath_(modelPath)
+{
}
-AclLiteModel::~AclLiteModel() {
+AclLiteModel::~AclLiteModel()
+{
DestroyResource();
}
-void AclLiteModel::DestroyResource() {
- if (isReleased_) {
+void AclLiteModel::DestroyResource()
+{
+ if (g_isReleased_) {
return;
}
@@ -51,19 +52,20 @@ void AclLiteModel::DestroyResource() {
DestroyDesc();
DestroyInput();
DestroyOutput();
- isReleased_ = true;
+ g_isReleased_ = true;
}
-AclLiteError AclLiteModel::Init() {
- aclError aclRet = aclrtGetRunMode(&runMode_);
+AclLiteError AclLiteModel::Init()
+{
+ aclError aclRet = aclrtGetRunMode(&g_runMode_);
if (aclRet != ACL_SUCCESS) {
ACLLITE_LOG_ERROR("acl get run mode failed");
return ACLLITE_ERROR_GET_RUM_MODE;
}
- AclLiteError ret = LoadModelFromFile(modelPath_);
+ AclLiteError ret = LoadModelFromFile(g_modelPath_);
if (ret != ACLLITE_OK) {
- ACLLITE_LOG_ERROR("Load model %s from file failed", modelPath_.c_str());
+ ACLLITE_LOG_ERROR("Load model %s from file failed", g_modelPath_.c_str());
return ret;
}
@@ -79,42 +81,44 @@ AclLiteError AclLiteModel::Init() {
return ret;
}
- ACLLITE_LOG_INFO("Init model %s success", modelPath_.c_str());
+ ACLLITE_LOG_INFO("Init model %s success", g_modelPath_.c_str());
return ACLLITE_OK;
}
-AclLiteError AclLiteModel::LoadModelFromFile(const string& modelPath) {
- if (loadFlag_) {
+AclLiteError AclLiteModel::LoadModelFromFile(const string& modelPath)
+{
+ if (g_loadFlag_) {
ACLLITE_LOG_ERROR("%s is loaded already", modelPath.c_str());
return ACLLITE_ERROR_LOAD_MODEL_REPEATED;
}
- aclError ret = aclmdlLoadFromFile(modelPath.c_str(), &modelId_);
+ aclError ret = aclmdlLoadFromFile(modelPath.c_str(), &g_modelId_);
if (ret != ACL_SUCCESS) {
- ACLLITE_LOG_ERROR("Load model(%s) from file return %d",
+ ACLLITE_LOG_ERROR("Load model(%s) from file return %d",
modelPath.c_str(), ret);
return ACLLITE_ERROR_LOAD_MODEL;
}
- loadFlag_ = true;
+ g_loadFlag_ = true;
ACLLITE_LOG_INFO("Load model %s success", modelPath.c_str());
return ACLLITE_OK;
}
-AclLiteError AclLiteModel::SetDesc() {
- modelDesc_ = aclmdlCreateDesc();
- if (modelDesc_ == nullptr) {
- ACLLITE_LOG_ERROR("Create model(%s) description failed",
- modelPath_.c_str());
+AclLiteError AclLiteModel::SetDesc()
+{
+ g_modelDesc_ = aclmdlCreateDesc();
+ if (g_modelDesc_ == nullptr) {
+ ACLLITE_LOG_ERROR("Create model(%s) description failed",
+ g_modelPath_.c_str());
return ACLLITE_ERROR_CREATE_MODEL_DESC;
}
- aclError ret = aclmdlGetDesc(modelDesc_, modelId_);
+ aclError ret = aclmdlGetDesc(g_modelDesc_, g_modelId_);
if (ret != ACL_SUCCESS) {
- ACLLITE_LOG_ERROR("Get model(%s) description failed",
- modelPath_.c_str());
+ ACLLITE_LOG_ERROR("Get model(%s) description failed",
+ g_modelPath_.c_str());
return ACLLITE_ERROR_GET_MODEL_DESC;
}
@@ -124,25 +128,27 @@ AclLiteError AclLiteModel::SetDesc() {
void AclLiteModel::DestroyDesc()
{
- if (modelDesc_ != nullptr) {
- (void)aclmdlDestroyDesc(modelDesc_);
- modelDesc_ = nullptr;
+ if (g_modelDesc_ != nullptr) {
+ (void)aclmdlDestroyDesc(g_modelDesc_);
+ g_modelDesc_ = nullptr;
}
}
-AclLiteError AclLiteModel::CreateInput(void *input, uint32_t size) {
+AclLiteError AclLiteModel::CreateInput(void *input, uint32_t size)
+{
vector inputData = {{input, size}};
return CreateInput(inputData);
}
-AclLiteError AclLiteModel::CreateInput(void *input1, uint32_t input1size,
- void* input2, uint32_t input2size) {
- vector inputData = {{input1, input1size}, {input2, input2size}};
+AclLiteError AclLiteModel::CreateInput(void *input1, uint32_t input1Size,
+ void* input2, uint32_t input2Size)
+{
+ vector inputData = {{input1, input1Size}, {input2, input2Size}};
return CreateInput(inputData);
}
AclLiteError AclLiteModel::CreateInput(vector& inputData) {
- uint32_t dataNum = aclmdlGetNumInputs(modelDesc_);
+ uint32_t dataNum = aclmdlGetNumInputs(g_modelDesc_);
if (dataNum == 0) {
ACLLITE_LOG_ERROR("Create input failed for no input data");
@@ -153,20 +159,20 @@ AclLiteError AclLiteModel::CreateInput(vector& inputData) {
return ACLLITE_ERROR_INVALID_ARGS;
}
- input_ = aclmdlCreateDataset();
- if (input_ == nullptr) {
+ g_input_ = aclmdlCreateDataset();
+ if (g_input_ == nullptr) {
ACLLITE_LOG_ERROR("Create input failed for create dataset failed");
return ACLLITE_ERROR_CREATE_DATASET;
}
for (uint32_t i = 0; i < inputData.size(); i++) {
- size_t modelInputSize = aclmdlGetInputSizeByIndex(modelDesc_, i);
+ size_t modelInputSize = aclmdlGetInputSizeByIndex(g_modelDesc_, i);
if (modelInputSize != inputData[i].size) {
ACLLITE_LOG_WARNING("Input size verify failed "
- "input[%d] size: %ld, provide size : %d",
+ "input[%d] size: %ld, provide size : %d",
i, modelInputSize, inputData[i].size);
}
- AclLiteError atlRet = AddDatasetBuffer(input_,
+ AclLiteError atlRet = AddDatasetBuffer(g_input_,
inputData[i].data,
inputData[i].size);
if (atlRet != ACLLITE_OK) {
@@ -181,21 +187,21 @@ AclLiteError AclLiteModel::CreateInput(vector& inputData) {
AclLiteError AclLiteModel::CreateOutput()
{
- if (modelDesc_ == nullptr) {
+ if (g_modelDesc_ == nullptr) {
ACLLITE_LOG_ERROR("Create output failed for no model(%s) description",
- modelPath_.c_str());
+ g_modelPath_.c_str());
return ACLLITE_ERROR_NO_MODEL_DESC;
}
- output_ = aclmdlCreateDataset();
- if (output_ == nullptr) {
+ g_output_ = aclmdlCreateDataset();
+ if (g_output_ == nullptr) {
ACLLITE_LOG_ERROR("Create output failed for create dataset error");
return ACLLITE_ERROR_CREATE_DATASET;
}
- outputsNum_ = aclmdlGetNumOutputs(modelDesc_);
- for (size_t i = 0; i < outputsNum_; ++i) {
- size_t bufSize = aclmdlGetOutputSizeByIndex(modelDesc_, i);
+ g_outputsNum_ = aclmdlGetNumOutputs(g_modelDesc_);
+ for (size_t i = 0; i < g_outputsNum_; ++i) {
+ size_t bufSize = aclmdlGetOutputSizeByIndex(g_modelDesc_, i);
void *outputBuffer = nullptr;
aclError ret = aclrtMalloc(&outputBuffer, bufSize,
@@ -206,7 +212,7 @@ AclLiteError AclLiteModel::CreateOutput()
return ACLLITE_ERROR_MALLOC_DEVICE;
}
- AclLiteError atlRet = AddDatasetBuffer(output_, outputBuffer, bufSize);
+ AclLiteError atlRet = AddDatasetBuffer(g_output_, outputBuffer, bufSize);
if (atlRet != ACLLITE_OK) {
ACLLITE_LOG_ERROR("Create output failed for "
"add dataset buffer error %d", atlRet);
@@ -215,7 +221,7 @@ AclLiteError AclLiteModel::CreateOutput()
}
}
- ACLLITE_LOG_INFO("Create model(%s) output success", modelPath_.c_str());
+ ACLLITE_LOG_INFO("Create model(%s) output success", g_modelPath_.c_str());
return ACLLITE_OK;
}
@@ -261,15 +267,15 @@ AclLiteError AclLiteModel::Execute(vector& inferOutputs,
}
AclLiteError AclLiteModel::Execute(vector& inferOutputs) {
- aclError ret = aclmdlExecute(modelId_, input_, output_);
+ aclError ret = aclmdlExecute(g_modelId_, g_input_, g_output_);
if (ret != ACL_SUCCESS) {
- ACLLITE_LOG_ERROR("Execute model(%s) error:%d", modelPath_.c_str(), ret);
+ ACLLITE_LOG_ERROR("Execute model(%s) error:%d", g_modelPath_.c_str(), ret);
return ACLLITE_ERROR_EXECUTE_MODEL;
}
- for (uint32_t i = 0; i < outputsNum_; i++) {
+ for (uint32_t i = 0; i < g_outputsNum_; i++) {
InferenceOutput out;
- AclLiteError ret = GetOutputItem(out, i);
+ AclLiteError ret = GetOutputItem(out, i);
if (ret != ACLLITE_OK) {
ACLLITE_LOG_ERROR("Get the %dth interference output failed, "
"error: %d", i, ret);
@@ -283,7 +289,7 @@ AclLiteError AclLiteModel::Execute(vector& inferOutputs) {
AclLiteError AclLiteModel::GetOutputItem(InferenceOutput& out,
uint32_t idx) {
- aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(output_, idx);
+ aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(g_output_, idx);
if (dataBuffer == nullptr) {
ACLLITE_LOG_ERROR("Get the %dth dataset buffer from model "
"inference output failed", idx);
@@ -304,8 +310,8 @@ AclLiteError AclLiteModel::GetOutputItem(InferenceOutput& out,
return ACLLITE_ERROR_GET_DATA_BUFFER_SIZE;
}
- void* data = CopyDataToHost(dataBufferDev, bufferSize,
- runMode_, MEMORY_NORMAL);
+ void* data = CopyDataToHost(dataBufferDev, bufferSize,
+ g_runMode_, MEMORY_NORMAL);
if (data == nullptr) {
ACLLITE_LOG_ERROR("Copy inference output to host failed");
return ACLLITE_ERROR_COPY_DATA;
@@ -319,67 +325,67 @@ AclLiteError AclLiteModel::GetOutputItem(InferenceOutput& out,
void AclLiteModel::DestroyInput()
{
- if (input_ == nullptr) {
+ if (g_input_ == nullptr) {
return;
}
- for (size_t i = 0; i < aclmdlGetDatasetNumBuffers(input_); ++i) {
- aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(input_, i);
+ for (size_t i = 0; i < aclmdlGetDatasetNumBuffers(g_input_); ++i) {
+ aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(g_input_, i);
aclDestroyDataBuffer(dataBuffer);
dataBuffer = nullptr;
}
- aclmdlDestroyDataset(input_);
- input_ = nullptr;
+ aclmdlDestroyDataset(g_input_);
+ g_input_ = nullptr;
}
void AclLiteModel::DestroyOutput()
{
- if (output_ == nullptr) {
+ if (g_output_ == nullptr) {
return;
}
- for (size_t i = 0; i < aclmdlGetDatasetNumBuffers(output_); ++i) {
- aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(output_, i);
+ for (size_t i = 0; i < aclmdlGetDatasetNumBuffers(g_output_); ++i) {
+ aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(g_output_, i);
void* data = aclGetDataBufferAddr(dataBuffer);
(void)aclrtFree(data);
(void)aclDestroyDataBuffer(dataBuffer);
dataBuffer = nullptr;
}
- (void)aclmdlDestroyDataset(output_);
- output_ = nullptr;
+ (void)aclmdlDestroyDataset(g_output_);
+ g_output_ = nullptr;
}
void AclLiteModel::Unload()
{
- if (!loadFlag_) {
+ if (!g_loadFlag_) {
ACLLITE_LOG_INFO("Model(%s) had not been loaded or unload already",
- modelPath_.c_str());
+ g_modelPath_.c_str());
return;
}
- aclError ret = aclmdlUnload(modelId_);
+ aclError ret = aclmdlUnload(g_modelId_);
if (ret != ACL_SUCCESS) {
- ACLLITE_LOG_ERROR("Unload model(%s) error:%d", modelPath_.c_str(), ret);
+ ACLLITE_LOG_ERROR("Unload model(%s) error:%d", g_modelPath_.c_str(), ret);
}
- if (modelDesc_ != nullptr) {
- (void)aclmdlDestroyDesc(modelDesc_);
- modelDesc_ = nullptr;
+ if (g_modelDesc_ != nullptr) {
+ (void)aclmdlDestroyDesc(g_modelDesc_);
+ g_modelDesc_ = nullptr;
}
- if (modelMemPtr_ != nullptr) {
- aclrtFree(modelMemPtr_);
- modelMemPtr_ = nullptr;
- modelMemSize_ = 0;
+ if (g_modelMemPtr_ != nullptr) {
+ aclrtFree(g_modelMemPtr_);
+ g_modelMemPtr_ = nullptr;
+ g_modelMemSize_ = 0;
}
- if (modelWeightPtr_ != nullptr) {
- aclrtFree(modelWeightPtr_);
- modelWeightPtr_ = nullptr;
- modelWeightSize_ = 0;
+ if (g_modelWeightPtr_ != nullptr) {
+ aclrtFree(g_modelWeightPtr_);
+ g_modelWeightPtr_ = nullptr;
+ g_modelWeightSize_ = 0;
}
- loadFlag_ = false;
- ACLLITE_LOG_INFO("Unload model %s success", modelPath_.c_str());
+ g_loadFlag_ = false;
+ ACLLITE_LOG_INFO("Unload model %s success", g_modelPath_.c_str());
}
\ No newline at end of file
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteResource.cpp b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteResource.cpp
old mode 100755
new mode 100644
index a8dab3a4e3c757e2887095fe316156506404065d..f43033b5373f1aff35e93f5a8401ffb2425c40cb
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteResource.cpp
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteResource.cpp
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,31 +12,32 @@
* 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.cpp
-* Description: handle file operations
*/
+
#include "AclLiteUtils.h"
#include "AclLiteResource.h"
using namespace std;
-AclLiteResource::AclLiteResource():
- isReleased_(false),
- useDefaultCtx_(true),
- deviceId_(0),
- runMode_(ACL_HOST),
- context_(nullptr),
- aclConfig_("") {
+AclLiteResource::AclLiteResource()
+ : g_isReleased_(false),
+ g_useDefaultCtx_(true),
+ g_deviceId_(0),
+ g_runMode_(ACL_HOST),
+ g_context_(nullptr),
+ g_aclConfig_("")
+{
}
-AclLiteResource::~AclLiteResource() {
+AclLiteResource::~AclLiteResource()
+{
Release();
}
-AclLiteError AclLiteResource::Init() {
+AclLiteError AclLiteResource::Init()
+{
// ACL init
- aclError ret = aclInit(aclConfig_.c_str());
+ aclError ret = aclInit(g_aclConfig_.c_str());
if (ret != ACL_SUCCESS) {
ACLLITE_LOG_ERROR("Acl init failed, errorcode is: %d", ret);
return ACLLITE_ERROR;
@@ -44,29 +45,29 @@ AclLiteError AclLiteResource::Init() {
ACLLITE_LOG_INFO("Acl init ok");
// open device
- ret = aclrtSetDevice(deviceId_);
+ ret = aclrtSetDevice(g_deviceId_);
if (ret != ACL_SUCCESS) {
- ACLLITE_LOG_ERROR("Acl open device %d failed, errorCode is : %d", deviceId_, ret);
+ ACLLITE_LOG_ERROR("Acl open device %d failed, errorCode is : %d", g_deviceId_, ret);
return ACLLITE_ERROR;
}
- ACLLITE_LOG_INFO("Open device %d ok", deviceId_);
+ ACLLITE_LOG_INFO("Open device %d ok", g_deviceId_);
- if (useDefaultCtx_) {
+ if (g_useDefaultCtx_) {
ACLLITE_LOG_INFO("Use default context currently");
- ret = aclrtGetCurrentContext(&context_);
- if ((ret != ACL_SUCCESS) || (context_ == nullptr)) {
+ ret = aclrtGetCurrentContext(&g_context_);
+ if ((ret != ACL_SUCCESS) || (g_context_ == nullptr)) {
ACLLITE_LOG_ERROR("Get current acl context failed, errorCode is : %d", ret);
return ACLLITE_ERROR_GET_ACL_CONTEXT;
}
} else {
- ret = aclrtCreateContext(&context_, deviceId_);
+ ret = aclrtCreateContext(&g_context_, g_deviceId_);
if (ret != ACL_SUCCESS) {
ACLLITE_LOG_ERROR("Create acl context failed, errorCode is : %d", ret);
return ACLLITE_ERROR_CREATE_ACL_CONTEXT;
}
}
- ret = aclrtGetRunMode(&runMode_);
+ ret = aclrtGetRunMode(&g_runMode_);
if (ret != ACL_SUCCESS) {
ACLLITE_LOG_WARNING("acl get run mode failed, errorCode is : %d", ret);
}
@@ -74,26 +75,27 @@ AclLiteError AclLiteResource::Init() {
return ACLLITE_OK;
}
-void AclLiteResource::Release() {
- if (isReleased_) {
+void AclLiteResource::Release()
+{
+ if (g_isReleased_) {
return;
}
aclError ret;
- if ((!useDefaultCtx_) && (context_ != nullptr)) {
- ret = aclrtDestroyContext(context_);
+ if ((!g_useDefaultCtx_) && (g_context_ != nullptr)) {
+ ret = aclrtDestroyContext(g_context_);
if (ret != ACL_SUCCESS) {
ACLLITE_LOG_ERROR("destroy context failed, errorCode is : %d", ret);
}
- context_ = nullptr;
+ g_context_ = nullptr;
}
ACLLITE_LOG_INFO("destroy context ok");
- ret = aclrtResetDevice(deviceId_);
+ ret = aclrtResetDevice(g_deviceId_);
if (ret != ACL_SUCCESS) {
ACLLITE_LOG_ERROR("reset device failed, errorCode is : %d", ret);
}
- ACLLITE_LOG_INFO("Reset device %d ok", deviceId_);
+ ACLLITE_LOG_INFO("Reset device %d ok", g_deviceId_);
ret = aclFinalize();
if (ret != ACL_SUCCESS) {
@@ -101,5 +103,5 @@ void AclLiteResource::Release() {
}
ACLLITE_LOG_INFO("Finalize acl ok");
- isReleased_ = true;
+ g_isReleased_ = true;
}
diff --git a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteUtils.cpp b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteUtils.cpp
old mode 100755
new mode 100644
index d29d61bb53e3a3c58e36337c6ae077fa3e802853..e60c9a35926cf690936c5f04d44a6d426ec98168
--- a/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteUtils.cpp
+++ b/cplusplus/level2_simple_inference/2_object_detection/YOLOV3_carColor_sample/src/AclLiteUtils.cpp
@@ -1,5 +1,5 @@
-/**
-* Copyright 2020 Huawei Technologies Co., Ltd
+/*
+* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,11 +12,8 @@
* 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.cpp
-* Description: handle file operations
*/
-#include "AclLiteUtils.h"
+
#include