Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
dc2cc7d2
M
models
项目概览
PaddlePaddle
/
models
大约 2 年 前同步成功
通知
232
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
dc2cc7d2
编写于
5月 22, 2018
作者:
Q
qingqing01
提交者:
GitHub
5月 22, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Small doc fix and add .gitignore (#924)
上级
e0dfa236
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
22 deletion
+26
-22
fluid/image_classification/caffe2fluid/.gitignore
fluid/image_classification/caffe2fluid/.gitignore
+2
-0
fluid/image_classification/caffe2fluid/README.md
fluid/image_classification/caffe2fluid/README.md
+24
-22
未找到文件。
fluid/image_classification/caffe2fluid/.gitignore
0 → 100644
浏览文件 @
dc2cc7d2
proto/caffepb.py
proto/caffe_pb2.py
fluid/image_classification/caffe2fluid/README.md
浏览文件 @
dc2cc7d2
...
@@ -8,10 +8,10 @@ This tool is used to convert a Caffe model to a Fluid model
...
@@ -8,10 +8,10 @@ This tool is used to convert a Caffe model to a Fluid model
3.
Caffe's customized layers convertion also be supported by extending this tool
3.
Caffe's customized layers convertion also be supported by extending this tool
4.
A bunch of tools in
'
*examples/imagenet/tools*
'
are provided to compare the difference
4.
A bunch of tools in
`examples/imagenet/tools`
are provided to compare the difference
### HowTo
### HowTo
1.
Prepare
caffepb.py in ./proto if your python has no 'pycaffe'
module, two options provided here:
1.
Prepare
`caffepb.py`
in
`./proto`
if your python has no
`pycaffe`
module, two options provided here:
-
Generate pycaffe from caffe.proto
-
Generate pycaffe from caffe.proto
```
```
bash ./proto/compile.sh
bash ./proto/compile.sh
...
@@ -24,37 +24,39 @@ This tool is used to convert a Caffe model to a Fluid model
...
@@ -24,37 +24,39 @@ This tool is used to convert a Caffe model to a Fluid model
2.
Convert the Caffe model to Fluid model
2.
Convert the Caffe model to Fluid model
-
Generate fluid code and weight file
-
Generate fluid code and weight file
```
```
python convert.py alexnet.prototxt \
python convert.py alexnet.prototxt \
--caffemodel alexnet.caffemodel \
--caffemodel alexnet.caffemodel \
--data-output-path alexnet.npy \
--data-output-path alexnet.npy \
--code-output-path alexnet.py
--code-output-path alexnet.py
```
```
- Save weights as fluid model file
-
Save weights as fluid model file
```
```
python alexnet.py alexnet.npy ./fluid #only infer the last layer's result
# only infer the last layer's result
python alexnet.py alexnet.npy ./fluid fc8,prob #infer these 2 layer's result
python alexnet.py alexnet.npy ./fluid
```
# infer these 2 layer's result
python alexnet.py alexnet.npy ./fluid fc8,prob
```
3.
Use the converted model to infer
3.
Use the converted model to infer
- See more details in
'*examples/imagenet/tools/run.sh*'
-
See more details in
`examples/imagenet/tools/run.sh`
4.
Compare the inference results with caffe
4.
Compare the inference results with caffe
- See more details in
'*examples/imagenet/tools/diff.sh*'
-
See more details in
`examples/imagenet/tools/diff.sh`
### How to convert custom layer
### How to convert custom layer
1. Implement your custom layer in a file under
'*kaffe/custom_layers*'
, eg: mylayer.py
1.
Implement your custom layer in a file under
`kaffe/custom_layers`
, eg: mylayer.py
-
Implement
```shape_func(input_shape, [other_caffe_params])```
to calculate the output shape
-
Implement
```shape_func(input_shape, [other_caffe_params])```
to calculate the output shape
-
Implement
```layer_func(inputs, name, [other_caffe_params])```
to construct a fluid layer
-
Implement
```layer_func(inputs, name, [other_caffe_params])```
to construct a fluid layer
-
Register these two functions
```register(kind='MyType', shape=shape_func, layer=layer_func)```
-
Register these two functions
```register(kind='MyType', shape=shape_func, layer=layer_func)```
- Notes: more examples can be found in
'*kaffe/custom_layers*'
-
Notes: more examples can be found in
`kaffe/custom_layers`
2. Add ```import mylayer``` to
'*kaffe/custom_layers/\_\_init__.py*'
2.
Add
```import mylayer```
to
`kaffe/custom_layers/\_\_init__.py`
3.
Prepare your pycaffe as your customized version(same as previous env prepare)
3.
Prepare your pycaffe as your customized version(same as previous env prepare)
- (option1) replace
'proto/caffe.proto'
with your own caffe.proto and compile it
-
(option1) replace
`proto/caffe.proto`
with your own caffe.proto and compile it
- (option2) change your
pycaffe
to the customized version
-
(option2) change your
`pycaffe`
to the customized version
4.
Convert the Caffe model to Fluid model
4.
Convert the Caffe model to Fluid model
...
@@ -63,7 +65,7 @@ This tool is used to convert a Caffe model to a Fluid model
...
@@ -63,7 +65,7 @@ This tool is used to convert a Caffe model to a Fluid model
export CAFFE2FLUID_CUSTOM_LAYERS=/path/to/caffe2fluid/kaffe
export CAFFE2FLUID_CUSTOM_LAYERS=/path/to/caffe2fluid/kaffe
```
```
6. Use the converted model when loading model in
'xxxnet.py' and 'xxxnet.npy'(no need if model is already in 'fluid/model' and 'fluid/params'
)
6.
Use the converted model when loading model in
`xxxnet.py`
and
`xxxnet.npy`
(no need if model is already in
`fluid/model`
and
`fluid/params`
)
### Tested models
### Tested models
-
Lenet:
-
Lenet:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录