Skip to content

Commit

Permalink
Merge branch 'object_detection' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wk-mnA committed May 30, 2024
2 parents 2b22614 + e0f98f5 commit 83ac606
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 112 deletions.
42 changes: 21 additions & 21 deletions R01_object_detection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ The AI model used for the sample application is [YOLOV3](https://arxiv.org/pdf/1
<tr>
<td>microSD card</td>
<td>Used as the filesystem.<br>
Must have over 4GB capacity of blank space.<br>
Must have over 16GB capacity of blank space.<br>
Operating Environment: Transcend UHS-I microSD 300S 16GB</td>
</tr>
<tr>
Expand Down Expand Up @@ -224,10 +224,10 @@ Replace each variable according to your board.
cd ${PROJECT_PATH}/R01_object_detection/<EXE_DIR>/yolov3_onnx
wget <URL>/<SO_FILE>
```
|Board | `EXE_DIR` |`SO_FILE` |`URL` |
|:---|:---|:---|:---|
|RZ/V2L EVK|[exe_v2l](./exe_v2l) |<span style="font-size: small">`R01_object_detection_deploy_tvm-v111.so`</span> |[Release v2.00](https://github.com/renesas-rz/rzv_ai_sdk/releases/tag/v2.00/) |
|RZ/V2H EVK|[exe_v2h](./exe_v2h) |<span style="font-size: small">`R01_object_detection_deploy_tvm_v2h-v210.so`</span> |[Release v3.00](https://github.com/renesas-rz/rzv_ai_sdk/releases/tag/v3.00/) |
|Board | `EXE_DIR` |`URL` |`SO_FILE` |File Location |
|:---|:---|:---|:---|:---|
|RZ/V2L EVK|[exe_v2l](./exe_v2l) |<span style="font-size: small">`https://github.com/renesas-rz/rzv_ai_sdk/releases/download/v2.00/`</span> |<span style="font-size: small">`R01_object_detection_deploy_tvm-v111.so`</span> |[Release v2.00](https://github.com/renesas-rz/rzv_ai_sdk/releases/tag/v2.00/) |
|RZ/V2H EVK|[exe_v2h](./exe_v2h) |<span style="font-size: small">`https://github.com/renesas-rz/rzv_ai_sdk/releases/download/v4.00/`</span> |<span style="font-size: small">`R01_object_detection_deploy_tvm_v2h-v221.so`</span> |[Release v4.00](https://github.com/renesas-rz/rzv_ai_sdk/releases/tag/v4.00/) |

- E.g., for RZ/V2L EVK, use following commands.
```sh
Expand All @@ -247,20 +247,20 @@ Replace each variable according to your board.
4. Check if `libtvm_runtime.so` exists under `/usr/lib64` directory of the rootfs (SD card) on the board.

5. Folder structure in the rootfs (SD Card) would look like:
```sh
├── usr/
└── lib64/
└── libtvm_runtime.so
└── home/
└── root/
└── tvm/
├── yolov3_onnx/
├── preprocess
├── deploy.json
├── deploy.params
└── deploy.so
├── coco-labels-2014_2017.txt
└── object_detection
```
|-- usr/
| `-- lib64/
| `-- libtvm_runtime.so
`-- home/
`-- root/
`-- tvm/
|-- yolov3_onnx/
| |-- preprocess
| |-- deploy.json
| |-- deploy.params
| `-- deploy.so
|-- coco-labels-2014_2017.txt
`-- object_detection
```
>**Note:** The directory name could be anything instead of `tvm`. If you copy the whole `EXE_DIR` folder on the board, you are not required to rename it `tvm`.
Expand All @@ -287,7 +287,7 @@ After completion of the guide, the user is expected of following things.
|RZ/V2L EVK | RZ/V2H EVK |
|:---|:---|
|<img src=./img/objectdetection.png width=350>| <img src=./img/objectdetection_v2h.png width=350> |
|<img src=./img/objectdetection.png width=350>| <img src=./img/objectdetection_v2h.jpg width=350> |
On application window, following information is displayed.
- Camera capture
Expand All @@ -314,7 +314,7 @@ Output3 size: 1x52x52x255
|Board | AI inference time|
|:---|:---|
|RZ/V2L EVK| Approximately 430ms |
|RZ/V2H EVK | Approximately 40ms |
|RZ/V2H EVK | Approximately 30ms |
### Processing
Expand Down
Binary file modified R01_object_detection/exe_v2h/object_detection
Binary file not shown.
8 changes: 4 additions & 4 deletions R01_object_detection/exe_v2h/yolov3_onnx/deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
},
{
"op": "tvm_op",
"name": "tvmgen_default_tvmgen_default_tvmgen_default_mera_drp_main_0",
"name": "tvmgen_default_tvmgen_default_mera_drp_main_0",
"attrs": {
"flatten_data": "0",
"func_name": "tvmgen_default_tvmgen_default_tvmgen_default_mera_drp_main_0",
"hash": "8204a5bc4fae0685",
"func_name": "tvmgen_default_tvmgen_default_mera_drp_main_0",
"hash": "eb1640a6874236c6",
"num_outputs": "3",
"num_inputs": "1",
"global_symbol": "tvmgen_default_tvmgen_default_tvmgen_default_mera_drp_main_0",
"global_symbol": "tvmgen_default_tvmgen_default_mera_drp_main_0",
"Compiler": "mera_drp"
},
"inputs": [
Expand Down
14 changes: 7 additions & 7 deletions R01_object_detection/exe_v2h/yolov3_onnx/preprocess/addr_map.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ data 12c000 279c00
data_out 3a5c00 1fb000
work 5a0c00 80
weight 5a0c80 80
drp_config 5a0d00 f3bc0
aimac_param_cmd 6948c0 20
aimac_param_desc 694900 10
aimac_cmd 694940 180
aimac_desc 694ac0 50
drp_param 694b80 f0
drp_desc 694c80 110
drp_config 5a0d00 efe10
aimac_param_cmd 690b40 20
aimac_param_desc 690b80 10
aimac_cmd 690bc0 180
aimac_desc 690d40 50
drp_param 690e00 f0
drp_desc 690f00 110
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified R01_object_detection/exe_v2h/yolov3_onnx/preprocess/drp_desc.bin
Binary file not shown.
8 changes: 4 additions & 4 deletions R01_object_detection/exe_v2h/yolov3_onnx_fhd/deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
},
{
"op": "tvm_op",
"name": "tvmgen_default_tvmgen_default_tvmgen_default_mera_drp_main_0",
"name": "tvmgen_default_tvmgen_default_mera_drp_main_0",
"attrs": {
"flatten_data": "0",
"func_name": "tvmgen_default_tvmgen_default_tvmgen_default_mera_drp_main_0",
"hash": "8204a5bc4fae0685",
"func_name": "tvmgen_default_tvmgen_default_mera_drp_main_0",
"hash": "eb1640a6874236c6",
"num_outputs": "3",
"num_inputs": "1",
"global_symbol": "tvmgen_default_tvmgen_default_tvmgen_default_mera_drp_main_0",
"global_symbol": "tvmgen_default_tvmgen_default_mera_drp_main_0",
"Compiler": "mera_drp"
},
"inputs": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ data a8c000 279c00
data_out d05c00 1fb000
work f00c00 80
weight f00c80 80
drp_config f00d00 f3bc0
aimac_param_cmd ff48c0 20
aimac_param_desc ff4900 10
aimac_cmd ff4940 180
aimac_desc ff4ac0 50
drp_param ff4b80 f0
drp_desc ff4c80 110
drp_config f00d00 efe10
aimac_param_cmd ff0b40 20
aimac_param_desc ff0b80 10
aimac_cmd ff0bc0 180
aimac_desc ff0d40 50
drp_param ff0e00 f0
drp_desc ff0f00 110
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified R01_object_detection/img/objectdetection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added R01_object_detection/img/objectdetection_v2h.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed R01_object_detection/img/objectdetection_v2h.png
Binary file not shown.
22 changes: 21 additions & 1 deletion R01_object_detection/src_v2h/MeraDrpRuntimeWrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Original Code (C) Copyright Edgecortix, Inc. 2022
* Modified Code (C) Copyright Renesas Electronics Corporation 2023
* Modified Code (C) Copyright Renesas Electronics Corporation 2023 
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -136,6 +136,10 @@ void MeraDrpRuntimeWrapper::Run() {
mod.GetFunction("run")();
}

void MeraDrpRuntimeWrapper::Run(int freq_index) {
mod.GetFunction("run")(freq_index);
}

void MeraDrpRuntimeWrapper::ProfileRun(const std::string& profile_table, const std::string& profile_csv) {
tvm::runtime::PackedFunc profile = mod.GetFunction("profile");
tvm::runtime::Array<tvm::runtime::profiling::MetricCollector> collectors;
Expand All @@ -152,6 +156,22 @@ void MeraDrpRuntimeWrapper::ProfileRun(const std::string& profile_table, const s
ofs_csv.close();
}

void MeraDrpRuntimeWrapper::ProfileRun(const std::string& profile_table, const std::string& profile_csv, int freq_index) {
tvm::runtime::PackedFunc profile = mod.GetFunction("profile");
tvm::runtime::Array<tvm::runtime::profiling::MetricCollector> collectors;
tvm::runtime::profiling::Report report = profile(collectors, freq_index);

std::string rep_table = report->AsTable();
std::ofstream ofs_table (profile_table, std::ofstream::out);
ofs_table << rep_table << std::endl;
ofs_table.close();

std::string rep_csv = report->AsCSV();
std::ofstream ofs_csv (profile_csv, std::ofstream::out);
ofs_csv << rep_csv << std::endl;
ofs_csv.close();
}

int MeraDrpRuntimeWrapper::GetNumInput(std::string model_dir) {
// TVM does not support api to get number input of model.
// This function calculate input number base on convention
Expand Down
4 changes: 3 additions & 1 deletion R01_object_detection/src_v2h/MeraDrpRuntimeWrapper.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Original Code (C) Copyright Edgecortix, Inc. 2022
* Modified Code (C) Copyright Renesas Electronics Corporation 2023
* Modified Code (C) Copyright Renesas Electronics Corporation 2023 
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -38,7 +38,9 @@ class MeraDrpRuntimeWrapper {
template <typename T>
void SetInput(int input_index, const T* data_ptr);
void Run();
void Run(int freq_index);
void ProfileRun(const std::string& profile_table, const std::string& profile_csv);
void ProfileRun(const std::string& profile_table, const std::string& profile_csv, int freq_index);
int GetNumInput(std::string model_dir);
InOutDataType GetInputDataType(int index);
int GetNumOutput();
Expand Down
2 changes: 1 addition & 1 deletion R01_object_detection/src_v2h/PreRuntime.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Original Code (C) Copyright Renesas Electronics Corporation 2023
*
* 
* *1 DRP-AI TVM is powered by EdgeCortix MERA(TM) Compiler Framework.
*
* Licensed to the Apache Software Foundation (ASF) under one
Expand Down
2 changes: 1 addition & 1 deletion R01_object_detection/src_v2h/PreRuntimeV2H.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Original Code (C) Copyright Renesas Electronics Corporation 2023
*
* 
* *1 DRP-AI TVM is powered by EdgeCortix MERA(TM) Compiler Framework.
*
* Licensed to the Apache Software Foundation (ASF) under one
Expand Down
13 changes: 2 additions & 11 deletions R01_object_detection/src_v2h/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,10 @@ const static uint32_t INF_OUT_SIZE = (NUM_CLASS + 5) * NUM_BB * num_grids[0] *
/*For termination method display*/
#define TEXT_START_X (1440)

/* DRP_MAX_FREQ and DRPAI_FREQ are the */
/* frequency settings for DRP-AI. */
/* DRPAI_FREQ is the frequency settings */
/* for DRP-AI. */
/* Basically use the default values */

#define DRP_MAX_FREQ (2)
/* DRP_MAX_FREQ can be set from 2 to 127 */
/* 2: 420MHz */
/* 3: 315MHz */
/* ... */
/* 127: 9.84MHz */
/* Calculation Formula: */
/* 1260MHz /(DRP_MAX_FREQ + 1) */

#define DRPAI_FREQ (2)
/* DRPAI_FREQ can be set from 1 to 127 */
/* 1,2: 1GHz */
Expand Down
67 changes: 13 additions & 54 deletions R01_object_detection/src_v2h/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ static uint32_t array_cap_time[30] = {1000,1000,1000,1000,1000,1000,1000,1000,10
#endif /* DISP_CAM_FRAME_RATE */

/*DRP-AI Frequency setting*/
static int32_t drp_max_freq;
static int32_t drpai_freq;

static Wayland wayland;
Expand Down Expand Up @@ -712,7 +711,7 @@ void *R_Inf_Thread(void *threadid)
goto err;
}

runtime.Run();
runtime.Run(drpai_freq);

/*Gets AI Inference End Time*/
ret = timespec_get(&inf_end_time, TIME_UTC);
Expand Down Expand Up @@ -1187,38 +1186,6 @@ uint64_t get_drpai_start_addr(int drpai_fd)
return drpai_data.address;
}

/*****************************************
* Function Name : set_drpai_freq
* Description : Function to set the DRP and DRP-AI frequency.
* Arguments : drpai_fd: DRP-AI file descriptor
* Return value : 0 if succeeded
* not 0 otherwise
******************************************/
int set_drpai_freq(int drpai_fd)
{
int ret = 0;
uint32_t data;

errno = 0;
data = drp_max_freq;
ret = ioctl(drpai_fd , DRPAI_SET_DRP_MAX_FREQ, &data);
if (-1 == ret)
{
fprintf(stderr, "[ERROR] Failed to set DRP Max Frequency : errno=%d\n", errno);
return -1;
}

errno = 0;
data = drpai_freq;
ret = ioctl(drpai_fd , DRPAI_SET_DRPAI_FREQ, &data);
if (-1 == ret)
{
fprintf(stderr, "[ERROR] Failed to set DRP-AI Frequency : errno=%d\n", errno);
return -1;
}
return 0;
}

/*****************************************
* Function Name : init_drpai
* Description : Function to initialize DRP-AI.
Expand All @@ -1239,13 +1206,6 @@ uint64_t init_drpai(int drpai_fd)
return 0;
}

/*Set DRP-AI frequency*/
ret = set_drpai_freq(drpai_fd);
if (ret != 0)
{
return 0;
}

return drpai_addr;
}

Expand All @@ -1266,6 +1226,8 @@ int32_t main(int32_t argc, char * argv[])
bool runtime_status = false;
int drpai_fd;

uint64_t drpaimem_addr_start = 0;

std::string media_port = query_device_status("usb");
gstreamer_pipeline = "v4l2src device=" + media_port +" ! video/x-raw, width="+std::to_string(CAM_IMAGE_WIDTH)+", height="+std::to_string(CAM_IMAGE_HEIGHT)+" ,framerate=30/1 ! videoconvert ! appsink -v";

Expand All @@ -1282,25 +1244,22 @@ int32_t main(int32_t argc, char * argv[])
/* Usually, users can use default values. */
if (2 <= argc)
{
drp_max_freq = atoi(argv[1]);
printf("Argument : <DRP0_max_freq_factor> = %d\n", drp_max_freq);
}
else
{
drp_max_freq = DRP_MAX_FREQ;
}
if (3 <= argc)
{
drpai_freq = atoi(argv[2]);
printf("Argument : <AI-MAC_freq_factor> = %d\n", drpai_freq);
drpai_freq = atoi(argv[1]);
if ((1 <= drpai_freq) && (127 >= drpai_freq))
{
printf("Argument : <AI-MAC_freq_factor> = %d\n", drpai_freq);
}
else
{
fprintf(stderr,"[ERROR] Invalid Command Line Argument : <AI-MAC_freq_factor>=%d\n", drpai_freq);
goto end_main;
}
}
else
{
drpai_freq = DRPAI_FREQ;
}

uint64_t drpaimem_addr_start = 0;

/*Load Label from label_list file*/
label_file_map = load_label_file(label_list);
if (label_file_map.empty())
Expand Down

0 comments on commit 83ac606

Please sign in to comment.