Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
ce6ffee2
X
X2Paddle
项目概览
PaddlePaddle
/
X2Paddle
大约 1 年 前同步成功
通知
328
Star
698
Fork
167
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
26
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
X2Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
26
Issue
26
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ce6ffee2
编写于
9月 17, 2020
作者:
S
SunAhong1993
提交者:
GitHub
9月 17, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7 from PaddlePaddle/develop
me
上级
bb7cd6b9
09d35587
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
10090 addition
and
13500 deletion
+10090
-13500
README.md
README.md
+2
-2
op_list.md
op_list.md
+19
-15
x2paddle/__init__.py
x2paddle/__init__.py
+1
-1
x2paddle/convert.py
x2paddle/convert.py
+9
-8
x2paddle/decoder/caffe.proto
x2paddle/decoder/caffe.proto
+1947
-0
x2paddle/decoder/caffe_pb2.py
x2paddle/decoder/caffe_pb2.py
+7684
-13342
x2paddle/decoder/onnx_shape_inference.py
x2paddle/decoder/onnx_shape_inference.py
+3
-3
x2paddle/op_mapper/caffe_custom_layer/normalize.py
x2paddle/op_mapper/caffe_custom_layer/normalize.py
+1
-1
x2paddle/op_mapper/caffe_op_mapper.py
x2paddle/op_mapper/caffe_op_mapper.py
+1
-1
x2paddle/op_mapper/onnx2paddle/opset9/opset.py
x2paddle/op_mapper/onnx2paddle/opset9/opset.py
+221
-76
x2paddle/op_mapper/paddle2onnx/opset11/opset.py
x2paddle/op_mapper/paddle2onnx/opset11/opset.py
+12
-20
x2paddle/op_mapper/paddle2onnx/opset11/paddle_custom_layer/multiclass_nms.py
...paddle2onnx/opset11/paddle_custom_layer/multiclass_nms.py
+4
-2
x2paddle/op_mapper/paddle2onnx/opset9/opset.py
x2paddle/op_mapper/paddle2onnx/opset9/opset.py
+141
-14
x2paddle/op_mapper/paddle2onnx/opset9/paddle_custom_layer/multiclass_nms.py
.../paddle2onnx/opset9/paddle_custom_layer/multiclass_nms.py
+4
-2
x2paddle/op_mapper/tf_op_mapper_nhwc.py
x2paddle/op_mapper/tf_op_mapper_nhwc.py
+30
-8
x2paddle/optimizer/tf_optimizer.py
x2paddle/optimizer/tf_optimizer.py
+3
-0
x2paddle_model_zoo.md
x2paddle_model_zoo.md
+8
-5
未找到文件。
README.md
浏览文件 @
ce6ffee2
...
...
@@ -15,7 +15,7 @@ paddlepaddle >= 1.8.0
**按需安装以下依赖**
tensorflow : tensorflow == 1.14.0
caffe : 无
onnx : onnx
=
= 1.6.0
onnx : onnx
>
= 1.6.0
## 安装
### 安装方式一(推荐)
...
...
@@ -58,7 +58,7 @@ x2paddle --framework=paddle2onnx --model=paddle_infer_model_dir --save_dir=onnx_
|--save_dir | 指定转换后的模型保存目录路径 |
|--model | 当framework为tensorflow/onnx时,该参数指定tensorflow的pb模型文件或onnx模型路径 |
|--caffe_proto |
**[可选]**
由caffe.proto编译成caffe_pb2.py文件的存放路径,当存在自定义Layer时使用,默认为None |
|--without_data_format_optimization |
**[可选]**
For TensorFlow, 当指定该参数
时,关闭NHWC->NCHW的优化,见
[
文档Q2
](
FAQ.md
)
|
|--without_data_format_optimization |
**[可选]**
For TensorFlow, 当指定该参数
为False时,打开NHWC->NCHW的优化,见
[
文档Q2
](
FAQ.md
)
,默认为True
|
|--define_input_shape |
**[可选]**
For TensorFlow, 当指定该参数时,强制用户输入每个Placeholder的shape,见
[
文档Q2
](
FAQ.md
)
|
|--params_merge |
**[可选]**
当指定该参数时,转换完成后,inference_model中的所有模型参数将合并保存为一个文件__params__ |
|--onnx_opset |
**[可选]**
当framework为paddle2onnx时,该参数可设置转换为ONNX的OpSet版本,目前支持9、10、11,默认为10 |
...
...
op_list.md
浏览文件 @
ce6ffee2
# X2Paddle支持OP列表
> 目前X2Paddle支持
5
0+的TensorFlow OP,30+的Caffe Layer,覆盖了大部分CV分类模型常用的操作。我们在如下列表中给出了目前X2Paddle支持的全部OP。
> 目前X2Paddle支持
7
0+的TensorFlow OP,30+的Caffe Layer,覆盖了大部分CV分类模型常用的操作。我们在如下列表中给出了目前X2Paddle支持的全部OP。
**注:**
目前,部分OP暂未支持,如您在转换过程中出现OP不支持的情况,可自行添加或反馈给我们。欢迎通过
[
ISSUE反馈
](
https://github.com/PaddlePaddle/X2Paddle/issues/new
)
的方式告知我们(模型名,代码实现或模型获取方式),我们会及时跟进:)
...
...
@@ -7,20 +7,24 @@
| 序号 | OP | 序号 | OP | 序号 | OP | 序号 | OP |
|------|------|------|------|------|------|------|------|
| 1 | Relu | 2 | Relu6 | 3 | Shape | 4 | Abs |
| 5 | Sigmoid | 6 | Exp | 7 | Rsqrt | 8 | swish_f32 |
| 9 | Tanh | 10 | LeakyRelu | 11 | Add | 12 | RealDiv |
| 13 | Sub | 14 | Maximum | 15 | Mul | 16 | FloorDiv |
| 17 | Placeholder | 18 | Const | 19 | Transpose | 20 | FusedBatchNorm |
| 21 | Conv2D | 22 | BiasAdd | 23 | MaxPool | 24 | DepthwiseConv2dNative |
| 25 | Reshape | 26 | AvgPool | 27 | SplitV | 28 | SquaredDifference |
| 29 | Tile | 30 | Pack | 31 | Pad | 32 | ResizeBilinear |
| 33 | Mean | 34 | MatMul | 35 | ArgMax | 36 | StridedSlice |
| 37 | Slice | 38 | Sum | 39 | Max | 40 | Conv2DBackpropInput |
| 41 | Cast | 42 | Split | 43 | Squeeze | 44 | ResizeNearestNeighbor |
| 45 | Softmax | 46 | Range | 47 | ConcatV2 | 48 | MirrorPad |
| 49 | Identity | 50 | GreaterEqual | 51 | StopGradient | 52 | Minimum |
| 53 | RadnomUniform | 54 | Fill | 55 | Floor | 56 | DepthToSpace |
| 1 | Relu | 2 | Relu6 | 3 | Shape | 4 | Abs |
| 5 | Sigmoid | 6 | Exp | 7 | Rsqrt | 8 | swish_f32 |
| 9 | Tanh | 10 | LeakyRelu | 11 | Add | 12 | RealDiv |
| 13 | Sub | 14 | Maximum | 15 | Mul | 16 | FloorDiv |
| 17 | Placeholder | 18 | Const | 19 | Transpose | 20 | FusedBatchNorm |
| 21 | Conv2D | 22 | BiasAdd | 23 | MaxPool | 24 | DepthwiseConv2dNative |
| 25 | Reshape | 26 | AvgPool | 27 | SplitV | 28 | SquaredDifference |
| 29 | Tile | 30 | Pack | 31 | Pad | 32 | ResizeBilinear |
| 33 | Mean | 34 | MatMul | 35 | ArgMax | 36 | StridedSlice |
| 37 | Slice | 38 | Sum | 39 | Max | 40 | Conv2DBackpropInput |
| 41 | Cast | 42 | Split | 43 | Squeeze | 44 | ResizeNearestNeighbor |
| 45 | Softmax | 46 | Range | 47 | ConcatV2 | 48 | MirrorPad |
| 49 | Identity | 50 | GreaterEqual | 51 | StopGradient | 52 | Minimum |
| 53 | RadnomUniform | 54 | Fill | 55 | Floor | 56 | DepthToSpace |
| 57 | Sqrt | 58 | Softplus | 59 | Erf | 60 | AddV2 |
| 61 | LessEqual | 62 | BatchMatMul | 63 | BatchMatMulV2 | 64 | ExpandDims |
| 65 | BatchToSpaceND | 66 | SpaceToBatchND | 67 | OneHot | 68 | Pow |
| 69 | All | 70 | GatherV2 | 71 | IteratorV2 | | |
## Caffe
...
...
x2paddle/__init__.py
浏览文件 @
ce6ffee2
__version__
=
"0.8.
1
"
__version__
=
"0.8.
4
"
from
.core.program
import
PaddleProgram
...
...
x2paddle/convert.py
浏览文件 @
ce6ffee2
...
...
@@ -66,8 +66,8 @@ def arg_parser():
parser
.
add_argument
(
"--without_data_format_optimization"
,
"-wo"
,
action
=
"store_true"
,
default
=
False
,
type
=
_text_type
,
default
=
"True"
,
help
=
"tf model conversion without data format optimization"
)
parser
.
add_argument
(
"--define_input_shape"
,
...
...
@@ -93,7 +93,7 @@ def arg_parser():
def
tf2paddle
(
model_path
,
save_dir
,
without_data_format_optimization
=
False
,
without_data_format_optimization
,
define_input_shape
=
False
,
params_merge
=
False
):
# check tensorflow installation and version
...
...
@@ -170,8 +170,8 @@ def onnx2paddle(model_path, save_dir, params_merge=False):
try
:
import
onnx
version
=
onnx
.
version
.
version
if
version
!=
'1.6.0'
:
print
(
"[ERROR] onnx
=
=1.6.0 is required"
)
if
version
<
'1.6.0'
:
print
(
"[ERROR] onnx
>
=1.6.0 is required"
)
return
except
:
print
(
"[ERROR] onnx is not installed, use
\"
pip install onnx==1.6.0
\"
."
)
...
...
@@ -240,11 +240,12 @@ def main():
if
args
.
framework
==
"tensorflow"
:
assert
args
.
model
is
not
None
,
"--model should be defined while translating tensorflow model"
without_data_format_optimization
=
False
assert
args
.
without_data_format_optimization
in
[
"True"
,
"False"
],
"--the param without_data_format_optimization should be defined True or False"
define_input_shape
=
False
params_merge
=
False
if
args
.
without_data_format_optimization
:
without_data_format_optimization
=
True
without_data_format_optimization
=
True
if
args
.
without_data_format_optimization
==
"True"
else
False
if
args
.
define_input_shape
:
define_input_shape
=
True
if
args
.
params_merge
:
...
...
x2paddle/decoder/caffe.proto
0 → 100644
浏览文件 @
ce6ffee2
syntax
=
"proto2"
;
package
caffe
;
// Specifies the shape (dimensions) of a Blob.
message
BlobShape
{
repeated
int64
dim
=
1
[
packed
=
true
];
}
message
BlobProto
{
optional
BlobShape
shape
=
7
;
repeated
float
data
=
5
[
packed
=
true
];
repeated
float
diff
=
6
[
packed
=
true
];
repeated
double
double_data
=
8
[
packed
=
true
];
repeated
double
double_diff
=
9
[
packed
=
true
];
// 4D dimensions -- deprecated. Use "shape" instead.
optional
int32
num
=
1
[
default
=
0
];
optional
int32
channels
=
2
[
default
=
0
];
optional
int32
height
=
3
[
default
=
0
];
optional
int32
width
=
4
[
default
=
0
];
}
// The BlobProtoVector is simply a way to pass multiple blobproto instances
// around.
message
BlobProtoVector
{
repeated
BlobProto
blobs
=
1
;
}
message
Datum
{
optional
int32
channels
=
1
;
optional
int32
height
=
2
;
optional
int32
width
=
3
;
// the actual image data, in bytes
optional
bytes
data
=
4
;
optional
int32
label
=
5
;
// Optionally, the datum could also hold float data.
repeated
float
float_data
=
6
;
// If true data contains an encoded image that need to be decoded
optional
bool
encoded
=
7
[
default
=
false
];
}
// The label (display) name and label id.
message
LabelMapItem
{
// Both name and label are required.
optional
string
name
=
1
;
optional
int32
label
=
2
;
// display_name is optional.
optional
string
display_name
=
3
;
}
message
LabelMap
{
repeated
LabelMapItem
item
=
1
;
}
// Sample a bbox in the normalized space [0, 1] with provided constraints.
message
Sampler
{
// Minimum scale of the sampled bbox.
optional
float
min_scale
=
1
[
default
=
1.
];
// Maximum scale of the sampled bbox.
optional
float
max_scale
=
2
[
default
=
1.
];
// Minimum aspect ratio of the sampled bbox.
optional
float
min_aspect_ratio
=
3
[
default
=
1.
];
// Maximum aspect ratio of the sampled bbox.
optional
float
max_aspect_ratio
=
4
[
default
=
1.
];
}
// Constraints for selecting sampled bbox.
message
SampleConstraint
{
// Minimum Jaccard overlap between sampled bbox and all bboxes in
// AnnotationGroup.
optional
float
min_jaccard_overlap
=
1
;
// Maximum Jaccard overlap between sampled bbox and all bboxes in
// AnnotationGroup.
optional
float
max_jaccard_overlap
=
2
;
// Minimum coverage of sampled bbox by all bboxes in AnnotationGroup.
optional
float
min_sample_coverage
=
3
;
// Maximum coverage of sampled bbox by all bboxes in AnnotationGroup.
optional
float
max_sample_coverage
=
4
;
// Minimum coverage of all bboxes in AnnotationGroup by sampled bbox.
optional
float
min_object_coverage
=
5
;
// Maximum coverage of all bboxes in AnnotationGroup by sampled bbox.
optional
float
max_object_coverage
=
6
;
}
// Sample a batch of bboxes with provided constraints.
message
BatchSampler
{
// Use original image as the source for sampling.
optional
bool
use_original_image
=
1
[
default
=
true
];
// Constraints for sampling bbox.
optional
Sampler
sampler
=
2
;
// Constraints for determining if a sampled bbox is positive or negative.
optional
SampleConstraint
sample_constraint
=
3
;
// If provided, break when found certain number of samples satisfing the
// sample_constraint.
optional
uint32
max_sample
=
4
;
// Maximum number of trials for sampling to avoid infinite loop.
optional
uint32
max_trials
=
5
[
default
=
100
];
}
// Condition for emitting annotations.
message
EmitConstraint
{
enum
EmitType
{
CENTER
=
0
;
MIN_OVERLAP
=
1
;
}
optional
EmitType
emit_type
=
1
[
default
=
CENTER
];
// If emit_type is MIN_OVERLAP, provide the emit_overlap.
optional
float
emit_overlap
=
2
;
}
// The normalized bounding box [0, 1] w.r.t. the input image size.
message
NormalizedBBox
{
optional
float
xmin
=
1
;
optional
float
ymin
=
2
;
optional
float
xmax
=
3
;
optional
float
ymax
=
4
;
optional
int32
label
=
5
;
optional
bool
difficult
=
6
;
optional
float
score
=
7
;
optional
float
size
=
8
;
}
// Annotation for each object instance.
message
Annotation
{
optional
int32
instance_id
=
1
[
default
=
0
];
optional
NormalizedBBox
bbox
=
2
;
}
// Group of annotations for a particular label.
message
AnnotationGroup
{
optional
int32
group_label
=
1
;
repeated
Annotation
annotation
=
2
;
}
// An extension of Datum which contains "rich" annotations.
message
AnnotatedDatum
{
enum
AnnotationType
{
BBOX
=
0
;
}
optional
Datum
datum
=
1
;
// If there are "rich" annotations, specify the type of annotation.
// Currently it only supports bounding box.
// If there are no "rich" annotations, use label in datum instead.
optional
AnnotationType
type
=
2
;
// Each group contains annotation for a particular class.
repeated
AnnotationGroup
annotation_group
=
3
;
}
message
FillerParameter
{
// The filler type.
optional
string
type
=
1
[
default
=
'constant'
];
optional
float
value
=
2
[
default
=
0
];
// the value in constant filler
optional
float
min
=
3
[
default
=
0
];
// the min value in uniform filler
optional
float
max
=
4
[
default
=
1
];
// the max value in uniform filler
optional
float
mean
=
5
[
default
=
0
];
// the mean value in Gaussian filler
optional
float
std
=
6
[
default
=
1
];
// the std value in Gaussian filler
// The expected number of non-zero output weights for a given input in
// Gaussian filler -- the default -1 means don't perform sparsification.
optional
int32
sparse
=
7
[
default
=
-
1
];
// Normalize the filler variance by fan_in, fan_out, or their average.
// Applies to 'xavier' and 'msra' fillers.
enum
VarianceNorm
{
FAN_IN
=
0
;
FAN_OUT
=
1
;
AVERAGE
=
2
;
}
optional
VarianceNorm
variance_norm
=
8
[
default
=
FAN_IN
];
}
message
NetParameter
{
optional
string
name
=
1
;
// consider giving the network a name
// DEPRECATED. See InputParameter. The input blobs to the network.
repeated
string
input
=
3
;
// DEPRECATED. See InputParameter. The shape of the input blobs.
repeated
BlobShape
input_shape
=
8
;
// 4D input dimensions -- deprecated. Use "input_shape" instead.
// If specified, for each input blob there should be four
// values specifying the num, channels, height and width of the input blob.
// Thus, there should be a total of (4 * #input) numbers.
repeated
int32
input_dim
=
4
;
// Whether the network will force every layer to carry out backward operation.
// If set False, then whether to carry out backward is determined
// automatically according to the net structure and learning rates.
optional
bool
force_backward
=
5
[
default
=
false
];
// The current "state" of the network, including the phase, level, and stage.
// Some layers may be included/excluded depending on this state and the states
// specified in the layers' include and exclude fields.
optional
NetState
state
=
6
;
// Print debugging information about results while running Net::Forward,
// Net::Backward, and Net::Update.
optional
bool
debug_info
=
7
[
default
=
false
];
// The layers that make up the net. Each of their configurations, including
// connectivity and behavior, is specified as a LayerParameter.
repeated
LayerParameter
layer
=
100
;
// ID 100 so layers are printed last.
// DEPRECATED: use 'layer' instead.
repeated
V1LayerParameter
layers
=
2
;
}
// NOTE
// Update the next available ID when you add a new SolverParameter field.
//
// SolverParameter next available ID: 44 (last added: plateau_winsize)
message
SolverParameter
{
//////////////////////////////////////////////////////////////////////////////
// Specifying the train and test networks
//
// Exactly one train net must be specified using one of the following fields:
// train_net_param, train_net, net_param, net
// One or more test nets may be specified using any of the following fields:
// test_net_param, test_net, net_param, net
// If more than one test net field is specified (e.g., both net and
// test_net are specified), they will be evaluated in the field order given
// above: (1) test_net_param, (2) test_net, (3) net_param/net.
// A test_iter must be specified for each test_net.
// A test_level and/or a test_stage may also be specified for each test_net.
//////////////////////////////////////////////////////////////////////////////
// Proto filename for the train net, possibly combined with one or more
// test nets.
optional
string
net
=
24
;
// Inline train net param, possibly combined with one or more test nets.
optional
NetParameter
net_param
=
25
;
optional
string
train_net
=
1
;
// Proto filename for the train net.
repeated
string
test_net
=
2
;
// Proto filenames for the test nets.
optional
NetParameter
train_net_param
=
21
;
// Inline train net params.
repeated
NetParameter
test_net_param
=
22
;
// Inline test net params.
// The states for the train/test nets. Must be unspecified or
// specified once per net.
//
// By default, all states will have solver = true;
// train_state will have phase = TRAIN,
// and all test_state's will have phase = TEST.
// Other defaults are set according to the NetState defaults.
optional
NetState
train_state
=
26
;
repeated
NetState
test_state
=
27
;
// Evaluation type.
optional
string
eval_type
=
41
[
default
=
"classification"
];
// ap_version: different ways of computing Average Precision.
// Check https://sanchom.wordpress.com/tag/average-precision/ for details.
// 11point: the 11-point interpolated average precision. Used in VOC2007.
// MaxIntegral: maximally interpolated AP. Used in VOC2012/ILSVRC.
// Integral: the natural integral of the precision-recall curve.
optional
string
ap_version
=
42
[
default
=
"Integral"
];
// If true, display per class result.
optional
bool
show_per_class_result
=
44
[
default
=
false
];
// The number of iterations for each test net.
repeated
int32
test_iter
=
3
;
// The number of iterations between two testing phases.
optional
int32
test_interval
=
4
[
default
=
0
];
optional
bool
test_compute_loss
=
19
[
default
=
false
];
// If true, run an initial test pass before the first iteration,
// ensuring memory availability and printing the starting value of the loss.
optional
bool
test_initialization
=
32
[
default
=
true
];
optional
float
base_lr
=
5
;
// The base learning rate
// the number of iterations between displaying info. If display = 0, no info
// will be displayed.
optional
int32
display
=
6
;
// Display the loss averaged over the last average_loss iterations
optional
int32
average_loss
=
33
[
default
=
1
];
optional
int32
max_iter
=
7
;
// the maximum number of iterations
// accumulate gradients over `iter_size` x `batch_size` instances
optional
int32
iter_size
=
36
[
default
=
1
];
// The learning rate decay policy. The currently implemented learning rate
// policies are as follows:
// - fixed: always return base_lr.
// - step: return base_lr * gamma ^ (floor(iter / step))
// - exp: return base_lr * gamma ^ iter
// - inv: return base_lr * (1 + gamma * iter) ^ (- power)
// - multistep: similar to step but it allows non uniform steps defined by
// stepvalue
// - poly: the effective learning rate follows a polynomial decay, to be
// zero by the max_iter. return base_lr (1 - iter/max_iter) ^ (power)
// - sigmoid: the effective learning rate follows a sigmod decay
// return base_lr ( 1/(1 + exp(-gamma * (iter - stepsize))))
// - plateau: decreases lr
// if the minimum loss isn't updated for 'plateau_winsize' iters
//
// where base_lr, max_iter, gamma, step, stepvalue and power are defined
// in the solver parameter protocol buffer, and iter is the current iteration.
optional
string
lr_policy
=
8
;
optional
float
gamma
=
9
;
// The parameter to compute the learning rate.
optional
float
power
=
10
;
// The parameter to compute the learning rate.
optional
float
momentum
=
11
;
// The momentum value.
optional
float
weight_decay
=
12
;
// The weight decay.
// regularization types supported: L1 and L2
// controlled by weight_decay
optional
string
regularization_type
=
29
[
default
=
"L2"
];
// the stepsize for learning rate policy "step"
optional
int32
stepsize
=
13
;
// the stepsize for learning rate policy "multistep"
repeated
int32
stepvalue
=
34
;
// the stepsize for learning rate policy "plateau"
repeated
int32
plateau_winsize
=
43
;
// Set clip_gradients to >= 0 to clip parameter gradients to that L2 norm,
// whenever their actual L2 norm is larger.
optional
float
clip_gradients
=
35
[
default
=
-
1
];
optional
int32
snapshot
=
14
[
default
=
0
];
// The snapshot interval
optional
string
snapshot_prefix
=
15
;
// The prefix for the snapshot.
// whether to snapshot diff in the results or not. Snapshotting diff will help
// debugging but the final protocol buffer size will be much larger.
optional
bool
snapshot_diff
=
16
[
default
=
false
];
enum
SnapshotFormat
{
HDF5
=
0
;
BINARYPROTO
=
1
;
}
optional
SnapshotFormat
snapshot_format
=
37
[
default
=
BINARYPROTO
];
// the mode solver will use: 0 for CPU and 1 for GPU. Use GPU in default.
enum
SolverMode
{
CPU
=
0
;
GPU
=
1
;
}
optional
SolverMode
solver_mode
=
17
[
default
=
GPU
];
// the device_id will that be used in GPU mode. Use device_id = 0 in default.
optional
int32
device_id
=
18
[
default
=
0
];
// If non-negative, the seed with which the Solver will initialize the Caffe
// random number generator -- useful for reproducible results. Otherwise,
// (and by default) initialize using a seed derived from the system clock.
optional
int64
random_seed
=
20
[
default
=
-
1
];
// type of the solver
optional
string
type
=
40
[
default
=
"SGD"
];
// numerical stability for RMSProp, AdaGrad and AdaDelta and Adam
optional
float
delta
=
31
[
default
=
1e-8
];
// parameters for the Adam solver
optional
float
momentum2
=
39
[
default
=
0.999
];
// RMSProp decay value
// MeanSquare(t) = rms_decay*MeanSquare(t-1) + (1-rms_decay)*SquareGradient(t)
optional
float
rms_decay
=
38
[
default
=
0.99
];
// If true, print information about the state of the net that may help with
// debugging learning problems.
optional
bool
debug_info
=
23
[
default
=
false
];
// If false, don't save a snapshot after training finishes.
optional
bool
snapshot_after_train
=
28
[
default
=
true
];
// DEPRECATED: old solver enum types, use string instead
enum
SolverType
{
SGD
=
0
;
NESTEROV
=
1
;
ADAGRAD
=
2
;
RMSPROP
=
3
;
ADADELTA
=
4
;
ADAM
=
5
;
}
// DEPRECATED: use type instead of solver_type
optional
SolverType
solver_type
=
30
[
default
=
SGD
];
}
// A message that stores the solver snapshots
message
SolverState
{
optional
int32
iter
=
1
;
// The current iteration
optional
string
learned_net
=
2
;
// The file that stores the learned net.
repeated
BlobProto
history
=
3
;
// The history for sgd solvers
optional
int32
current_step
=
4
[
default
=
0
];
// The current step for learning rate
optional
float
minimum_loss
=
5
[
default
=
1E38
];
// Historical minimum loss
optional
int32
iter_last_event
=
6
[
default
=
0
];
// The iteration when last lr-update or min_loss-update happend
}
enum
Phase
{
TRAIN
=
0
;
TEST
=
1
;
}
message
NetState
{
optional
Phase
phase
=
1
[
default
=
TEST
];
optional
int32
level
=
2
[
default
=
0
];
repeated
string
stage
=
3
;
}
message
NetStateRule
{
// Set phase to require the NetState have a particular phase (TRAIN or TEST)
// to meet this rule.
optional
Phase
phase
=
1
;
// Set the minimum and/or maximum levels in which the layer should be used.
// Leave undefined to meet the rule regardless of level.
optional
int32
min_level
=
2
;
optional
int32
max_level
=
3
;
// Customizable sets of stages to include or exclude.
// The net must have ALL of the specified stages and NONE of the specified
// "not_stage"s to meet the rule.
// (Use multiple NetStateRules to specify conjunctions of stages.)
repeated
string
stage
=
4
;
repeated
string
not_stage
=
5
;
}
// Specifies training parameters (multipliers on global learning constants,
// and the name and other settings used for weight sharing).
message
ParamSpec
{
// The names of the parameter blobs -- useful for sharing parameters among
// layers, but never required otherwise. To share a parameter between two
// layers, give it a (non-empty) name.
optional
string
name
=
1
;
// Whether to require shared weights to have the same shape, or just the same
// count -- defaults to STRICT if unspecified.
optional
DimCheckMode
share_mode
=
2
;
enum
DimCheckMode
{
// STRICT (default) requires that num, channels, height, width each match.
STRICT
=
0
;
// PERMISSIVE requires only the count (num*channels*height*width) to match.
PERMISSIVE
=
1
;
}
// The multiplier on the global learning rate for this parameter.
optional
float
lr_mult
=
3
[
default
=
1.0
];
// The multiplier on the global weight decay for this parameter.
optional
float
decay_mult
=
4
[
default
=
1.0
];
}
// NOTE
// Update the next available ID when you add a new LayerParameter field.
//
// LayerParameter next available layer-specific ID: 147 (last added: recurrent_param)
message
LayerParameter
{
optional
string
name
=
1
;
// the layer name
optional
string
type
=
2
;
// the layer type
repeated
string
bottom
=
3
;
// the name of each bottom blob
repeated
string
top
=
4
;
// the name of each top blob
// The train / test phase for computation.
optional
Phase
phase
=
10
;
// The amount of weight to assign each top blob in the objective.
// Each layer assigns a default value, usually of either 0 or 1,
// to each top blob.
repeated
float
loss_weight
=
5
;
// Specifies training parameters (multipliers on global learning constants,
// and the name and other settings used for weight sharing).
repeated
ParamSpec
param
=
6
;
// The blobs containing the numeric parameters of the layer.
repeated
BlobProto
blobs
=
7
;
// Specifies whether to backpropagate to each bottom. If unspecified,
// Caffe will automatically infer whether each input needs backpropagation
// to compute parameter gradients. If set to true for some inputs,
// backpropagation to those inputs is forced; if set false for some inputs,
// backpropagation to those inputs is skipped.
//
// The size must be either 0 or equal to the number of bottoms.
repeated
bool
propagate_down
=
11
;
// Rules controlling whether and when a layer is included in the network,
// based on the current NetState. You may specify a non-zero number of rules
// to include OR exclude, but not both. If no include or exclude rules are
// specified, the layer is always included. If the current NetState meets
// ANY (i.e., one or more) of the specified rules, the layer is
// included/excluded.
repeated
NetStateRule
include
=
8
;
repeated
NetStateRule
exclude
=
9
;
// Parameters for data pre-processing.
optional
TransformationParameter
transform_param
=
100
;
// Parameters shared by loss layers.
optional
LossParameter
loss_param
=
101
;
// Layer type-specific parameters.
//
// Note: certain layers may have more than one computational engine
// for their implementation. These layers include an Engine type and
// engine parameter for selecting the implementation.
// The default for the engine is set by the ENGINE switch at compile-time.
optional
AccuracyParameter
accuracy_param
=
102
;
optional
AnnotatedDataParameter
annotated_data_param
=
200
;
optional
ArgMaxParameter
argmax_param
=
103
;
optional
BatchNormParameter
batch_norm_param
=
139
;
optional
BiasParameter
bias_param
=
141
;
optional
ConcatParameter
concat_param
=
104
;
optional
ContrastiveLossParameter
contrastive_loss_param
=
105
;
optional
ConvolutionParameter
convolution_param
=
106
;
optional
CropParameter
crop_param
=
144
;
optional
DataParameter
data_param
=
107
;
optional
DetectionEvaluateParameter
detection_evaluate_param
=
205
;
optional
DetectionOutputParameter
detection_output_param
=
204
;
optional
DropoutParameter
dropout_param
=
108
;
optional
DummyDataParameter
dummy_data_param
=
109
;
optional
EltwiseParameter
eltwise_param
=
110
;
optional
ELUParameter
elu_param
=
140
;
optional
EmbedParameter
embed_param
=
137
;
optional
ExpParameter
exp_param
=
111
;
optional
FlattenParameter
flatten_param
=
135
;
optional
HDF5DataParameter
hdf5_data_param
=
112
;
optional
HDF5OutputParameter
hdf5_output_param
=
113
;
optional
HingeLossParameter
hinge_loss_param
=
114
;
optional
ImageDataParameter
image_data_param
=
115
;
optional
InfogainLossParameter
infogain_loss_param
=
116
;
optional
InnerProductParameter
inner_product_param
=
117
;
optional
InputParameter
input_param
=
143
;
optional
LogParameter
log_param
=
134
;
optional
LRNParameter
lrn_param
=
118
;
optional
MemoryDataParameter
memory_data_param
=
119
;
optional
MultiBoxLossParameter
multibox_loss_param
=
201
;
optional
MVNParameter
mvn_param
=
120
;
optional
NormalizeParameter
norm_param
=
206
;
optional
ParameterParameter
parameter_param
=
145
;
optional
PermuteParameter
permute_param
=
202
;
optional
PoolingParameter
pooling_param
=
121
;
optional
PowerParameter
power_param
=
122
;
optional
PReLUParameter
prelu_param
=
131
;
optional
PriorBoxParameter
prior_box_param
=
203
;
optional
PythonParameter
python_param
=
130
;
optional
RecurrentParameter
recurrent_param
=
146
;
optional
ReductionParameter
reduction_param
=
136
;
optional
ReLUParameter
relu_param
=
123
;
optional
ReshapeParameter
reshape_param
=
133
;
optional
ScaleParameter
scale_param
=
142
;
optional
SigmoidParameter
sigmoid_param
=
124
;
optional
SoftmaxParameter
softmax_param
=
125
;
optional
SPPParameter
spp_param
=
132
;
optional
SliceParameter
slice_param
=
126
;
optional
TanHParameter
tanh_param
=
127
;
optional
ThresholdParameter
threshold_param
=
128
;
optional
TileParameter
tile_param
=
138
;
optional
VideoDataParameter
video_data_param
=
207
;
optional
WindowDataParameter
window_data_param
=
129
;
optional
AxpyParameter
axpy_param
=
210
;
optional
UpsampleParameter
upsample_param
=
211
;
optional
ROIPoolingParameter
roi_pooling_param
=
212
;
optional
ShuffleChannelParameter
shuffle_channel_param
=
213
;
}
// Message that stores parameters used to apply transformation
// to the data layer's data
message
TransformationParameter
{
// For data pre-processing, we can do simple scaling and subtracting the
// data mean, if provided. Note that the mean subtraction is always carried
// out before scaling.
optional
float
scale
=
1
[
default
=
1
];
// Specify if we want to randomly mirror data.
optional
bool
mirror
=
2
[
default
=
false
];
// Specify if we would like to randomly crop an image.
optional
uint32
crop_size
=
3
[
default
=
0
];
optional
uint32
crop_h
=
11
[
default
=
0
];
optional
uint32
crop_w
=
12
[
default
=
0
];
// mean_file and mean_value cannot be specified at the same time
optional
string
mean_file
=
4
;
// if specified can be repeated once (would substract it from all the channels)
// or can be repeated the same number of times as channels
// (would subtract them from the corresponding channel)
repeated
float
mean_value
=
5
;
// Force the decoded image to have 3 color channels.
optional
bool
force_color
=
6
[
default
=
false
];
// Force the decoded image to have 1 color channels.
optional
bool
force_gray
=
7
[
default
=
false
];
// Resize policy
optional
ResizeParameter
resize_param
=
8
;
// Noise policy
optional
NoiseParameter
noise_param
=
9
;
// Distortion policy
optional
DistortionParameter
distort_param
=
13
;
// Expand policy
optional
ExpansionParameter
expand_param
=
14
;
// Constraint for emitting the annotation after transformation.
optional
EmitConstraint
emit_constraint
=
10
;
}
// Message that stores parameters used by data transformer for resize policy
message
ResizeParameter
{
//Probability of using this resize policy
optional
float
prob
=
1
[
default
=
1
];
enum
Resize_mode
{
WARP
=
1
;
FIT_SMALL_SIZE
=
2
;
FIT_LARGE_SIZE_AND_PAD
=
3
;
}
optional
Resize_mode
resize_mode
=
2
[
default
=
WARP
];
optional
uint32
height
=
3
[
default
=
0
];
optional
uint32
width
=
4
[
default
=
0
];
// A parameter used to update bbox in FIT_SMALL_SIZE mode.
optional
uint32
height_scale
=
8
[
default
=
0
];
optional
uint32
width_scale
=
9
[
default
=
0
];
enum
Pad_mode
{
CONSTANT
=
1
;
MIRRORED
=
2
;
REPEAT_NEAREST
=
3
;
}
// Padding mode for BE_SMALL_SIZE_AND_PAD mode and object centering
optional
Pad_mode
pad_mode
=
5
[
default
=
CONSTANT
];
// if specified can be repeated once (would fill all the channels)
// or can be repeated the same number of times as channels
// (would use it them to the corresponding channel)
repeated
float
pad_value
=
6
;
enum
Interp_mode
{
//Same as in OpenCV
LINEAR
=
1
;
AREA
=
2
;
NEAREST
=
3
;
CUBIC
=
4
;
LANCZOS4
=
5
;
}
//interpolation for for resizing
repeated
Interp_mode
interp_mode
=
7
;
}
message
SaltPepperParameter
{
//Percentage of pixels
optional
float
fraction
=
1
[
default
=
0
];
repeated
float
value
=
2
;
}
// Message that stores parameters used by data transformer for transformation
// policy
message
NoiseParameter
{
//Probability of using this resize policy
optional
float
prob
=
1
[
default
=
0
];
// Histogram equalized
optional
bool
hist_eq
=
2
[
default
=
false
];
// Color inversion
optional
bool
inverse
=
3
[
default
=
false
];
// Grayscale
optional
bool
decolorize
=
4
[
default
=
false
];
// Gaussian blur
optional
bool
gauss_blur
=
5
[
default
=
false
];
// JPEG compression quality (-1 = no compression)
optional
float
jpeg
=
6
[
default
=
-
1
];
// Posterization
optional
bool
posterize
=
7
[
default
=
false
];
// Erosion
optional
bool
erode
=
8
[
default
=
false
];
// Salt-and-pepper noise
optional
bool
saltpepper
=
9
[
default
=
false
];
optional
SaltPepperParameter
saltpepper_param
=
10
;
// Local histogram equalization
optional
bool
clahe
=
11
[
default
=
false
];
// Color space conversion
optional
bool
convert_to_hsv
=
12
[
default
=
false
];
// Color space conversion
optional
bool
convert_to_lab
=
13
[
default
=
false
];
}
// Message that stores parameters used by data transformer for distortion policy
message
DistortionParameter
{
// The probability of adjusting brightness.
optional
float
brightness_prob
=
1
[
default
=
0.0
];
// Amount to add to the pixel values within [-delta, delta].
// The possible value is within [0, 255]. Recommend 32.
optional
float
brightness_delta
=
2
[
default
=
0.0
];
// The probability of adjusting contrast.
optional
float
contrast_prob
=
3
[
default
=
0.0
];
// Lower bound for random contrast factor. Recommend 0.5.
optional
float
contrast_lower
=
4
[
default
=
0.0
];
// Upper bound for random contrast factor. Recommend 1.5.
optional
float
contrast_upper
=
5
[
default
=
0.0
];
// The probability of adjusting hue.
optional
float
hue_prob
=
6
[
default
=
0.0
];
// Amount to add to the hue channel within [-delta, delta].
// The possible value is within [0, 180]. Recommend 36.
optional
float
hue_delta
=
7
[
default
=
0.0
];
// The probability of adjusting saturation.
optional
float
saturation_prob
=
8
[
default
=
0.0
];
// Lower bound for the random saturation factor. Recommend 0.5.
optional
float
saturation_lower
=
9
[
default
=
0.0
];
// Upper bound for the random saturation factor. Recommend 1.5.
optional
float
saturation_upper
=
10
[
default
=
0.0
];
// The probability of randomly order the image channels.
optional
float
random_order_prob
=
11
[
default
=
0.0
];
}
// Message that stores parameters used by data transformer for expansion policy
message
ExpansionParameter
{
//Probability of using this expansion policy
optional
float
prob
=
1
[
default
=
1
];
// The ratio to expand the image.
optional
float
max_expand_ratio
=
2
[
default
=
1.
];
}
// Message that stores parameters shared by loss layers
message
LossParameter
{
// If specified, ignore instances with the given label.
optional
int32
ignore_label
=
1
;
// How to normalize the loss for loss layers that aggregate across batches,
// spatial dimensions, or other dimensions. Currently only implemented in
// SoftmaxWithLoss and SigmoidCrossEntropyLoss layers.
enum
NormalizationMode
{
// Divide by the number of examples in the batch times spatial dimensions.
// Outputs that receive the ignore label will NOT be ignored in computing
// the normalization factor.
FULL
=
0
;
// Divide by the total number of output locations that do not take the
// ignore_label. If ignore_label is not set, this behaves like FULL.
VALID
=
1
;
// Divide by the batch size.
BATCH_SIZE
=
2
;
// Do not normalize the loss.
NONE
=
3
;
}
// For historical reasons, the default normalization for
// SigmoidCrossEntropyLoss is BATCH_SIZE and *not* VALID.
optional
NormalizationMode
normalization
=
3
[
default
=
VALID
];
// Deprecated. Ignored if normalization is specified. If normalization
// is not specified, then setting this to false will be equivalent to
// normalization = BATCH_SIZE to be consistent with previous behavior.
optional
bool
normalize
=
2
;
}
// Messages that store parameters used by individual layer types follow, in
// alphabetical order.
message
AccuracyParameter
{
// When computing accuracy, count as correct by comparing the true label to
// the top k scoring classes. By default, only compare to the top scoring
// class (i.e. argmax).
optional
uint32
top_k
=
1
[
default
=
1
];
// The "label" axis of the prediction blob, whose argmax corresponds to the
// predicted label -- may be negative to index from the end (e.g., -1 for the
// last axis). For example, if axis == 1 and the predictions are
// (N x C x H x W), the label blob is expected to contain N*H*W ground truth
// labels with integer values in {0, 1, ..., C-1}.
optional
int32
axis
=
2
[
default
=
1
];
// If specified, ignore instances with the given label.
optional
int32
ignore_label
=
3
;
}
message
AnnotatedDataParameter
{
// Define the sampler.
repeated
BatchSampler
batch_sampler
=
1
;
// Store label name and label id in LabelMap format.
optional
string
label_map_file
=
2
;
// If provided, it will replace the AnnotationType stored in each
// AnnotatedDatum.
optional
AnnotatedDatum.AnnotationType
anno_type
=
3
;
}
message
ArgMaxParameter
{
// If true produce pairs (argmax, maxval)
optional
bool
out_max_val
=
1
[
default
=
false
];
optional
uint32
top_k
=
2
[
default
=
1
];
// The axis along which to maximise -- may be negative to index from the
// end (e.g., -1 for the last axis).
// By default ArgMaxLayer maximizes over the flattened trailing dimensions
// for each index of the first / num dimension.
optional
int32
axis
=
3
;
}
message
ConcatParameter
{
// The axis along which to concatenate -- may be negative to index from the
// end (e.g., -1 for the last axis). Other axes must have the
// same dimension for all the bottom blobs.
// By default, ConcatLayer concatenates blobs along the "channels" axis (1).
optional
int32
axis
=
2
[
default
=
1
];
// DEPRECATED: alias for "axis" -- does not support negative indexing.
optional
uint32
concat_dim
=
1
[
default
=
1
];
}
message
BatchNormParameter
{
// If false, accumulate global mean/variance values via a moving average. If
// true, use those accumulated values instead of computing mean/variance
// across the batch.
optional
bool
use_global_stats
=
1
;
// How much does the moving average decay each iteration?
optional
float
moving_average_fraction
=
2
[
default
=
.999
];
// Small value to add to the variance estimate so that we don't divide by
// zero.
optional
float
eps
=
3
[
default
=
1e-5
];
}
message
BiasParameter
{
// The first axis of bottom[0] (the first input Blob) along which to apply
// bottom[1] (the second input Blob). May be negative to index from the end
// (e.g., -1 for the last axis).
//
// For example, if bottom[0] is 4D with shape 100x3x40x60, the output
// top[0] will have the same shape, and bottom[1] may have any of the
// following shapes (for the given value of axis):
// (axis == 0 == -4) 100; 100x3; 100x3x40; 100x3x40x60
// (axis == 1 == -3) 3; 3x40; 3x40x60
// (axis == 2 == -2) 40; 40x60
// (axis == 3 == -1) 60
// Furthermore, bottom[1] may have the empty shape (regardless of the value of
// "axis") -- a scalar bias.
optional
int32
axis
=
1
[
default
=
1
];
// (num_axes is ignored unless just one bottom is given and the bias is
// a learned parameter of the layer. Otherwise, num_axes is determined by the
// number of axes by the second bottom.)
// The number of axes of the input (bottom[0]) covered by the bias
// parameter, or -1 to cover all axes of bottom[0] starting from `axis`.
// Set num_axes := 0, to add a zero-axis Blob: a scalar.
optional
int32
num_axes
=
2
[
default
=
1
];
// (filler is ignored unless just one bottom is given and the bias is
// a learned parameter of the layer.)
// The initialization for the learned bias parameter.
// Default is the zero (0) initialization, resulting in the BiasLayer
// initially performing the identity operation.
optional
FillerParameter
filler
=
3
;
}
message
ContrastiveLossParameter
{
// margin for dissimilar pair
optional
float
margin
=
1
[
default
=
1.0
];
// The first implementation of this cost did not exactly match the cost of
// Hadsell et al 2006 -- using (margin - d^2) instead of (margin - d)^2.
// legacy_version = false (the default) uses (margin - d)^2 as proposed in the
// Hadsell paper. New models should probably use this version.
// legacy_version = true uses (margin - d^2). This is kept to support /
// reproduce existing models and results
optional
bool
legacy_version
=
2
[
default
=
false
];
}
message
ConvolutionParameter
{
optional
uint32
num_output
=
1
;
// The number of outputs for the layer
optional
bool
bias_term
=
2
[
default
=
true
];
// whether to have bias terms
// Pad, kernel size, and stride are all given as a single value for equal
// dimensions in all spatial dimensions, or once per spatial dimension.
repeated
uint32
pad
=
3
;
// The padding size; defaults to 0
repeated
uint32
kernel_size
=
4
;
// The kernel size
repeated
uint32
stride
=
6
;
// The stride; defaults to 1
// Factor used to dilate the kernel, (implicitly) zero-filling the resulting
// holes. (Kernel dilation is sometimes referred to by its use in the
// algorithme à trous from Holschneider et al. 1987.)
repeated
uint32
dilation
=
18
;
// The dilation; defaults to 1
// For 2D convolution only, the *_h and *_w versions may also be used to
// specify both spatial dimensions.
optional
uint32
pad_h
=
9
[
default
=
0
];
// The padding height (2D only)
optional
uint32
pad_w
=
10
[
default
=
0
];
// The padding width (2D only)
optional
uint32
kernel_h
=
11
;
// The kernel height (2D only)
optional
uint32
kernel_w
=
12
;
// The kernel width (2D only)
optional
uint32
stride_h
=
13
;
// The stride height (2D only)
optional
uint32
stride_w
=
14
;
// The stride width (2D only)
optional
uint32
group
=
5
[
default
=
1
];
// The group size for group conv
optional
FillerParameter
weight_filler
=
7
;
// The filler for the weight
optional
FillerParameter
bias_filler
=
8
;
// The filler for the bias
enum
Engine
{
DEFAULT
=
0
;
CAFFE
=
1
;
CUDNN
=
2
;
}
optional
Engine
engine
=
15
[
default
=
DEFAULT
];
// The axis to interpret as "channels" when performing convolution.
// Preceding dimensions are treated as independent inputs;
// succeeding dimensions are treated as "spatial".
// With (N, C, H, W) inputs, and axis == 1 (the default), we perform
// N independent 2D convolutions, sliding C-channel (or (C/g)-channels, for
// groups g>1) filters across the spatial axes (H, W) of the input.
// With (N, C, D, H, W) inputs, and axis == 1, we perform
// N independent 3D convolutions, sliding (C/g)-channels
// filters across the spatial axes (D, H, W) of the input.
optional
int32
axis
=
16
[
default
=
1
];
// Whether to force use of the general ND convolution, even if a specific
// implementation for blobs of the appropriate number of spatial dimensions
// is available. (Currently, there is only a 2D-specific convolution
// implementation; for input blobs with num_axes != 2, this option is
// ignored and the ND implementation will be used.)
optional
bool
force_nd_im2col
=
17
[
default
=
false
];
}
message
CropParameter
{
// To crop, elements of the first bottom are selected to fit the dimensions
// of the second, reference bottom. The crop is configured by
// - the crop `axis` to pick the dimensions for cropping
// - the crop `offset` to set the shift for all/each dimension
// to align the cropped bottom with the reference bottom.
// All dimensions up to but excluding `axis` are preserved, while
// the dimensions including and trailing `axis` are cropped.
// If only one `offset` is set, then all dimensions are offset by this amount.
// Otherwise, the number of offsets must equal the number of cropped axes to
// shift the crop in each dimension accordingly.
// Note: standard dimensions are N,C,H,W so the default is a spatial crop,
// and `axis` may be negative to index from the end (e.g., -1 for the last
// axis).
optional
int32
axis
=
1
[
default
=
2
];
repeated
uint32
offset
=
2
;
}
message
DataParameter
{
enum
DB
{
LEVELDB
=
0
;
LMDB
=
1
;
}
// Specify the data source.
optional
string
source
=
1
;
// Specify the batch size.
optional
uint32
batch_size
=
4
;
// The rand_skip variable is for the data layer to skip a few data points
// to avoid all asynchronous sgd clients to start at the same point. The skip
// point would be set as rand_skip * rand(0,1). Note that rand_skip should not
// be larger than the number of keys in the database.
// DEPRECATED. Each solver accesses a different subset of the database.
optional
uint32
rand_skip
=
7
[
default
=
0
];
optional
DB
backend
=
8
[
default
=
LEVELDB
];
// DEPRECATED. See TransformationParameter. For data pre-processing, we can do
// simple scaling and subtracting the data mean, if provided. Note that the
// mean subtraction is always carried out before scaling.
optional
float
scale
=
2
[
default
=
1
];
optional
string
mean_file
=
3
;
// DEPRECATED. See TransformationParameter. Specify if we would like to randomly
// crop an image.
optional
uint32
crop_size
=
5
[
default
=
0
];
// DEPRECATED. See TransformationParameter. Specify if we want to randomly mirror
// data.
optional
bool
mirror
=
6
[
default
=
false
];
// Force the encoded image to have 3 color channels
optional
bool
force_encoded_color
=
9
[
default
=
false
];
// Prefetch queue (Number of batches to prefetch to host memory, increase if
// data access bandwidth varies).
optional
uint32
prefetch
=
10
[
default
=
4
];
}
// Message that store parameters used by DetectionEvaluateLayer
message
DetectionEvaluateParameter
{
// Number of classes that are actually predicted. Required!
optional
uint32
num_classes
=
1
;
// Label id for background class. Needed for sanity check so that
// background class is neither in the ground truth nor the detections.
optional
uint32
background_label_id
=
2
[
default
=
0
];
// Threshold for deciding true/false positive.
optional
float
overlap_threshold
=
3
[
default
=
0.5
];
// If true, also consider difficult ground truth for evaluation.
optional
bool
evaluate_difficult_gt
=
4
[
default
=
true
];
// A file which contains a list of names and sizes with same order
// of the input DB. The file is in the following format:
// name height width
// ...
// If provided, we will scale the prediction and ground truth NormalizedBBox
// for evaluation.
optional
string
name_size_file
=
5
;
// The resize parameter used in converting NormalizedBBox to original image.
optional
ResizeParameter
resize_param
=
6
;
}
message
NonMaximumSuppressionParameter
{
// Threshold to be used in nms.
optional
float
nms_threshold
=
1
[
default
=
0.3
];
// Maximum number of results to be kept.
optional
int32
top_k
=
2
;
// Parameter for adaptive nms.
optional
float
eta
=
3
[
default
=
1.0
];
}
message
SaveOutputParameter
{
// Output directory. If not empty, we will save the results.
optional
string
output_directory
=
1
;
// Output name prefix.
optional
string
output_name_prefix
=
2
;
// Output format.
// VOC - PASCAL VOC output format.
// COCO - MS COCO output format.
optional
string
output_format
=
3
;
// If you want to output results, must also provide the following two files.
// Otherwise, we will ignore saving results.
// label map file.
optional
string
label_map_file
=
4
;
// A file which contains a list of names and sizes with same order
// of the input DB. The file is in the following format:
// name height width
// ...
optional
string
name_size_file
=
5
;
// Number of test images. It can be less than the lines specified in
// name_size_file. For example, when we only want to evaluate on part
// of the test images.
optional
uint32
num_test_image
=
6
;
// The resize parameter used in saving the data.
optional
ResizeParameter
resize_param
=
7
;
}
// Message that store parameters used by DetectionOutputLayer
message
DetectionOutputParameter
{
// Number of classes to be predicted. Required!
optional
uint32
num_classes
=
1
;
// If true, bounding box are shared among different classes.
optional
bool
share_location
=
2
[
default
=
true
];
// Background label id. If there is no background class,
// set it as -1.
optional
int32
background_label_id
=
3
[
default
=
0
];
// Parameters used for non maximum suppression.
optional
NonMaximumSuppressionParameter
nms_param
=
4
;
// Parameters used for saving detection results.
optional
SaveOutputParameter
save_output_param
=
5
;
// Type of coding method for bbox.
optional
PriorBoxParameter.CodeType
code_type
=
6
[
default
=
CORNER
];
// If true, variance is encoded in target; otherwise we need to adjust the
// predicted offset accordingly.
optional
bool
variance_encoded_in_target
=
8
[
default
=
false
];
// Number of total bboxes to be kept per image after nms step.
// -1 means keeping all bboxes after nms step.
optional
int32
keep_top_k
=
7
[
default
=
-
1
];
// Only consider detections whose confidences are larger than a threshold.
// If not provided, consider all boxes.
optional
float
confidence_threshold
=
9
;
// If true, visualize the detection results.
optional
bool
visualize
=
10
[
default
=
false
];
// The threshold used to visualize the detection results.
optional
float
visualize_threshold
=
11
;
// If provided, save outputs to video file.
optional
string
save_file
=
12
;
}
message
DropoutParameter
{
optional
float
dropout_ratio
=
1
[
default
=
0.5
];
// dropout ratio
}
// DummyDataLayer fills any number of arbitrarily shaped blobs with random
// (or constant) data generated by "Fillers" (see "message FillerParameter").
message
DummyDataParameter
{
// This layer produces N >= 1 top blobs. DummyDataParameter must specify 1 or N
// shape fields, and 0, 1 or N data_fillers.
//
// If 0 data_fillers are specified, ConstantFiller with a value of 0 is used.
// If 1 data_filler is specified, it is applied to all top blobs. If N are
// specified, the ith is applied to the ith top blob.
repeated
FillerParameter
data_filler
=
1
;
repeated
BlobShape
shape
=
6
;
// 4D dimensions -- deprecated. Use "shape" instead.
repeated
uint32
num
=
2
;
repeated
uint32
channels
=
3
;
repeated
uint32
height
=
4
;
repeated
uint32
width
=
5
;
}
message
EltwiseParameter
{
enum
EltwiseOp
{
PROD
=
0
;
SUM
=
1
;
MAX
=
2
;
}
optional
EltwiseOp
operation
=
1
[
default
=
SUM
];
// element-wise operation
repeated
float
coeff
=
2
;
// blob-wise coefficient for SUM operation
// Whether to use an asymptotically slower (for >2 inputs) but stabler method
// of computing the gradient for the PROD operation. (No effect for SUM op.)
optional
bool
stable_prod_grad
=
3
[
default
=
true
];
}
// Message that stores parameters used by ELULayer
message
ELUParameter
{
// Described in:
// Clevert, D.-A., Unterthiner, T., & Hochreiter, S. (2015). Fast and Accurate
// Deep Network Learning by Exponential Linear Units (ELUs). arXiv
optional
float
alpha
=
1
[
default
=
1
];
}
// Message that stores parameters used by EmbedLayer
message
EmbedParameter
{
optional
uint32
num_output
=
1
;
// The number of outputs for the layer
// The input is given as integers to be interpreted as one-hot
// vector indices with dimension num_input. Hence num_input should be
// 1 greater than the maximum possible input value.
optional
uint32
input_dim
=
2
;
optional
bool
bias_term
=
3
[
default
=
true
];
// Whether to use a bias term
optional
FillerParameter
weight_filler
=
4
;
// The filler for the weight
optional
FillerParameter
bias_filler
=
5
;
// The filler for the bias
}
// Message that stores parameters used by ExpLayer
message
ExpParameter
{
// ExpLayer computes outputs y = base ^ (shift + scale * x), for base > 0.
// Or if base is set to the default (-1), base is set to e,
// so y = exp(shift + scale * x).
optional
float
base
=
1
[
default
=
-
1.0
];
optional
float
scale
=
2
[
default
=
1.0
];
optional
float
shift
=
3
[
default
=
0.0
];
}
/// Message that stores parameters used by FlattenLayer
message
FlattenParameter
{
// The first axis to flatten: all preceding axes are retained in the output.
// May be negative to index from the end (e.g., -1 for the last axis).
optional
int32
axis
=
1
[
default
=
1
];
// The last axis to flatten: all following axes are retained in the output.
// May be negative to index from the end (e.g., the default -1 for the last
// axis).
optional
int32
end_axis
=
2
[
default
=
-
1
];
}
// Message that stores parameters used by HDF5DataLayer
message
HDF5DataParameter
{
// Specify the data source.
optional
string
source
=
1
;
// Specify the batch size.
optional
uint32
batch_size
=
2
;
// Specify whether to shuffle the data.
// If shuffle == true, the ordering of the HDF5 files is shuffled,
// and the ordering of data within any given HDF5 file is shuffled,
// but data between different files are not interleaved; all of a file's
// data are output (in a random order) before moving onto another file.
optional
bool
shuffle
=
3
[
default
=
false
];
}
message
HDF5OutputParameter
{
optional
string
file_name
=
1
;
}
message
HingeLossParameter
{
enum
Norm
{
L1
=
1
;
L2
=
2
;
}
// Specify the Norm to use L1 or L2
optional
Norm
norm
=
1
[
default
=
L1
];
}
message
ImageDataParameter
{
// Specify the data source.
optional
string
source
=
1
;
// Specify the batch size.
optional
uint32
batch_size
=
4
[
default
=
1
];
// The rand_skip variable is for the data layer to skip a few data points
// to avoid all asynchronous sgd clients to start at the same point. The skip
// point would be set as rand_skip * rand(0,1). Note that rand_skip should not
// be larger than the number of keys in the database.
optional
uint32
rand_skip
=
7
[
default
=
0
];
// Whether or not ImageLayer should shuffle the list of files at every epoch.
optional
bool
shuffle
=
8
[
default
=
false
];
// It will also resize images if new_height or new_width are not zero.
optional
uint32
new_height
=
9
[
default
=
0
];
optional
uint32
new_width
=
10
[
default
=
0
];
// Specify if the images are color or gray
optional
bool
is_color
=
11
[
default
=
true
];
// DEPRECATED. See TransformationParameter. For data pre-processing, we can do
// simple scaling and subtracting the data mean, if provided. Note that the
// mean subtraction is always carried out before scaling.
optional
float
scale
=
2
[
default
=
1
];
optional
string
mean_file
=
3
;
// DEPRECATED. See TransformationParameter. Specify if we would like to randomly
// crop an image.
optional
uint32
crop_size
=
5
[
default
=
0
];
// DEPRECATED. See TransformationParameter. Specify if we want to randomly mirror
// data.
optional
bool
mirror
=
6
[
default
=
false
];
optional
string
root_folder
=
12
[
default
=
""
];
}
message
InfogainLossParameter
{
// Specify the infogain matrix source.
optional
string
source
=
1
;
}
message
InnerProductParameter
{
optional
uint32
num_output
=
1
;
// The number of outputs for the layer
optional
bool
bias_term
=
2
[
default
=
true
];
// whether to have bias terms
optional
FillerParameter
weight_filler
=
3
;
// The filler for the weight
optional
FillerParameter
bias_filler
=
4
;
// The filler for the bias
// The first axis to be lumped into a single inner product computation;
// all preceding axes are retained in the output.
// May be negative to index from the end (e.g., -1 for the last axis).
optional
int32
axis
=
5
[
default
=
1
];
// Specify whether to transpose the weight matrix or not.
// If transpose == true, any operations will be performed on the transpose
// of the weight matrix. The weight matrix itself is not going to be transposed
// but rather the transfer flag of operations will be toggled accordingly.
optional
bool
transpose
=
6
[
default
=
false
];
}
message
InputParameter
{
// This layer produces N >= 1 top blob(s) to be assigned manually.
// Define N shapes to set a shape for each top.
// Define 1 shape to set the same shape for every top.
// Define no shape to defer to reshaping manually.
repeated
BlobShape
shape
=
1
;
}
// Message that stores parameters used by LogLayer
message
LogParameter
{
// LogLayer computes outputs y = log_base(shift + scale * x), for base > 0.
// Or if base is set to the default (-1), base is set to e,
// so y = ln(shift + scale * x) = log_e(shift + scale * x)
optional
float
base
=
1
[
default
=
-
1.0
];
optional
float
scale
=
2
[
default
=
1.0
];
optional
float
shift
=
3
[
default
=
0.0
];
}
// Message that stores parameters used by LRNLayer
message
LRNParameter
{
optional
uint32
local_size
=
1
[
default
=
5
];
optional
float
alpha
=
2
[
default
=
1.
];
optional
float
beta
=
3
[
default
=
0.75
];
enum
NormRegion
{
ACROSS_CHANNELS
=
0
;
WITHIN_CHANNEL
=
1
;
}
optional
NormRegion
norm_region
=
4
[
default
=
ACROSS_CHANNELS
];
optional
float
k
=
5
[
default
=
1.
];
enum
Engine
{
DEFAULT
=
0
;
CAFFE
=
1
;
CUDNN
=
2
;
}
optional
Engine
engine
=
6
[
default
=
DEFAULT
];
}
message
MemoryDataParameter
{
optional
uint32
batch_size
=
1
;
optional
uint32
channels
=
2
;
optional
uint32
height
=
3
;
optional
uint32
width
=
4
;
}
// Message that store parameters used by MultiBoxLossLayer
message
MultiBoxLossParameter
{
// Localization loss type.
enum
LocLossType
{
L2
=
0
;
SMOOTH_L1
=
1
;
}
optional
LocLossType
loc_loss_type
=
1
[
default
=
SMOOTH_L1
];
// Confidence loss type.
enum
ConfLossType
{
SOFTMAX
=
0
;
LOGISTIC
=
1
;
}
optional
ConfLossType
conf_loss_type
=
2
[
default
=
SOFTMAX
];
// Weight for localization loss.
optional
float
loc_weight
=
3
[
default
=
1.0
];
// Number of classes to be predicted. Required!
optional
uint32
num_classes
=
4
;
// If true, bounding box are shared among different classes.
optional
bool
share_location
=
5
[
default
=
true
];
// Matching method during training.
enum
MatchType
{
BIPARTITE
=
0
;
PER_PREDICTION
=
1
;
}
optional
MatchType
match_type
=
6
[
default
=
PER_PREDICTION
];
// If match_type is PER_PREDICTION, use overlap_threshold to
// determine the extra matching bboxes.
optional
float
overlap_threshold
=
7
[
default
=
0.5
];
// Use prior for matching.
optional
bool
use_prior_for_matching
=
8
[
default
=
true
];
// Background label id.
optional
uint32
background_label_id
=
9
[
default
=
0
];
// If true, also consider difficult ground truth.
optional
bool
use_difficult_gt
=
10
[
default
=
true
];
// If true, perform negative mining.
// DEPRECATED: use mining_type instead.
optional
bool
do_neg_mining
=
11
;
// The negative/positive ratio.
optional
float
neg_pos_ratio
=
12
[
default
=
3.0
];
// The negative overlap upperbound for the unmatched predictions.
optional
float
neg_overlap
=
13
[
default
=
0.5
];
// Type of coding method for bbox.
optional
PriorBoxParameter.CodeType
code_type
=
14
[
default
=
CORNER
];
// If true, encode the variance of prior box in the loc loss target instead of
// in bbox.
optional
bool
encode_variance_in_target
=
16
[
default
=
false
];
// If true, map all object classes to agnostic class. It is useful for learning
// objectness detector.
optional
bool
map_object_to_agnostic
=
17
[
default
=
false
];
// If true, ignore cross boundary bbox during matching.
// Cross boundary bbox is a bbox who is outside of the image region.
optional
bool
ignore_cross_boundary_bbox
=
18
[
default
=
false
];
// If true, only backpropagate on corners which are inside of the image
// region when encode_type is CORNER or CORNER_SIZE.
optional
bool
bp_inside
=
19
[
default
=
false
];
// Mining type during training.
// NONE : use all negatives.
// MAX_NEGATIVE : select negatives based on the score.
// HARD_EXAMPLE : select hard examples based on "Training Region-based Object Detectors with Online Hard Example Mining", Shrivastava et.al.
enum
MiningType
{
NONE
=
0
;
MAX_NEGATIVE
=
1
;
HARD_EXAMPLE
=
2
;
}
optional
MiningType
mining_type
=
20
[
default
=
MAX_NEGATIVE
];
// Parameters used for non maximum suppression durig hard example mining.
optional
NonMaximumSuppressionParameter
nms_param
=
21
;
optional
int32
sample_size
=
22
[
default
=
64
];
optional
bool
use_prior_for_nms
=
23
[
default
=
false
];
}
message
MVNParameter
{
// This parameter can be set to false to normalize mean only
optional
bool
normalize_variance
=
1
[
default
=
true
];
// This parameter can be set to true to perform DNN-like MVN
optional
bool
across_channels
=
2
[
default
=
false
];
// Epsilon for not dividing by zero while normalizing variance
optional
float
eps
=
3
[
default
=
1e-9
];
}
// Message that stores parameters used by NormalizeLayer
message
NormalizeParameter
{
optional
bool
across_spatial
=
1
[
default
=
true
];
// Initial value of scale. Default is 1.0 for all
optional
FillerParameter
scale_filler
=
2
;
// Whether or not scale parameters are shared across channels.
optional
bool
channel_shared
=
3
[
default
=
true
];
// Epsilon for not dividing by zero while normalizing variance
optional
float
eps
=
4
[
default
=
1e-10
];
}
message
ParameterParameter
{
optional
BlobShape
shape
=
1
;
}
message
PermuteParameter
{
// The new orders of the axes of data. Notice it should be with
// in the same range as the input data, and it starts from 0.
// Do not provide repeated order.
repeated
uint32
order
=
1
;
}
message
PoolingParameter
{
enum
PoolMethod
{
MAX
=
0
;
AVE
=
1
;
STOCHASTIC
=
2
;
}
optional
PoolMethod
pool
=
1
[
default
=
MAX
];
// The pooling method
// Pad, kernel size, and stride are all given as a single value for equal
// dimensions in height and width or as Y, X pairs.
optional
uint32
pad
=
4
[
default
=
0
];
// The padding size (equal in Y, X)
optional
uint32
pad_h
=
9
[
default
=
0
];
// The padding height
optional
uint32
pad_w
=
10
[
default
=
0
];
// The padding width
optional
uint32
kernel_size
=
2
;
// The kernel size (square)
optional
uint32
kernel_h
=
5
;
// The kernel height
optional
uint32
kernel_w
=
6
;
// The kernel width
optional
uint32
stride
=
3
[
default
=
1
];
// The stride (equal in Y, X)
optional
uint32
stride_h
=
7
;
// The stride height
optional
uint32
stride_w
=
8
;
// The stride width
enum
Engine
{
DEFAULT
=
0
;
CAFFE
=
1
;
CUDNN
=
2
;
}
optional
Engine
engine
=
11
[
default
=
DEFAULT
];
// If global_pooling then it will pool over the size of the bottom by doing
// kernel_h = bottom->height and kernel_w = bottom->width
optional
bool
global_pooling
=
12
[
default
=
false
];
}
message
PowerParameter
{
// PowerLayer computes outputs y = (shift + scale * x) ^ power.
optional
float
power
=
1
[
default
=
1.0
];
optional
float
scale
=
2
[
default
=
1.0
];
optional
float
shift
=
3
[
default
=
0.0
];
}
// Message that store parameters used by PriorBoxLayer
message
PriorBoxParameter
{
// Encode/decode type.
enum
CodeType
{
CORNER
=
1
;
CENTER_SIZE
=
2
;
CORNER_SIZE
=
3
;
}
// Minimum box size (in pixels). Required!
repeated
float
min_size
=
1
;
// Maximum box size (in pixels). Required!
repeated
float
max_size
=
2
;
// Various of aspect ratios. Duplicate ratios will be ignored.
// If none is provided, we use default ratio 1.
repeated
float
aspect_ratio
=
3
;
// If true, will flip each aspect ratio.
// For example, if there is aspect ratio "r",
// we will generate aspect ratio "1.0/r" as well.
optional
bool
flip
=
4
[
default
=
true
];
// If true, will clip the prior so that it is within [0, 1]
optional
bool
clip
=
5
[
default
=
false
];
// Variance for adjusting the prior bboxes.
repeated
float
variance
=
6
;
// By default, we calculate img_height, img_width, step_x, step_y based on
// bottom[0] (feat) and bottom[1] (img). Unless these values are explicitely
// provided.
// Explicitly provide the img_size.
optional
uint32
img_size
=
7
;
// Either img_size or img_h/img_w should be specified; not both.
optional
uint32
img_h
=
8
;
optional
uint32
img_w
=
9
;
// Explicitly provide the step size.
optional
float
step
=
10
;
// Either step or step_h/step_w should be specified; not both.
optional
float
step_h
=
11
;
optional
float
step_w
=
12
;
// Offset to the top left corner of each cell.
optional
float
offset
=
13
[
default
=
0.5
];
}
message
PythonParameter
{
optional
string
module
=
1
;
optional
string
layer
=
2
;
// This value is set to the attribute `param_str` of the `PythonLayer` object
// in Python before calling the `setup()` method. This could be a number,
// string, dictionary in Python dict format, JSON, etc. You may parse this
// string in `setup` method and use it in `forward` and `backward`.
optional
string
param_str
=
3
[
default
=
''
];
// Whether this PythonLayer is shared among worker solvers during data parallelism.
// If true, each worker solver sequentially run forward from this layer.
// This value should be set true if you are using it as a data layer.
optional
bool
share_in_parallel
=
4
[
default
=
false
];
}
// Message that stores parameters used by RecurrentLayer
message
RecurrentParameter
{
// The dimension of the output (and usually hidden state) representation --
// must be explicitly set to non-zero.
optional
uint32
num_output
=
1
[
default
=
0
];
optional
FillerParameter
weight_filler
=
2
;
// The filler for the weight
optional
FillerParameter
bias_filler
=
3
;
// The filler for the bias
// Whether to enable displaying debug_info in the unrolled recurrent net.
optional
bool
debug_info
=
4
[
default
=
false
];
// Whether to add as additional inputs (bottoms) the initial hidden state
// blobs, and add as additional outputs (tops) the final timestep hidden state
// blobs. The number of additional bottom/top blobs required depends on the
// recurrent architecture -- e.g., 1 for RNNs, 2 for LSTMs.
optional
bool
expose_hidden
=
5
[
default
=
false
];
}
// Message that stores parameters used by ReductionLayer
message
ReductionParameter
{
enum
ReductionOp
{
SUM
=
1
;
ASUM
=
2
;
SUMSQ
=
3
;
MEAN
=
4
;
}
optional
ReductionOp
operation
=
1
[
default
=
SUM
];
// reduction operation
// The first axis to reduce to a scalar -- may be negative to index from the
// end (e.g., -1 for the last axis).
// (Currently, only reduction along ALL "tail" axes is supported; reduction
// of axis M through N, where N < num_axes - 1, is unsupported.)
// Suppose we have an n-axis bottom Blob with shape:
// (d0, d1, d2, ..., d(m-1), dm, d(m+1), ..., d(n-1)).
// If axis == m, the output Blob will have shape
// (d0, d1, d2, ..., d(m-1)),
// and the ReductionOp operation is performed (d0 * d1 * d2 * ... * d(m-1))
// times, each including (dm * d(m+1) * ... * d(n-1)) individual data.
// If axis == 0 (the default), the output Blob always has the empty shape
// (count 1), performing reduction across the entire input --
// often useful for creating new loss functions.
optional
int32
axis
=
2
[
default
=
0
];
optional
float
coeff
=
3
[
default
=
1.0
];
// coefficient for output
}
// Message that stores parameters used by ReLULayer
message
ReLUParameter
{
// Allow non-zero slope for negative inputs to speed up optimization
// Described in:
// Maas, A. L., Hannun, A. Y., & Ng, A. Y. (2013). Rectifier nonlinearities
// improve neural network acoustic models. In ICML Workshop on Deep Learning
// for Audio, Speech, and Language Processing.
optional
float
negative_slope
=
1
[
default
=
0
];
enum
Engine
{
DEFAULT
=
0
;
CAFFE
=
1
;
CUDNN
=
2
;
}
optional
Engine
engine
=
2
[
default
=
DEFAULT
];
}
message
ReshapeParameter
{
// Specify the output dimensions. If some of the dimensions are set to 0,
// the corresponding dimension from the bottom layer is used (unchanged).
// Exactly one dimension may be set to -1, in which case its value is
// inferred from the count of the bottom blob and the remaining dimensions.
// For example, suppose we want to reshape a 2D blob "input" with shape 2 x 8:
//
// layer {
// type: "Reshape" bottom: "input" top: "output"
// reshape_param { ... }
// }
//
// If "input" is 2D with shape 2 x 8, then the following reshape_param
// specifications are all equivalent, producing a 3D blob "output" with shape
// 2 x 2 x 4:
//
// reshape_param { shape { dim: 2 dim: 2 dim: 4 } }
// reshape_param { shape { dim: 0 dim: 2 dim: 4 } }
// reshape_param { shape { dim: 0 dim: 2 dim: -1 } }
// reshape_param { shape { dim: 0 dim:-1 dim: 4 } }
//
optional
BlobShape
shape
=
1
;
// axis and num_axes control the portion of the bottom blob's shape that are
// replaced by (included in) the reshape. By default (axis == 0 and
// num_axes == -1), the entire bottom blob shape is included in the reshape,
// and hence the shape field must specify the entire output shape.
//
// axis may be non-zero to retain some portion of the beginning of the input
// shape (and may be negative to index from the end; e.g., -1 to begin the
// reshape after the last axis, including nothing in the reshape,
// -2 to include only the last axis, etc.).
//
// For example, suppose "input" is a 2D blob with shape 2 x 8.
// Then the following ReshapeLayer specifications are all equivalent,
// producing a blob "output" with shape 2 x 2 x 4:
//
// reshape_param { shape { dim: 2 dim: 2 dim: 4 } }
// reshape_param { shape { dim: 2 dim: 4 } axis: 1 }
// reshape_param { shape { dim: 2 dim: 4 } axis: -3 }
//
// num_axes specifies the extent of the reshape.
// If num_axes >= 0 (and axis >= 0), the reshape will be performed only on
// input axes in the range [axis, axis+num_axes].
// num_axes may also be -1, the default, to include all remaining axes
// (starting from axis).
//
// For example, suppose "input" is a 2D blob with shape 2 x 8.
// Then the following ReshapeLayer specifications are equivalent,
// producing a blob "output" with shape 1 x 2 x 8.
//
// reshape_param { shape { dim: 1 dim: 2 dim: 8 } }
// reshape_param { shape { dim: 1 dim: 2 } num_axes: 1 }
// reshape_param { shape { dim: 1 } num_axes: 0 }
//
// On the other hand, these would produce output blob shape 2 x 1 x 8:
//
// reshape_param { shape { dim: 2 dim: 1 dim: 8 } }
// reshape_param { shape { dim: 1 } axis: 1 num_axes: 0 }
//
optional
int32
axis
=
2
[
default
=
0
];
optional
int32
num_axes
=
3
[
default
=
-
1
];
}
message
ScaleParameter
{
// The first axis of bottom[0] (the first input Blob) along which to apply
// bottom[1] (the second input Blob). May be negative to index from the end
// (e.g., -1 for the last axis).
//
// For example, if bottom[0] is 4D with shape 100x3x40x60, the output
// top[0] will have the same shape, and bottom[1] may have any of the
// following shapes (for the given value of axis):
// (axis == 0 == -4) 100; 100x3; 100x3x40; 100x3x40x60
// (axis == 1 == -3) 3; 3x40; 3x40x60
// (axis == 2 == -2) 40; 40x60
// (axis == 3 == -1) 60
// Furthermore, bottom[1] may have the empty shape (regardless of the value of
// "axis") -- a scalar multiplier.
optional
int32
axis
=
1
[
default
=
1
];
// (num_axes is ignored unless just one bottom is given and the scale is
// a learned parameter of the layer. Otherwise, num_axes is determined by the
// number of axes by the second bottom.)
// The number of axes of the input (bottom[0]) covered by the scale
// parameter, or -1 to cover all axes of bottom[0] starting from `axis`.
// Set num_axes := 0, to multiply with a zero-axis Blob: a scalar.
optional
int32
num_axes
=
2
[
default
=
1
];
// (filler is ignored unless just one bottom is given and the scale is
// a learned parameter of the layer.)
// The initialization for the learned scale parameter.
// Default is the unit (1) initialization, resulting in the ScaleLayer
// initially performing the identity operation.
optional
FillerParameter
filler
=
3
;
// Whether to also learn a bias (equivalent to a ScaleLayer+BiasLayer, but
// may be more efficient). Initialized with bias_filler (defaults to 0).
optional
bool
bias_term
=
4
[
default
=
false
];
optional
FillerParameter
bias_filler
=
5
;
}
message
SigmoidParameter
{
enum
Engine
{
DEFAULT
=
0
;
CAFFE
=
1
;
CUDNN
=
2
;
}
optional
Engine
engine
=
1
[
default
=
DEFAULT
];
}
message
SliceParameter
{
// The axis along which to slice -- may be negative to index from the end
// (e.g., -1 for the last axis).
// By default, SliceLayer concatenates blobs along the "channels" axis (1).
optional
int32
axis
=
3
[
default
=
1
];
repeated
uint32
slice_point
=
2
;
// DEPRECATED: alias for "axis" -- does not support negative indexing.
optional
uint32
slice_dim
=
1
[
default
=
1
];
}
// Message that stores parameters used by SoftmaxLayer, SoftmaxWithLossLayer
message
SoftmaxParameter
{
enum
Engine
{
DEFAULT
=
0
;
CAFFE
=
1
;
CUDNN
=
2
;
}
optional
Engine
engine
=
1
[
default
=
DEFAULT
];
// The axis along which to perform the softmax -- may be negative to index
// from the end (e.g., -1 for the last axis).
// Any other axes will be evaluated as independent softmaxes.
optional
int32
axis
=
2
[
default
=
1
];
}
message
TanHParameter
{
enum
Engine
{
DEFAULT
=
0
;
CAFFE
=
1
;
CUDNN
=
2
;
}
optional
Engine
engine
=
1
[
default
=
DEFAULT
];
}
// Message that stores parameters used by TileLayer
message
TileParameter
{
// The index of the axis to tile.
optional
int32
axis
=
1
[
default
=
1
];
// The number of copies (tiles) of the blob to output.
optional
int32
tiles
=
2
;
}
// Message that stores parameters used by ThresholdLayer
message
ThresholdParameter
{
optional
float
threshold
=
1
[
default
=
0
];
// Strictly positive values
}
message
VideoDataParameter
{
enum
VideoType
{
WEBCAM
=
0
;
VIDEO
=
1
;
}
optional
VideoType
video_type
=
1
[
default
=
WEBCAM
];
optional
int32
device_id
=
2
[
default
=
0
];
optional
string
video_file
=
3
;
// Number of frames to be skipped before processing a frame.
optional
uint32
skip_frames
=
4
[
default
=
0
];
}
message
WindowDataParameter
{
// Specify the data source.
optional
string
source
=
1
;
// For data pre-processing, we can do simple scaling and subtracting the
// data mean, if provided. Note that the mean subtraction is always carried
// out before scaling.
optional
float
scale
=
2
[
default
=
1
];
optional
string
mean_file
=
3
;
// Specify the batch size.
optional
uint32
batch_size
=
4
;
// Specify if we would like to randomly crop an image.
optional
uint32
crop_size
=
5
[
default
=
0
];
// Specify if we want to randomly mirror data.
optional
bool
mirror
=
6
[
default
=
false
];
// Foreground (object) overlap threshold
optional
float
fg_threshold
=
7
[
default
=
0.5
];
// Background (non-object) overlap threshold
optional
float
bg_threshold
=
8
[
default
=
0.5
];
// Fraction of batch that should be foreground objects
optional
float
fg_fraction
=
9
[
default
=
0.25
];
// Amount of contextual padding to add around a window
// (used only by the window_data_layer)
optional
uint32
context_pad
=
10
[
default
=
0
];
// Mode for cropping out a detection window
// warp: cropped window is warped to a fixed size and aspect ratio
// square: the tightest square around the window is cropped
optional
string
crop_mode
=
11
[
default
=
"warp"
];
// cache_images: will load all images in memory for faster access
optional
bool
cache_images
=
12
[
default
=
false
];
// append root_folder to locate images
optional
string
root_folder
=
13
[
default
=
""
];
}
message
SPPParameter
{
enum
PoolMethod
{
MAX
=
0
;
AVE
=
1
;
STOCHASTIC
=
2
;
}
optional
uint32
pyramid_height
=
1
;
optional
PoolMethod
pool
=
2
[
default
=
MAX
];
// The pooling method
enum
Engine
{
DEFAULT
=
0
;
CAFFE
=
1
;
CUDNN
=
2
;
}
optional
Engine
engine
=
6
[
default
=
DEFAULT
];
}
// DEPRECATED: use LayerParameter.
message
V1LayerParameter
{
repeated
string
bottom
=
2
;
repeated
string
top
=
3
;
optional
string
name
=
4
;
repeated
NetStateRule
include
=
32
;
repeated
NetStateRule
exclude
=
33
;
enum
LayerType
{
NONE
=
0
;
ABSVAL
=
35
;
ACCURACY
=
1
;
ARGMAX
=
30
;
BNLL
=
2
;
CONCAT
=
3
;
CONTRASTIVE_LOSS
=
37
;
CONVOLUTION
=
4
;
DATA
=
5
;
DECONVOLUTION
=
39
;
DROPOUT
=
6
;
DUMMY_DATA
=
32
;
EUCLIDEAN_LOSS
=
7
;
ELTWISE
=
25
;
EXP
=
38
;
FLATTEN
=
8
;
HDF5_DATA
=
9
;
HDF5_OUTPUT
=
10
;
HINGE_LOSS
=
28
;
IM2COL
=
11
;
IMAGE_DATA
=
12
;
INFOGAIN_LOSS
=
13
;
INNER_PRODUCT
=
14
;
LRN
=
15
;
MEMORY_DATA
=
29
;
MULTINOMIAL_LOGISTIC_LOSS
=
16
;
MVN
=
34
;
POOLING
=
17
;
POWER
=
26
;
RELU
=
18
;
SIGMOID
=
19
;
SIGMOID_CROSS_ENTROPY_LOSS
=
27
;
SILENCE
=
36
;
SOFTMAX
=
20
;
SOFTMAX_LOSS
=
21
;
SPLIT
=
22
;
SLICE
=
33
;
TANH
=
23
;
WINDOW_DATA
=
24
;
THRESHOLD
=
31
;
}
optional
LayerType
type
=
5
;
repeated
BlobProto
blobs
=
6
;
repeated
string
param
=
1001
;
repeated
DimCheckMode
blob_share_mode
=
1002
;
enum
DimCheckMode
{
STRICT
=
0
;
PERMISSIVE
=
1
;
}
repeated
float
blobs_lr
=
7
;
repeated
float
weight_decay
=
8
;
repeated
float
loss_weight
=
35
;
optional
AccuracyParameter
accuracy_param
=
27
;
optional
ArgMaxParameter
argmax_param
=
23
;
optional
ConcatParameter
concat_param
=
9
;
optional
ContrastiveLossParameter
contrastive_loss_param
=
40
;
optional
ConvolutionParameter
convolution_param
=
10
;
optional
DataParameter
data_param
=
11
;
optional
DropoutParameter
dropout_param
=
12
;
optional
DummyDataParameter
dummy_data_param
=
26
;
optional
EltwiseParameter
eltwise_param
=
24
;
optional
ExpParameter
exp_param
=
41
;
optional
HDF5DataParameter
hdf5_data_param
=
13
;
optional
HDF5OutputParameter
hdf5_output_param
=
14
;
optional
HingeLossParameter
hinge_loss_param
=
29
;
optional
ImageDataParameter
image_data_param
=
15
;
optional
InfogainLossParameter
infogain_loss_param
=
16
;
optional
InnerProductParameter
inner_product_param
=
17
;
optional
LRNParameter
lrn_param
=
18
;
optional
MemoryDataParameter
memory_data_param
=
22
;
optional
MVNParameter
mvn_param
=
34
;
optional
PoolingParameter
pooling_param
=
19
;
optional
PowerParameter
power_param
=
21
;
optional
ReLUParameter
relu_param
=
30
;
optional
SigmoidParameter
sigmoid_param
=
38
;
optional
SoftmaxParameter
softmax_param
=
39
;
optional
SliceParameter
slice_param
=
31
;
optional
TanHParameter
tanh_param
=
37
;
optional
ThresholdParameter
threshold_param
=
25
;
optional
WindowDataParameter
window_data_param
=
20
;
optional
TransformationParameter
transform_param
=
36
;
optional
LossParameter
loss_param
=
42
;
optional
V0LayerParameter
layer
=
1
;
}
// DEPRECATED: V0LayerParameter is the old way of specifying layer parameters
// in Caffe. We keep this message type around for legacy support.
message
V0LayerParameter
{
optional
string
name
=
1
;
// the layer name
optional
string
type
=
2
;
// the string to specify the layer type
// Parameters to specify layers with inner products.
optional
uint32
num_output
=
3
;
// The number of outputs for the layer
optional
bool
biasterm
=
4
[
default
=
true
];
// whether to have bias terms
optional
FillerParameter
weight_filler
=
5
;
// The filler for the weight
optional
FillerParameter
bias_filler
=
6
;
// The filler for the bias
optional
uint32
pad
=
7
[
default
=
0
];
// The padding size
optional
uint32
kernelsize
=
8
;
// The kernel size
optional
uint32
group
=
9
[
default
=
1
];
// The group size for group conv
optional
uint32
stride
=
10
[
default
=
1
];
// The stride
enum
PoolMethod
{
MAX
=
0
;
AVE
=
1
;
STOCHASTIC
=
2
;
}
optional
PoolMethod
pool
=
11
[
default
=
MAX
];
// The pooling method
optional
float
dropout_ratio
=
12
[
default
=
0.5
];
// dropout ratio
optional
uint32
local_size
=
13
[
default
=
5
];
// for local response norm
optional
float
alpha
=
14
[
default
=
1.
];
// for local response norm
optional
float
beta
=
15
[
default
=
0.75
];
// for local response norm
optional
float
k
=
22
[
default
=
1.
];
// For data layers, specify the data source
optional
string
source
=
16
;
// For data pre-processing, we can do simple scaling and subtracting the
// data mean, if provided. Note that the mean subtraction is always carried
// out before scaling.
optional
float
scale
=
17
[
default
=
1
];
optional
string
meanfile
=
18
;
// For data layers, specify the batch size.
optional
uint32
batchsize
=
19
;
// For data layers, specify if we would like to randomly crop an image.
optional
uint32
cropsize
=
20
[
default
=
0
];
// For data layers, specify if we want to randomly mirror data.
optional
bool
mirror
=
21
[
default
=
false
];
// The blobs containing the numeric parameters of the layer
repeated
BlobProto
blobs
=
50
;
// The ratio that is multiplied on the global learning rate. If you want to
// set the learning ratio for one blob, you need to set it for all blobs.
repeated
float
blobs_lr
=
51
;
// The weight decay that is multiplied on the global weight decay.
repeated
float
weight_decay
=
52
;
// The rand_skip variable is for the data layer to skip a few data points
// to avoid all asynchronous sgd clients to start at the same point. The skip
// point would be set as rand_skip * rand(0,1). Note that rand_skip should not
// be larger than the number of keys in the database.
optional
uint32
rand_skip
=
53
[
default
=
0
];
// Fields related to detection (det_*)
// foreground (object) overlap threshold
optional
float
det_fg_threshold
=
54
[
default
=
0.5
];
// background (non-object) overlap threshold
optional
float
det_bg_threshold
=
55
[
default
=
0.5
];
// Fraction of batch that should be foreground objects
optional
float
det_fg_fraction
=
56
[
default
=
0.25
];
// optional bool OBSOLETE_can_clobber = 57 [default = true];
// Amount of contextual padding to add around a window
// (used only by the window_data_layer)
optional
uint32
det_context_pad
=
58
[
default
=
0
];
// Mode for cropping out a detection window
// warp: cropped window is warped to a fixed size and aspect ratio
// square: the tightest square around the window is cropped
optional
string
det_crop_mode
=
59
[
default
=
"warp"
];
// For ReshapeLayer, one needs to specify the new dimensions.
optional
int32
new_num
=
60
[
default
=
0
];
optional
int32
new_channels
=
61
[
default
=
0
];
optional
int32
new_height
=
62
[
default
=
0
];
optional
int32
new_width
=
63
[
default
=
0
];
// Whether or not ImageLayer should shuffle the list of files at every epoch.
// It will also resize images if new_height or new_width are not zero.
optional
bool
shuffle_images
=
64
[
default
=
false
];
// For ConcatLayer, one needs to specify the dimension for concatenation, and
// the other dimensions must be the same for all the bottom blobs.
// By default it will concatenate blobs along the channels dimension.
optional
uint32
concat_dim
=
65
[
default
=
1
];
optional
HDF5OutputParameter
hdf5_output_param
=
1001
;
}
message
PReLUParameter
{
// Parametric ReLU described in K. He et al, Delving Deep into Rectifiers:
// Surpassing Human-Level Performance on ImageNet Classification, 2015.
// Initial value of a_i. Default is a_i=0.25 for all i.
optional
FillerParameter
filler
=
1
;
// Whether or not slope paramters are shared across channels.
optional
bool
channel_shared
=
2
[
default
=
false
];
}
message
AxpyParameter
{
}
message
UpsampleParameter
{
optional
int32
scale
=
1
[
default
=
1
];
}
message
ROIPoolingParameter
{
// Pad, kernel size, and stride are all given as a single value for equal
// dimensions in height and width or as Y, X pairs.
optional
uint32
pooled_h
=
1
[
default
=
0
];
// The pooled output height
optional
uint32
pooled_w
=
2
[
default
=
0
];
// The pooled output width
// Multiplicative spatial scale factor to translate ROI coords from their
// input scale to the scale used when pooling
optional
float
spatial_scale
=
3
[
default
=
1
];
}
message
ShuffleChannelParameter
{
optional
uint32
group
=
1
[
default
=
1
];
// The number of group
}
x2paddle/decoder/caffe_pb2.py
浏览文件 @
ce6ffee2
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
x2paddle/decoder/onnx_shape_inference.py
浏览文件 @
ce6ffee2
...
...
@@ -267,9 +267,9 @@ class SymbolicShapeInference:
if
pending_nodes
and
self
.
verbose_
>
0
:
print
(
'SymbolicShapeInference: orphaned nodes discarded: '
)
print
(
*
[
n
.
op_type
+
': '
+
n
.
output
[
0
]
for
n
in
pending_nodes
],
sep
=
'
\n
'
)
for
n
in
pending_nodes
:
print
(
n
.
op_type
+
': '
+
n
.
output
[
0
])
if
input_shapes
is
not
None
:
for
input_name
,
shape
in
input_shapes
.
items
():
for
idx
in
range
(
len
(
self
.
out_mp_
.
graph
.
input
)):
...
...
x2paddle/op_mapper/caffe_custom_layer/normalize.py
浏览文件 @
ce6ffee2
...
...
@@ -17,7 +17,7 @@ def normalize_layer(inputs,
scale_param
=
fluid
.
layers
.
create_parameter
(
shape
=
[
1
]
if
channel_shared
else
[
1
,
1
,
1
,
input_shape
[
0
][
1
]],
dtype
=
input
.
dtype
,
attr
=
name
+
'_scale'
)
attr
=
fluid
.
ParamAttr
(
name
=
name
+
'_scale'
)
)
scale_param
=
fluid
.
layers
.
reshape
(
x
=
scale_param
,
\
shape
=
[
1
]
if
channel_shared
else
[
input_shape
[
0
][
1
]])
out
=
fluid
.
layers
.
elementwise_mul
(
...
...
x2paddle/op_mapper/caffe_op_mapper.py
浏览文件 @
ce6ffee2
...
...
@@ -226,7 +226,7 @@ class CaffeOpMapper(OpMapper):
data
.
append
(
np
.
zeros
([
output_c
,
input_c
,
kernel
[
0
],
kernel
[
1
]]).
astype
(
'float32'
))
data
.
append
(
np
.
zeros
([
output_c
,
])
).
astype
(
'float32'
)
data
.
append
(
np
.
zeros
([
output_c
,
])
.
astype
(
'float32'
)
)
else
:
data
=
self
.
adjust_parameters
(
node
)
self
.
weights
[
node
.
layer_name
+
'_weights'
]
=
data
[
0
]
...
...
x2paddle/op_mapper/onnx2paddle/opset9/opset.py
浏览文件 @
ce6ffee2
...
...
@@ -43,6 +43,21 @@ def _const_weight_or_none(node, necessary=False):
return
None
def
_is_static_shape
(
shape
):
negtive_dims
=
0
error_dims
=
0
for
dim
in
shape
:
if
dim
<
0
:
negtive_dims
+=
1
if
dim
<
-
1
:
error_dims
+=
1
if
negtive_dims
>
1
:
return
False
if
error_dims
>
0
:
return
False
return
True
def
_get_same_padding
(
in_size
,
kernel_size
,
stride
):
new_size
=
int
(
math
.
ceil
(
in_size
*
1.0
/
stride
))
pad_size
=
(
new_size
-
1
)
*
stride
+
kernel_size
-
in_size
...
...
@@ -231,42 +246,9 @@ class OpSet9():
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_y
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
val_y_shape
=
val_y
.
out_shapes
[
0
]
val_x_shape
=
val_x
.
out_shapes
[
0
]
if
len
(
val_x_shape
)
<
len
(
val_y_shape
):
val_x
,
val_y
=
val_y
,
val_x
val_y_shape
,
val_x_shape
=
val_x_shape
,
val_y_shape
str_y_shape
=
','
.
join
(
str
(
e
)
for
e
in
val_y_shape
)
str_x_shape
=
','
.
join
(
str
(
e
)
for
e
in
val_x_shape
)
slice_idx
=
0
if
str_y_shape
not
in
str_x_shape
:
for
dim
in
val_y_shape
:
if
dim
==
1
:
slice_idx
+=
1
else
:
break
attr
=
{
"name"
:
string
(
node
.
layer_name
)}
if
slice_idx
<
len
(
val_y_shape
)
and
slice_idx
>
0
:
val_y_reshaped
=
val_y_shape
[
slice_idx
:]
var_y_reshaped
=
val_y
.
layer_name
+
'_reshaped'
attr_reshaped
=
{
'shape'
:
val_y_reshaped
,
'name'
:
string
(
var_y_reshaped
)
}
node
.
fluid_code
.
add_layer
(
'reshape'
,
inputs
=
val_y
,
output
=
var_y_reshaped
,
param_attr
=
attr_reshaped
)
inputs
=
{
'x'
:
val_x
,
'y'
:
var_y_reshaped
}
node
.
fluid_code
.
add_layer
(
op_type
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
attr
)
else
:
inputs
=
{
'x'
:
val_x
,
'y'
:
val_y
}
node
.
fluid_code
.
add_layer
(
op_type
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
attr
)
inputs
=
{
'x'
:
val_x
,
'y'
:
val_y
}
node
.
fluid_code
.
add_layer
(
op_type
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
@
print_mapping_info
def
place_holder
(
self
,
node
):
...
...
@@ -429,6 +411,7 @@ class OpSet9():
output_shape
=
node
.
out_shapes
[
0
]
assume_pad2d
=
False
attr
=
{}
paddings
=
[]
if
len
(
pads
)
==
4
:
assume_pad2d
|=
mode
!=
'constant'
if
data_shape
:
...
...
@@ -479,8 +462,21 @@ class OpSet9():
output
=
node
,
param_attr
=
{
'shape'
:
[
1
]})
else
:
node
.
fluid_code
.
add_layer
(
'unsqueeze'
,
inputs
=
val_x
,
output
=
node
,
param_attr
=
attr
)
if
str
(
val_x
.
dtype
)
==
'bool'
:
val_x_cast
=
val_x
.
layer_name
+
'_cast'
node
.
fluid_code
.
add_layer
(
'cast'
,
inputs
=
val_x
,
output
=
val_x_cast
,
param_attr
=
{
'dtype'
:
string
(
'int64'
)})
node
.
fluid_code
.
add_layer
(
'unsqueeze'
,
inputs
=
val_x_cast
,
output
=
node
,
param_attr
=
attr
)
else
:
node
.
fluid_code
.
add_layer
(
'unsqueeze'
,
inputs
=
val_x
,
output
=
node
,
param_attr
=
attr
)
@
print_mapping_info
def
Shrink
(
self
,
node
):
...
...
@@ -492,16 +488,6 @@ class OpSet9():
node
.
fluid_code
.
add_layer
(
'hard_shrink'
,
inputs
=
val_x
,
output
=
node
,
param_attr
=
attr
)
def
Greater
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_y
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
node
.
fluid_code
.
add_layer
(
'greater_than'
,
inputs
=
{
'x'
:
val_x
,
'y'
:
val_y
},
output
=
node
,
param_attr
=
None
)
@
print_mapping_info
def
Constant
(
self
,
node
):
val_output
=
self
.
graph
.
get_node
(
node
.
layer
.
output
[
0
],
copy
=
True
)
...
...
@@ -571,25 +557,26 @@ class OpSet9():
def
Expand
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_shape
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
if
len
(
val_shape
.
outputs
)
==
1
:
self
.
omit_nodes
.
append
(
val_shape
.
layer_name
)
val_y
=
self
.
graph
.
get_node
(
node
.
layer
.
output
[
0
],
copy
=
True
)
out_shape
=
node
.
out_shapes
[
0
]
val_x_dtype
=
val_x
.
dtype
name_ones
=
node
.
layer_name
+
'_ones'
attr_ones
=
{
'shape'
:
out_shape
,
'dtype'
:
string
(
val_x_dtype
)}
attr_ones
=
{
'shape'
:
val_shape
.
layer_name
,
'dtype'
:
string
(
val_x_dtype
),
'value'
:
1
}
node
.
fluid_code
.
add_layer
(
'ones'
,
inputs
=
None
,
output
=
name_ones
,
param_attr
=
attr_ones
)
'fill_constant'
,
inputs
=
None
,
output
=
name_ones
,
param_attr
=
attr_ones
)
inputs
=
{
'x'
:
name_ones
,
'y'
:
val_x
}
attr
=
{
'name'
:
string
(
node
.
layer_name
)}
node
.
fluid_code
.
add_layer
(
'elementwise_mul'
,
inputs
=
inputs
,
output
=
node
.
layer_name
,
param_attr
=
attr
)
param_attr
=
None
)
@
print_mapping_info
def
Gather
(
self
,
node
):
...
...
@@ -600,12 +587,35 @@ class OpSet9():
#assert len(
# indices_shape) <= 2, "Gather op don't support dim of indice >2 "
if
axis
==
0
and
len
(
indices_shape
)
<=
1
:
node
.
fluid_code
.
add_layer
(
'gather'
,
inputs
=
{
'input'
:
val_x
,
'index'
:
indices
},
output
=
node
,
param_attr
=
None
)
if
len
(
val_x
.
out_shapes
[
0
])
<=
1
:
node
.
fluid_code
.
add_layer
(
'gather'
,
inputs
=
{
'input'
:
val_x
,
'index'
:
indices
},
output
=
node
,
param_attr
=
None
)
elif
len
(
val_x
.
out_shapes
[
0
])
>
1
:
if
len
(
indices_shape
)
==
0
:
gather_
=
node
.
layer_name
+
'_1'
node
.
fluid_code
.
add_layer
(
'gather'
,
inputs
=
{
'input'
:
val_x
,
'index'
:
indices
},
output
=
gather_
,
param_attr
=
None
)
node
.
fluid_code
.
add_layer
(
'squeeze'
,
inputs
=
{
'input'
:
gather_
,
'axes'
:
[
0
]},
output
=
node
,
param_attr
=
None
)
else
:
node
.
fluid_code
.
add_layer
(
'gather'
,
inputs
=
{
'input'
:
val_x
,
'index'
:
indices
},
output
=
node
,
param_attr
=
None
)
elif
axis
>
0
and
len
(
indices_shape
)
<=
1
:
perm
=
list
(
range
(
len
(
val_x
.
out_shapes
[
0
])))
perm
=
[
axis
]
+
perm
[:
axis
]
+
perm
[
axis
+
1
:]
...
...
@@ -624,12 +634,25 @@ class OpSet9():
param_attr
=
None
)
node
.
fluid_code
.
add_layer
(
'transpose'
,
inputs
=
node
,
output
=
node
,
param_attr
=
attr_trans
)
if
len
(
indices_shape
)
<
1
:
node
.
fluid_code
.
add_layer
(
'squeeze'
,
inputs
=
{
'input'
:
node
,
'axes'
:
[
axis
]},
output
=
node
,
param_attr
=
None
)
elif
axis
==
0
and
len
(
indices_shape
)
>
1
:
if
val_x
.
out_shapes
[
0
]
is
not
None
and
isinstance
(
val_x
,
ONNXGraphDataNode
):
indices_cast
=
indices
.
layer_name
+
'_cast'
node
.
fluid_code
.
add_layer
(
'
embedding
'
,
'
cast
'
,
inputs
=
indices
,
output
=
indices_cast
,
param_attr
=
{
'dtype'
:
string
(
'int64'
)})
node
.
fluid_code
.
add_layer
(
'embedding'
,
inputs
=
indices_cast
,
output
=
node
,
use_fluid
=
True
,
param_attr
=
{
...
...
@@ -638,7 +661,6 @@ class OpSet9():
})
else
:
from
functools
import
reduce
#indices_shape = [1,7]
reshape_shape
=
reduce
(
lambda
x
,
y
:
x
*
y
,
indices_shape
)
indices_reshape
=
indices
.
layer_name
+
'_shape'
node
.
fluid_code
.
add_layer
(
...
...
@@ -678,7 +700,7 @@ class OpSet9():
perm
=
list
(
range
(
len
(
val_x
.
out_shapes
[
0
])))
perm
=
[
axis
]
+
perm
[:
axis
]
+
perm
[
axis
+
1
:]
attr_trans
=
{
'perm'
:
perm
}
name_trans
=
val_x
.
layer_name
+
'_trans'
name_trans
=
val_x
.
layer_name
+
'_trans
pose
'
node
.
fluid_code
.
add_layer
(
'transpose'
,
inputs
=
val_x
,
...
...
@@ -690,8 +712,12 @@ class OpSet9():
'index'
:
indices_reshape
},
output
=
node
,
param_attr
=
None
)
input_transpose
=
node
.
layer_name
+
'_transpose'
node
.
fluid_code
.
add_layer
(
'transpose'
,
inputs
=
node
,
output
=
node
,
param_attr
=
attr_trans
)
'transpose'
,
inputs
=
node
,
output
=
input_transpose
,
param_attr
=
attr_trans
)
val_x_shape
=
val_x
.
out_shapes
[
0
]
reshaped_shape
=
[]
for
i
in
perm
:
...
...
@@ -700,10 +726,90 @@ class OpSet9():
reshaped_shape
.
append
(
i
)
node
.
fluid_code
.
add_layer
(
'reshape'
,
inputs
=
nod
e
,
inputs
=
input_transpos
e
,
output
=
node
,
param_attr
=
{
'shape'
:
reshaped_shape
})
@
print_mapping_info
def
ScatterND
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
indices
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
updates
=
self
.
graph
.
get_input_node
(
node
,
idx
=
2
,
copy
=
True
)
if
len
(
indices
.
out_shapes
[
0
])
==
1
:
node
.
fluid_code
.
add_layer
(
'scatter'
,
inputs
=
{
'input'
:
val_x
,
'index'
:
indices
,
'updates'
:
updates
},
output
=
node
,
param_attr
=
None
)
else
:
input_inner_indices
=
node
.
layer_name
+
'_input_inner_indices'
node
.
fluid_code
.
add_layer
(
'scatter_nd'
,
inputs
=
{
'shape'
:
val_x
.
out_shapes
[
0
],
'index'
:
indices
,
'updates'
:
updates
},
output
=
input_inner_indices
,
param_attr
=
None
)
constant_minus_one
=
node
.
layer_name
+
'_constant_minus_one'
node
.
fluid_code
.
add_layer
(
'fill_constant'
,
inputs
=
None
,
output
=
constant_minus_one
,
param_attr
=
{
'shape'
:
updates
.
out_shapes
[
0
],
'dtype'
:
string
(
updates
.
dtype
),
'value'
:
-
1
})
indices_mask
=
node
.
layer_name
+
'_indices_mask'
node
.
fluid_code
.
add_layer
(
'scatter_nd'
,
inputs
=
{
'shape'
:
val_x
.
out_shapes
[
0
],
'index'
:
indices
,
'updates'
:
constant_minus_one
},
output
=
indices_mask
,
param_attr
=
None
)
constant_1
=
node
.
layer_name
+
'_constant_1'
node
.
fluid_code
.
add_layer
(
'fill_constant'
,
inputs
=
None
,
output
=
constant_1
,
param_attr
=
{
'shape'
:
val_x
.
out_shapes
[
0
],
'dtype'
:
string
(
val_x
.
dtype
),
'value'
:
1
})
input_out_indices_mask
=
node
.
layer_name
+
'_input_out_indices_mask'
node
.
fluid_code
.
add_layer
(
"elementwise_add"
,
inputs
=
{
"x"
:
indices_mask
,
"y"
:
constant_1
},
output
=
input_out_indices_mask
,
param_attr
=
None
)
input_out_indices
=
node
.
layer_name
+
'_input_out_indices'
node
.
fluid_code
.
add_layer
(
"elementwise_mul"
,
inputs
=
{
"x"
:
val_x
,
"y"
:
input_out_indices_mask
},
output
=
input_out_indices
,
param_attr
=
None
)
node
.
fluid_code
.
add_layer
(
"elementwise_add"
,
inputs
=
{
"x"
:
input_inner_indices
,
"y"
:
input_out_indices
},
output
=
node
,
param_attr
=
None
)
@
print_mapping_info
def
Range
(
self
,
node
):
val_start
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
...
...
@@ -754,17 +860,21 @@ class OpSet9():
}
else
:
if
starts
.
dtype
!=
'int32'
:
starts_cast
=
starts
.
layer_name
+
'_cast'
node
.
fluid_code
.
add_layer
(
'cast'
,
inputs
=
starts
,
output
=
starts
,
output
=
starts
_cast
,
param_attr
=
{
'dtype'
:
string
(
'int32'
)})
attr
[
'starts'
]
=
starts_cast
if
ends
.
dtype
!=
'int32'
:
ends_cast
=
ends
.
layer_name
+
'_cast'
node
.
fluid_code
.
add_layer
(
'cast'
,
inputs
=
ends
,
output
=
ends
,
output
=
ends
_cast
,
param_attr
=
{
'dtype'
:
string
(
'int32'
)})
attr
[
'ends'
]
=
ends_cast
else
:
starts
=
node
.
get_attr
(
'starts'
)
ends
=
node
.
get_attr
(
'ends'
)
...
...
@@ -789,8 +899,6 @@ class OpSet9():
'this is not supported'
)
if
len
(
value
)
==
1
:
value
=
value
[
0
]
if
dtype
.
name
==
'int64'
:
dtype
=
'int32'
attr
=
{
'shape'
:
val_shape
.
layer_name
,
'dtype'
:
string
(
dtype
),
...
...
@@ -831,6 +939,14 @@ class OpSet9():
inputs
=
{
'x'
:
val_x
},
output
=
node
,
param_attr
=
{
'shape'
:
shape_value
.
tolist
()})
elif
len
(
node
.
out_shapes
[
0
])
>
0
and
_is_static_shape
(
node
.
out_shapes
[
0
]):
node
.
fluid_code
.
add_layer
(
'reshape'
,
inputs
=
{
'x'
:
val_x
,
'shape'
:
node
.
out_shapes
[
0
]},
output
=
node
,
param_attr
=
attr
)
elif
val_shape
.
dtype
==
'int64'
:
val_shape_cast
=
val_shape
.
layer_name
+
'_cast'
node
.
fluid_code
.
add_layer
(
...
...
@@ -882,6 +998,11 @@ class OpSet9():
node
.
fluid_code
.
add_layer
(
'cast'
,
inputs
=
val_input
,
output
=
node
,
param_attr
=
attr
)
@
print_mapping_info
def
Not
(
self
,
node
):
val_input
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
node
.
fluid_code
.
add_layer
(
'logical_not'
,
inputs
=
val_input
,
output
=
node
)
@
print_mapping_info
def
AveragePool
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
...
...
@@ -922,12 +1043,16 @@ class OpSet9():
@
print_mapping_info
def
Concat
(
self
,
node
):
inputs
=
[]
dtypes
=
set
()
for
i
in
range
(
len
(
node
.
layer
.
input
)):
ipt
=
self
.
graph
.
get_input_node
(
node
,
idx
=
i
,
copy
=
True
)
if
isinstance
(
ipt
,
str
):
inputs
.
append
(
ipt
)
else
:
inputs
.
append
(
ipt
.
layer_name
)
dtypes
.
add
(
ipt
.
dtype
)
if
len
(
dtypes
)
>
1
:
assert
'Unspported situation happened, please create issue on https://github.com/PaddlePaddle/X2Paddle/issues.'
axis
=
node
.
get_attr
(
'axis'
)
attr
=
{
'axis'
:
axis
}
node
.
fluid_code
.
add_layer
(
...
...
@@ -1015,10 +1140,22 @@ class OpSet9():
def
MatMul
(
self
,
node
):
val_x
=
self
.
graph
.
get_input_node
(
node
,
idx
=
0
,
copy
=
True
)
val_y
=
self
.
graph
.
get_input_node
(
node
,
idx
=
1
,
copy
=
True
)
x_shape
=
val_x
.
out_shapes
[
0
]
y_shape
=
val_y
.
out_shapes
[
0
]
inputs
=
{
"x"
:
val_x
,
"y"
:
val_y
}
attr
=
{
"name"
:
string
(
node
.
layer_name
)}
node
.
fluid_code
.
add_layer
(
"matmul"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
attr
)
if
y_shape
[
0
]
==
1
and
x_shape
[
-
1
]
!=
1
and
x_shape
[
0
]
!=
1
:
y_squeeze
=
val_y
.
layer_name
+
'_squeeze'
node
.
fluid_code
.
add_layer
(
"squeeze"
,
inputs
=
val_y
,
output
=
y_squeeze
,
param_attr
=
{
'axes'
:
[
0
]})
inputs
[
'y'
]
=
y_squeeze
node
.
fluid_code
.
add_layer
(
"matmul"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
else
:
node
.
fluid_code
.
add_layer
(
"matmul"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
None
)
@
print_mapping_info
def
BatchNormalization
(
self
,
node
):
...
...
@@ -1154,7 +1291,6 @@ class OpSet9():
'y'
:
cast_condition
},
output
=
mul_val_x
,
param_attr
=
None
)
mul_val_y
=
val_y
.
layer_name
+
'_mul'
node
.
fluid_code
.
add_layer
(
"elementwise_mul"
,
...
...
@@ -1204,6 +1340,15 @@ class OpSet9():
if
repeats
is
None
:
repeats
=
val_repeats
.
layer_name
if
val_repeats
.
dtype
!=
'int32'
:
attr
=
{
"dtype"
:
string
(
"int32"
)}
node
.
fluid_code
.
add_layer
(
"cast"
,
inputs
=
repeats
,
output
=
"{}.tmp"
.
format
(
repeats
),
param_attr
=
attr
)
repeats
=
"{}.tmp"
.
format
(
repeats
)
elif
isinstance
(
repeats
,
int
):
repeats
=
[
repeats
]
...
...
x2paddle/op_mapper/paddle2onnx/opset11/opset.py
浏览文件 @
ce6ffee2
...
...
@@ -93,16 +93,13 @@ class OpSet11(OpSet10):
else
:
coordinate_transformation_mode
=
'half_pixel'
roi_name
=
self
.
get_name
(
op
.
type
,
'roi'
)
roi_node
=
self
.
make_constant_node
(
roi_name
,
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
])
if
(
'OutSize'
in
input_names
and
len
(
op
.
input
(
'OutSize'
))
>
0
)
or
(
'SizeTensor'
in
input_names
and
len
(
op
.
input
(
'SizeTensor'
))
>
0
):
node_list
=
list
()
roi_node
=
self
.
make_constant_node
(
self
.
get_name
(
op
.
type
,
'roi'
),
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
])
roi_name
=
self
.
get_name
(
op
.
type
,
'roi'
)
roi_node
=
self
.
make_constant_node
(
roi_name
,
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
])
empty_name
=
self
.
get_name
(
op
.
type
,
'empty'
)
empty_tensor
=
helper
.
make_tensor
(
empty_name
,
...
...
@@ -168,7 +165,7 @@ class OpSet11(OpSet10):
elif
'Scale'
in
input_names
and
len
(
op
.
input
(
'Scale'
))
>
0
:
node
=
helper
.
make_node
(
'Resize'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
op
.
input
(
'Scale'
)[
0
]],
inputs
=
[
op
.
input
(
'X'
)[
0
],
roi_name
,
op
.
input
(
'Scale'
)[
0
]],
outputs
=
op
.
output
(
'Out'
),
mode
=
'linear'
,
coordinate_transformation_mode
=
coordinate_transformation_mode
)
...
...
@@ -180,10 +177,6 @@ class OpSet11(OpSet10):
scale_node
=
self
.
make_constant_node
(
scale_name
,
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
scale
,
scale
])
roi_name
=
self
.
get_name
(
op
.
type
,
'roi'
)
roi_node
=
self
.
make_constant_node
(
roi_name
,
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
])
node
=
helper
.
make_node
(
'Resize'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
roi_name
,
scale_name
],
...
...
@@ -194,7 +187,7 @@ class OpSet11(OpSet10):
return
[
scale_node
,
roi_node
,
node
]
else
:
raise
Exception
(
"Unexpected situation happend"
)
return
node
return
[
roi_node
,
node
]
def
nearest_interp
(
self
,
op
,
block
):
input_names
=
op
.
input_names
...
...
@@ -203,18 +196,21 @@ class OpSet11(OpSet10):
if
align_corners
:
coordinate_transformation_mode
=
'align_corners'
else
:
coordinate_transformation_mode
=
'asymmetric'
coordinate_transformation_mode
=
'half_pixel'
roi_name
=
self
.
get_name
(
op
.
type
,
'roi'
)
roi_node
=
self
.
make_constant_node
(
roi_name
,
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
])
if
'OutSize'
in
input_names
and
len
(
op
.
input
(
'OutSize'
))
>
0
:
node
=
helper
.
make_node
(
'Resize'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
''
,
op
.
input
(
'OutSize'
)[
0
]],
inputs
=
[
op
.
input
(
'X'
)[
0
],
roi_name
,
op
.
input
(
'OutSize'
)[
0
]],
outputs
=
op
.
output
(
'Out'
),
mode
=
'nearest'
,
coordinate_transformation_mode
=
coordinate_transformation_mode
)
elif
'Scale'
in
input_names
and
len
(
op
.
input
(
'Scale'
))
>
0
:
node
=
helper
.
make_node
(
'Resize'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
op
.
input
(
'Scale'
)[
0
]],
inputs
=
[
op
.
input
(
'X'
)[
0
],
roi_name
,
op
.
input
(
'Scale'
)[
0
]],
outputs
=
op
.
output
(
'Out'
),
mode
=
'nearest'
,
coordinate_transformation_mode
=
coordinate_transformation_mode
)
...
...
@@ -226,10 +222,6 @@ class OpSet11(OpSet10):
scale_node
=
self
.
make_constant_node
(
scale_name
,
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
scale
,
scale
])
roi_name
=
self
.
get_name
(
op
.
type
,
'roi'
)
roi_node
=
self
.
make_constant_node
(
roi_name
,
onnx_pb
.
TensorProto
.
FLOAT
,
[
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
])
node
=
helper
.
make_node
(
'Resize'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
roi_name
,
scale_name
],
...
...
@@ -240,7 +232,7 @@ class OpSet11(OpSet10):
return
[
scale_node
,
roi_node
,
node
]
else
:
raise
Exception
(
"Unexpected situation happend"
)
return
node
return
[
roi_node
,
node
]
def
hard_swish
(
self
,
op
,
block
):
min_name
=
self
.
get_name
(
op
.
type
,
'min'
)
...
...
x2paddle/op_mapper/paddle2onnx/opset11/paddle_custom_layer/multiclass_nms.py
浏览文件 @
ce6ffee2
...
...
@@ -72,6 +72,8 @@ def multiclass_nms(op, block):
dims
=
(),
vals
=
[
float
(
attrs
[
'nms_threshold'
])]))
boxes_num
=
block
.
var
(
outputs
[
'Out'
][
0
]).
shape
[
0
]
top_k_value
=
np
.
int64
(
boxes_num
if
attrs
[
'keep_top_k'
]
==
-
1
else
attrs
[
'keep_top_k'
])
node_keep_top_k
=
onnx
.
helper
.
make_node
(
'Constant'
,
inputs
=
[],
...
...
@@ -80,7 +82,7 @@ def multiclass_nms(op, block):
name
=
name_keep_top_k
[
0
]
+
"@const"
,
data_type
=
onnx
.
TensorProto
.
INT64
,
dims
=
(),
vals
=
[
np
.
int64
(
attrs
[
'keep_top_k'
])
]))
vals
=
[
top_k_value
]))
node_keep_top_k_2D
=
onnx
.
helper
.
make_node
(
'Constant'
,
...
...
@@ -90,7 +92,7 @@ def multiclass_nms(op, block):
name
=
name_keep_top_k_2D
[
0
]
+
"@const"
,
data_type
=
onnx
.
TensorProto
.
INT64
,
dims
=
[
1
,
1
],
vals
=
[
np
.
int64
(
attrs
[
'keep_top_k'
])
]))
vals
=
[
top_k_value
]))
# the paddle data format is x1,y1,x2,y2
kwargs
=
{
'center_point_box'
:
0
}
...
...
x2paddle/op_mapper/paddle2onnx/opset9/opset.py
浏览文件 @
ce6ffee2
...
...
@@ -174,14 +174,15 @@ class OpSet9(object):
inputs
=
[
op
.
input
(
'X'
)[
0
],
temp_value
],
outputs
=
op
.
output
(
'Out'
))
return
[
shape_node
,
y_node
,
node
]
elif
len
(
x_shape
)
==
len
(
y_shape
):
elif
axis
==
-
1
or
axis
==
(
len
(
x_shape
)
-
1
)
or
len
(
x_shape
)
==
len
(
y_shape
):
node
=
helper
.
make_node
(
'Add'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
op
.
input
(
'Y'
)[
0
]],
outputs
=
op
.
output
(
'Out'
))
return
node
else
:
raise
Exc
pe
tion
(
"Unexpected situation happend in elementwise_add"
)
raise
Exc
ep
tion
(
"Unexpected situation happend in elementwise_add"
)
def
elementwise_sub
(
self
,
op
,
block
):
axis
=
op
.
attr
(
'axis'
)
...
...
@@ -203,14 +204,15 @@ class OpSet9(object):
inputs
=
[
op
.
input
(
'X'
)[
0
],
temp_value
],
outputs
=
op
.
output
(
'Out'
))
return
[
shape_node
,
y_node
,
node
]
elif
len
(
x_shape
)
==
len
(
y_shape
):
elif
axis
==
-
1
or
axis
==
(
len
(
x_shape
)
-
1
)
or
len
(
x_shape
)
==
len
(
y_shape
):
node
=
helper
.
make_node
(
'Sub'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
op
.
input
(
'Y'
)[
0
]],
outputs
=
op
.
output
(
'Out'
))
return
node
else
:
raise
Exc
pe
tion
(
"Unexpected situation happend in elementwise_sub"
)
raise
Exc
ep
tion
(
"Unexpected situation happend in elementwise_sub"
)
def
pool2d
(
self
,
op
,
block
):
pool_type
=
{
...
...
@@ -403,6 +405,22 @@ class OpSet9(object):
'Sum'
,
inputs
=
op
.
input
(
'X'
),
outputs
=
op
.
output
(
'Out'
))
return
node
def
floor
(
self
,
op
,
block
):
node
=
helper
.
make_node
(
'Floor'
,
inputs
=
op
.
input
(
'X'
),
outputs
=
op
.
output
(
'Out'
))
return
node
def
uniform_random_batch_size_like
(
self
,
op
,
block
):
node
=
helper
.
make_node
(
'RandomUniformLike'
,
inputs
=
op
.
input
(
'Input'
),
outputs
=
op
.
output
(
'Out'
),
high
=
op
.
attr
(
'max'
),
dtype
=
self
.
paddle_onnx_dtype_map
[
op
.
attr
(
'dtype'
)],
low
=
op
.
attr
(
'min'
),
seed
=
float
(
op
.
attr
(
'seed'
)),
)
return
node
def
depthwise_conv2d
(
self
,
op
,
block
):
return
self
.
conv2d
(
op
,
block
)
...
...
@@ -444,7 +462,7 @@ class OpSet9(object):
ends
=
op
.
attr
(
'ends'
)
node
=
helper
.
make_node
(
"Slice"
,
inputs
=
[
op
.
input
(
'Input'
)[
0
]
,
starts_name
,
ends_name
,
axes_name
],
inputs
=
[
op
.
input
(
'Input'
)[
0
]],
outputs
=
op
.
output
(
'Out'
),
axes
=
axes
,
starts
=
starts
,
...
...
@@ -565,7 +583,7 @@ class OpSet9(object):
input_shape
=
block
.
vars
[
op
.
input
(
'X'
)[
0
]].
shape
if
op
.
attr
(
'align_corners'
)
or
op
.
attr
(
'align_mode'
)
==
0
:
raise
Exception
(
"Resize in onnx(opset<=10) only support coordinate_transformation_mode: 'asymmetric', Try converting with --onnx_op
es
t 11"
"Resize in onnx(opset<=10) only support coordinate_transformation_mode: 'asymmetric', Try converting with --onnx_op
se
t 11"
)
if
(
'OutSize'
in
input_names
and
len
(
op
.
input
(
'OutSize'
))
>
0
)
or
(
'SizeTensor'
in
input_names
and
...
...
@@ -671,14 +689,82 @@ class OpSet9(object):
input_names
=
op
.
input_names
if
op
.
attr
(
'align_corners'
):
raise
Exception
(
"Resize in onnx(opset<=10) only support coordinate_transformation_mode: 'asymmetric', Try converting with --onnx_op
es
t 11"
"Resize in onnx(opset<=10) only support coordinate_transformation_mode: 'asymmetric', Try converting with --onnx_op
se
t 11"
)
if
'OutSize'
in
input_names
and
len
(
op
.
input
(
'OutSize'
))
>
0
:
node
=
helper
.
make_node
(
node_list
=
list
()
shape_name0
=
self
.
get_name
(
op
.
type
,
'shape'
)
shape_node0
=
helper
.
make_node
(
'Shape'
,
inputs
=
op
.
input
(
'X'
),
outputs
=
[
shape_name0
])
starts_name
=
self
.
get_name
(
op
.
type
,
'slice.starts'
)
starts_node
=
self
.
make_constant_node
(
starts_name
,
onnx_pb
.
TensorProto
.
INT64
,
[
0
])
ends_name
=
self
.
get_name
(
op
.
type
,
'slice.ends'
)
ends_node
=
self
.
make_constant_node
(
ends_name
,
onnx_pb
.
TensorProto
.
INT64
,
[
2
])
shape_name1
=
self
.
get_name
(
op
.
type
,
'shape'
)
shape_node1
=
helper
.
make_node
(
'Slice'
,
inputs
=
[
shape_name0
,
starts_name
,
ends_name
],
outputs
=
[
shape_name1
])
node_list
.
extend
([
shape_node0
,
starts_node
,
ends_node
,
shape_node1
])
if
'OutSize'
in
input_names
and
len
(
op
.
input
(
'OutSize'
))
>
0
:
cast_shape_name
=
self
.
get_name
(
op
.
type
,
"shape.cast"
)
cast_shape_node
=
helper
.
make_node
(
'Cast'
,
inputs
=
op
.
input
(
'OutSize'
),
outputs
=
[
cast_shape_name
],
to
=
onnx_pb
.
TensorProto
.
INT64
)
node_list
.
append
(
cast_shape_node
)
else
:
concat_shape_name
=
self
.
get_name
(
op
.
type
,
op
.
output
(
'Out'
)[
0
]
+
"shape.concat"
)
concat_shape_node
=
helper
.
make_node
(
"Concat"
,
inputs
=
op
.
input
(
'SizeTensor'
),
outputs
=
[
concat_shape_name
],
axis
=
0
)
cast_shape_name
=
self
.
get_name
(
op
.
type
,
"shape.cast"
)
cast_shape_node
=
helper
.
make_node
(
'Cast'
,
inputs
=
[
concat_shape_name
],
outputs
=
[
cast_shape_name
],
to
=
onnx_pb
.
TensorProto
.
INT64
)
node_list
.
extend
([
concat_shape_node
,
cast_shape_node
])
shape_name2
=
self
.
get_name
(
op
.
type
,
"shape.concat"
)
shape_node2
=
helper
.
make_node
(
'Concat'
,
inputs
=
[
shape_name1
,
cast_shape_name
],
outputs
=
[
shape_name2
],
axis
=
0
)
node_list
.
append
(
shape_node2
)
cast_shape_name2
=
self
.
get_name
(
op
.
type
,
"shape.cast"
)
cast_shape_node2
=
helper
.
make_node
(
'Cast'
,
inputs
=
[
shape_name2
],
outputs
=
[
cast_shape_name2
],
to
=
onnx_pb
.
TensorProto
.
FLOAT
)
node_list
.
append
(
cast_shape_node2
)
cast_shape_name0
=
self
.
get_name
(
op
.
type
,
"shape.cast"
)
cast_shape_node0
=
helper
.
make_node
(
'Cast'
,
inputs
=
[
shape_name0
],
outputs
=
[
cast_shape_name0
],
to
=
onnx_pb
.
TensorProto
.
FLOAT
)
node_list
.
append
(
cast_shape_node0
)
outputs_h_w_scales
=
op
.
output
(
'Out'
)[
0
]
+
"@out_hw_scales"
node_h_w_scales
=
helper
.
make_node
(
'Div'
,
inputs
=
[
cast_shape_name2
,
cast_shape_name0
],
outputs
=
[
outputs_h_w_scales
])
node_list
.
append
(
node_h_w_scales
)
result_node
=
helper
.
make_node
(
'Resize'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
o
p
.
input
(
'OutSize'
)[
0
]
],
inputs
=
[
op
.
input
(
'X'
)[
0
],
o
utputs_h_w_scales
],
outputs
=
op
.
output
(
'Out'
),
mode
=
'nearest'
)
mode
=
'linear'
)
node_list
.
extend
([
result_node
])
return
node_list
elif
'Scale'
in
input_names
and
len
(
op
.
input
(
'Scale'
))
>
0
:
node
=
helper
.
make_node
(
'Resize'
,
...
...
@@ -714,6 +800,38 @@ class OpSet9(object):
beta
=
offset
)
return
node
def
swish
(
self
,
op
,
block
):
beta
=
op
.
attr
(
'beta'
)
beta_name
=
self
.
get_name
(
op
.
type
,
'beta'
)
beta_node
=
onnx
.
helper
.
make_node
(
'Constant'
,
name
=
beta_name
,
inputs
=
[],
outputs
=
[
beta_name
],
value
=
onnx
.
helper
.
make_tensor
(
name
=
beta_name
,
data_type
=
onnx
.
TensorProto
.
FLOAT
,
dims
=
(),
vals
=
[
beta
]))
beta_x_name
=
self
.
get_name
(
op
.
type
,
'beta_x'
)
beta_x_node
=
onnx
.
helper
.
make_node
(
'Mul'
,
name
=
beta_x_name
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
beta_name
],
outputs
=
[
beta_x_name
])
sigmoid_name
=
self
.
get_name
(
op
.
type
,
'sigmoid'
)
sigmoid_node
=
onnx
.
helper
.
make_node
(
'Sigmoid'
,
name
=
sigmoid_name
,
inputs
=
[
beta_x_name
],
outputs
=
[
sigmoid_name
])
swish_node
=
onnx
.
helper
.
make_node
(
'Mul'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
sigmoid_name
],
outputs
=
op
.
output
(
'Out'
))
return
[
beta_node
,
beta_x_node
,
sigmoid_node
,
swish_node
]
def
hard_swish
(
self
,
op
,
block
):
scale_name
=
self
.
get_name
(
op
.
type
,
'scale'
)
offset_name
=
self
.
get_name
(
op
.
type
,
'offset'
)
...
...
@@ -728,8 +846,8 @@ class OpSet9(object):
node0
=
helper
.
make_node
(
'Add'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
offset_name
],
outputs
=
[
name0
])
name1
=
self
.
get_name
(
op
.
type
,
'relu'
)
min_value
=
op
.
attr
(
'min'
)
max_value
=
op
.
attr
(
'
max
'
)
min_value
=
0.0
max_value
=
op
.
attr
(
'
threshold
'
)
node1
=
helper
.
make_node
(
'Clip'
,
inputs
=
[
name0
],
...
...
@@ -763,14 +881,15 @@ class OpSet9(object):
inputs
=
[
op
.
input
(
'X'
)[
0
],
temp_value
],
outputs
=
op
.
output
(
'Out'
))
return
[
shape_node
,
y_node
,
node
]
elif
len
(
x_shape
)
==
len
(
y_shape
):
elif
axis
==
-
1
or
axis
==
(
len
(
x_shape
)
-
1
)
or
len
(
x_shape
)
==
len
(
y_shape
):
node
=
helper
.
make_node
(
'Mul'
,
inputs
=
[
op
.
input
(
'X'
)[
0
],
op
.
input
(
'Y'
)[
0
]],
outputs
=
op
.
output
(
'Out'
))
return
node
else
:
raise
Exc
petion
(
"Unexpected situation happend in elementwise_add
"
)
raise
Exc
eption
(
"Unexpected situation happend in elementwise_mul
"
)
return
node
def
feed
(
self
,
op
,
block
):
...
...
@@ -799,6 +918,14 @@ class OpSet9(object):
axes
=
op
.
attr
(
'axes'
))
return
node
def
cast
(
self
,
op
,
block
):
node
=
helper
.
make_node
(
'Cast'
,
inputs
=
op
.
input
(
'X'
),
outputs
=
op
.
output
(
'Out'
),
to
=
self
.
paddle_onnx_dtype_map
[
op
.
attr
(
'out_dtype'
)])
return
node
def
arg_max
(
self
,
op
,
block
):
node
=
helper
.
make_node
(
'ArgMax'
,
...
...
x2paddle/op_mapper/paddle2onnx/opset9/paddle_custom_layer/multiclass_nms.py
浏览文件 @
ce6ffee2
...
...
@@ -72,6 +72,8 @@ def multiclass_nms(op, block):
dims
=
(),
vals
=
[
float
(
attrs
[
'nms_threshold'
])]))
boxes_num
=
block
.
var
(
outputs
[
'Out'
][
0
]).
shape
[
0
]
top_k_value
=
np
.
int64
(
boxes_num
if
attrs
[
'keep_top_k'
]
==
-
1
else
attrs
[
'keep_top_k'
])
node_keep_top_k
=
onnx
.
helper
.
make_node
(
'Constant'
,
inputs
=
[],
...
...
@@ -80,7 +82,7 @@ def multiclass_nms(op, block):
name
=
name_keep_top_k
[
0
]
+
"@const"
,
data_type
=
onnx
.
TensorProto
.
INT64
,
dims
=
(),
vals
=
[
np
.
int64
(
attrs
[
'keep_top_k'
])
]))
vals
=
[
top_k_value
]))
node_keep_top_k_2D
=
onnx
.
helper
.
make_node
(
'Constant'
,
...
...
@@ -90,7 +92,7 @@ def multiclass_nms(op, block):
name
=
name_keep_top_k_2D
[
0
]
+
"@const"
,
data_type
=
onnx
.
TensorProto
.
INT64
,
dims
=
[
1
,
1
],
vals
=
[
np
.
int64
(
attrs
[
'keep_top_k'
])
]))
vals
=
[
top_k_value
]))
# the paddle data format is x1,y1,x2,y2
kwargs
=
{
'center_point_box'
:
0
}
...
...
x2paddle/op_mapper/tf_op_mapper_nhwc.py
浏览文件 @
ce6ffee2
...
...
@@ -299,6 +299,10 @@ class TFOpMapperNHWC(OpMapper):
data_format
=
node
.
get_attr
(
"data_format"
).
decode
()
pad_mode
=
node
.
get_attr
(
"padding"
).
decode
()
channel_first
=
data_format
==
"NCHW"
if
data_format
==
"NHWC"
:
n
,
h
,
w
,
c
=
input
.
out_shapes
[
0
]
else
:
n
,
c
,
h
,
w
=
input
.
out_shapes
[
0
]
if
kernel
.
layer_type
==
'Const'
:
kernel_value
=
kernel
.
value
...
...
@@ -329,10 +333,15 @@ class TFOpMapperNHWC(OpMapper):
"dilation"
:
dilations
[
2
:
4
],
"padding"
:
string
(
pad_mode
)
}
if
hasattr
(
node
,
'dilation'
)
and
attr
[
'dilation'
]
==
[
1
,
1
]:
if
len
(
node
.
dilation
)
==
1
:
attr
[
'dilation'
]
=
[
1
,
node
.
dilation
[
0
]]
if
c
==
-
1
:
reshape_attr
=
{
"shape"
:
[
0
,
k_size
[
2
],
0
,
0
]}
node
.
fluid_code
.
add_layer
(
"reshape"
,
inputs
=
input
,
output
=
input
,
param_attr
=
reshape_attr
)
node
.
fluid_code
.
add_layer
(
"conv2d"
,
inputs
=
input
,
output
=
node
,
param_attr
=
attr
)
if
not
channel_first
:
...
...
@@ -748,11 +757,12 @@ class TFOpMapperNHWC(OpMapper):
self
.
add_omit_nodes
(
begin
.
layer_name
,
node
.
layer_name
)
begin
=
begin
.
value
.
tolist
()
else
:
begin
=
begin
shape
=
begin
.
out_shapes
[
0
]
attr
=
{
"shape"
:
shape
}
node
.
fluid_code
.
add_layer
(
"reshape"
,
inputs
=
begin
,
output
=
begin
,
param_attr
=
attr
)
begin
=
self
.
decoder
.
infer_tensor
(
begin
).
tolist
()
# shape = begin.out_shapes[0]
# attr = {"shape": shape}
# node.fluid_code.add_layer(
# "reshape", inputs=begin, output=begin, param_attr=attr)
if
size
.
layer_type
==
"Const"
:
self
.
add_omit_nodes
(
size
.
layer_name
,
node
.
layer_name
)
size
=
size
.
value
.
tolist
()
...
...
@@ -1058,13 +1068,25 @@ class TFOpMapperNHWC(OpMapper):
axis
=
axis
.
value
.
tolist
()
assert
axis
==
0
,
"Only support axis=0 in GatherV2 OP"
attr
=
{
'overwrite'
:
False
}
embeddings_shape
=
embeddings
.
out_shapes
[
0
][
-
1
]
reshape_list
=
list
()
reshape_name
=
index
.
layer_name
if
len
(
index
.
out_shapes
[
0
])
!=
1
:
reshape_list
=
index
.
out_shapes
[
0
]
reshape_attr
=
{
"shape"
:
[
-
1
]}
reshape_name
=
"{}_reshape"
.
format
(
index
.
layer_name
)
node
.
fluid_code
.
add_layer
(
"reshape"
,
inputs
=
index
,
output
=
index
,
param_attr
=
reshape_attr
)
inputs
=
{
'input'
:
embeddings
,
'index'
:
index
}
"reshape"
,
inputs
=
index
,
output
=
reshape_name
,
param_attr
=
reshape_attr
)
inputs
=
{
'input'
:
embeddings
,
'index'
:
reshape_name
}
node
.
fluid_code
.
add_layer
(
"gather"
,
inputs
=
inputs
,
output
=
node
,
param_attr
=
attr
)
if
len
(
index
.
out_shapes
[
0
])
!=
1
:
reshape_attr
=
{
"shape"
:
reshape_list
+
[
embeddings_shape
]}
node
.
fluid_code
.
add_layer
(
"reshape"
,
inputs
=
node
,
output
=
node
,
param_attr
=
reshape_attr
)
def
OneShotIterator
(
self
,
node
):
return
self
.
Placeholder
(
node
)
...
...
x2paddle/optimizer/tf_optimizer.py
浏览文件 @
ce6ffee2
...
...
@@ -863,6 +863,9 @@ class TFOptimizer(object):
weight
=
numpy
.
expand_dims
(
weight
,
2
)
weight
=
numpy
.
expand_dims
(
weight
,
3
)
self
.
op_mapper
.
weights
[
in_nodes3
[
0
].
layer_name
]
=
weight
# fix bug in Paddle1.8.3 and may change in next version.
# self.op_mapper.weights[in_nodes3[0].layer_name +
# '_1'] = weight.reshape(1, -1)
in_nodes3
[
0
].
fluid_code
.
layers
[
0
].
param_attr
[
"shape"
]
=
[
1
,
in_shape
[
-
1
],
1
,
1
]
...
...
x2paddle_model_zoo.md
浏览文件 @
ce6ffee2
# X2Paddle模型测试库
> 目前X2Paddle支持
5
0+的TensorFlow OP,40+的Caffe Layer,覆盖了大部分CV分类模型常用的操作。我们在如下模型列表中测试了X2Paddle的转换。
> 目前X2Paddle支持
7
0+的TensorFlow OP,40+的Caffe Layer,覆盖了大部分CV分类模型常用的操作。我们在如下模型列表中测试了X2Paddle的转换。
**注:**
受限于不同框架的差异,部分模型可能会存在目前无法转换的情况,如TensorFlow中包含控制流的模型,NLP模型等。对于CV常见的模型,如若您发现无法转换或转换失败,存在较大diff等问题,欢迎通过
[
ISSUE反馈
](
https://github.com/PaddlePaddle/X2Paddle/issues/new
)
的方式告知我们(模型名,代码实现或模型获取方式),我们会及时跟进:)
...
...
@@ -20,10 +20,13 @@
| ResNet_V1_101 |
[
code
](
https://github.com/tensorflow/models/tree/master/research/slim/nets
)
|-|
| ResNet_V2_101 |
[
code
](
https://github.com/tensorflow/models/tree/master/research/slim/nets
)
|-|
| UNet |
[
code1
](
https://github.com/jakeret/tf_unet
)
/
[
code2
](
https://github.com/lyatdawn/Unet-Tensorflow
)
|-|
|MTCNN |
[
code
](
https://github.com/AITTSMD/MTCNN-Tensorflow
)
|-|
|YOLO-V3|
[
code
](
https://github.com/YunYang1994/tensorflow-yolov3
)
| 转换需要关闭NHWC->NCHW的优化,见
[
文档Q2
](
FAQ.md
)
|
| FALSR |
[
code
](
https://github.com/xiaomi-automl/FALSR
)
| - |
| DCSCN |
[
code
](
https://modelzoo.co/model/dcscn-super-resolution
)
| - |
| MTCNN |
[
code
](
https://github.com/AITTSMD/MTCNN-Tensorflow
)
|-|
| YOLO-V3|
[
code
](
https://github.com/YunYang1994/tensorflow-yolov3
)
| 转换需要关闭NHWC->NCHW的优化,见
[
文档Q2
](
FAQ.md
)
|
| FALSR |
[
code
](
https://github.com/xiaomi-automl/FALSR
)
| 需使用参数without_data_format_optimization |
| DCSCN |
[
code
](
https://modelzoo.co/model/dcscn-super-resolution
)
| 需使用参数without_data_format_optimization |
| Bert(albert) |
[
code
](
https://github.com/google-research/albert#pre-trained-models
)
| 需使用参数without_data_format_optimization |
| Bert(chinese_L-12_H-768_A-12) |
[
code
](
https://github.com/google-research/bert#pre-trained-models
)
| 需使用参数without_data_format_optimization |
| Bert(multi_cased_L-12_H-768_A-12) |
[
code
](
https://github.com/google-research/bert#pre-trained-models
)
| 需使用参数without_data_format_optimization |
## Caffe
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录