README.md 2.91 KB
Newer Older
liucong's avatar
liucong committed
1
2
3
4
5
6
7
8
9
10
# ResNet50

## 模型介绍
使用MIGraphX推理框架对ResNet50模型进行推理。

## 模型结构
ResNet50模型包含了49个卷积层、一个全连接层。

## Python版本推理

liucong's avatar
liucong committed
11
下面介绍如何运行Python代码示例,Python示例的详细说明见Doc目录下的Tutorial_Python.md。
liucong's avatar
liucong committed
12

liucong's avatar
liucong committed
13
### 下载镜像
liucong's avatar
liucong committed
14

liucong's avatar
liucong committed
15
在光源中下载MIGraphX镜像: 
liucong's avatar
liucong committed
16
17
18
19
20

```python
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
```

liucong's avatar
liucong committed
21
### 设置Python环境变量
liucong's avatar
liucong committed
22

liucong's avatar
liucong committed
23
24
25
```
export PYTHONPATH=/opt/dtk/lib:$PYTHONPATH
```
liucong's avatar
liucong committed
26

liucong's avatar
liucong committed
27
### 安装依赖
liucong's avatar
liucong committed
28
29

```python
liucong's avatar
liucong committed
30
# 进入resnet50 migraphx工程根目录
liucong's avatar
liucong committed
31
cd <path_to_resnet50_migraphx> 
liucong's avatar
liucong committed
32
33
34
35
36
37
38
39

# 进入示例程序目录
cd Python/

# 安装依赖
pip install -r requirements.txt
```

liucong's avatar
liucong committed
40
41
42
### 运行示例

在Python目录下执行如下命令运行该示例程序:
liucong's avatar
liucong committed
43
44
45
46
47
48
49
50

```python
python Classifier.py
```

输出结果中,每个值分别对应每个label的输出值。

```
liucong's avatar
liucong committed
51
52
[-2.07137913e-02  2.25237548e-01 -1.98313940e+00 -2.97359991e+00
 -1.61100197e+00  4.24269080e-01 -9.02939081e-01  1.21229446e+00
liucong's avatar
liucong committed
53
 ...
liucong's avatar
liucong committed
54
55
 -2.69769251e-01 -4.28011447e-01  1.25102985e+00  9.06333506e-01
 -1.08657002e-01  3.15954179e-01  1.94901276e+00 -5.70572793e-01]
liucong's avatar
liucong committed
56
57
58
59
```

## C++版本推理

liucong's avatar
liucong committed
60
61
62
63
64
下面介绍如何运行C++代码示例,C++示例的详细说明见Doc目录下的Tutorial_Cpp.md。

### 下载镜像

在光源中下载MIGraphX镜像: 
liucong's avatar
liucong committed
65

liucong's avatar
liucong committed
66
67
68
```
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:ort1.14.0_migraphx3.0.0-dtk22.10.1
```
liucong's avatar
liucong committed
69
70
71
72

### 安装Opencv依赖

```python
liucong's avatar
liucong committed
73
cd <path_to_resnet50_migraphx>
liucong's avatar
liucong committed
74
75
76
77
78
sh ./3rdParty/InstallOpenCVDependences.sh
```

### 修改CMakeLists.txt

liucong's avatar
liucong committed
79
80
如果使用ubuntu系统,需要修改CMakeLists.txt中依赖库路径:
将"${CMAKE_CURRENT_SOURCE_DIR}/depend/lib64/"修改为"${CMAKE_CURRENT_SOURCE_DIR}/depend/lib/"
liucong's avatar
liucong committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95


### 安装OpenCV并构建工程

```
rbuild build -d depend
```

### 设置环境变量

将依赖库依赖加入环境变量LD_LIBRARY_PATH,在~/.bashrc中添加如下语句:

**Centos**:

```
liucong's avatar
liucong committed
96
export LD_LIBRARY_PATH=<path_to_resnet50_migraphx>/depend/lib64/:$LD_LIBRARY_PATH
liucong's avatar
liucong committed
97
98
99
100
101
```

**Ubuntu**:

```
liucong's avatar
liucong committed
102
export LD_LIBRARY_PATH=<path_to_resnet50_migraphx>/depend/lib/:$LD_LIBRARY_PATH
liucong's avatar
liucong committed
103
104
105
106
107
108
109
110
```

然后执行:

```
source ~/.bashrc
```

liucong's avatar
liucong committed
111
### 运行示例
liucong's avatar
liucong committed
112
113

```python
liucong's avatar
liucong committed
114
# 进入resnet50 migraphx工程根目录
liucong's avatar
liucong committed
115
cd <path_to_resnet50_migraphx> 
liucong's avatar
liucong committed
116
117
118
119
120
121
122
123
124
125
126

# 进入build目录
cd ./build/

# 执行示例程序
./ResNet50
```

输出结果中,每个值分别对应每个label的输出值。

```
liucong's avatar
liucong committed
127
128
129
130
131
132
label:0,confidence:-0.020714
label:1,confidence:0.225238
label:2,confidence:-1.983140
label:3,confidence:-2.973601
label:4,confidence:-1.611002
label:5,confidence:0.424268
liucong's avatar
liucong committed
133
...
liucong's avatar
liucong committed
134
135
136
137
138
label:995,confidence:0.906333
label:996,confidence:-0.108658
label:997,confidence:0.315955
label:998,confidence:1.949013
label:999,confidence:-0.570573
liucong's avatar
liucong committed
139
140
```

liucong's avatar
liucong committed
141
## 源码仓库及问题反馈
liucong's avatar
liucong committed
142

liucong's avatar
liucong committed
143
https://developer.hpccube.com/codes/modelzoo/resnet50_migraphx
liucong's avatar
liucong committed
144

liucong's avatar
liucong committed
145
## 参考
liucong's avatar
liucong committed
146

liucong's avatar
liucong committed
147
https://github.com/onnx/models/tree/main/vision/classification/resnet
liucong's avatar
liucong committed
148