提交 9828c2c7 编写于 作者: M Macrobull

Merge remote-tracking branch 'upstream/master'

......@@ -8,6 +8,8 @@ X2Paddle支持将Caffe和TensorFlow模型转至PaddlePaddle模型,同时我们
任何使用问题均可通过[ISSUE](https://github.com/PaddlePaddle/X2Paddle/issues)的方式及时反馈,或者也可直接通过pull request的方式一起更新代码和文档。
> **目前X2Paddle主要支持CV部分模型,对于NLP模型暂未支持。**
## [caffe2fluid](caffe2fluid)
1. 支持将Caffe模型转至PaddlePaddle fluid可加载预测模型
2. 提供Caffe-PaddlePaddle常用API的对比文档[[doc](caffe2fluid/doc)]
......
......@@ -69,7 +69,23 @@ bash tools/diff.sh alexnet ../../alexnet.prototxt \
2. 添加`import mylayer``kaffe/custom_layers/__init__.py`
3. 准备你的pycaffe作为你的定制版本(与以前的env准备相同)
> 选择一:编译你自己的caffe.proto来代替proto/caffe.proto
> 选择一:
1. 编译你自己的caffe.proto来代替proto/caffe.proto
2. 修改./kaffe/caffe/resolver.py
```python
try:
# Try to import PyCaffe first
import caffe
self.caffe = caffe
except ImportError:
# Fall back to the protobuf implementation
self.caffepb = import_caffepb()
show_fallback_warning()
# 将上述代码替换为下列代码:
self.caffepb = import_caffepb()
show_fallback_warning()
```
> 选择二:更换你的pycaffe到特定的版本
4. 按照之前步骤,将Caffe模型转换为PaddlePaddle模型
......
......@@ -72,7 +72,22 @@ In the model conversion, when encounter an unsupported custom layer, users can a
2. Add ```import mylayer``` to `kaffe/custom_layers/__init__.py`
3. Prepare your pycaffe as your customized version(same as previous env prepare)
- (option1) replace `proto/caffe.proto` with your own caffe.proto and compile it
- (option1)
1. replace `proto/caffe.proto` with your own caffe.proto and compile it
2. modify the ./kaffe/caffe/resolver.py
```python
try:
# Try to import PyCaffe first
import caffe
self.caffe = caffe
except ImportError:
# Fall back to the protobuf implementation
self.caffepb = import_caffepb()
show_fallback_warning()
# replace the above code with:
self.caffepb = import_caffepb()
show_fallback_warning()
```
- (option2) change your `pycaffe` to the customized version
4. Convert the Caffe model to Fluid model
......
......@@ -51,8 +51,8 @@ layer {
top: "out3"
slice_param {
axis: 1 # 使用-1效果相同
alice_point: 1
alice_point: 2
slice_point: 1
slice_point: 2
}
}
# 输出3个数组,第一个shape:(2,1),第二个shape:(2,1),第三个shape:(2,4)
......
......@@ -172,7 +172,7 @@ def load_model(exe, place, net_file, net_name, net_weight, debug):
def get_shape(fluid, program, name):
for var in program.list_vars():
if var.name == 'data':
if var.type == 'Input':
return list(var.shape[1:])
raise ValueError('not found shape for input layer[%s], '
......
......@@ -49,7 +49,7 @@ if [[ -z $PYTHON ]];then
PYTHON=`which python`
fi
$PYTHON ../../convert.py \
$proto_file \
--npy_path $proto_file \
--caffemodel $caffemodel_file \
--data-output-path $weight_file\
--code-output-path $net_file
......
import os
import sys
import subprocess
SHARED_CAFFE_RESOLVER = None
......@@ -9,6 +10,10 @@ def import_caffepb():
p = os.path.dirname(p)
p = os.path.join(p, '../../proto')
sys.path.insert(0, p)
pb_version = subprocess.getstatusoutput('protoc --version')[1]
ver_str = pb_version.split(' ')[-1].replace('.', '')
ver_int = int(ver_str)
assert vaer_int >= 360, 'The version of protobuf must be larger than 3.6.0!'
import caffe_pb2
return caffe_pb2
......
......@@ -49,13 +49,13 @@ def detectionoutput_layer(inputs,
pbv = fluid.layers.reshape(x=pbv, shape=[-1, 4])
mbox_loc = inputs[0]
mbox_loc = fluid.layers.reshape(
x=mbox_loc, shape=[-1, mbox_conf_flatten.shape[1], 4])
x=mbox_loc, shape=[0, mbox_conf_flatten.shape[1], 4])
default = {"nms_threshold": 0.3, "top_k": 10, "eta": 1.0}
fields = ['eta', 'top_k', 'nms_threshold']
for f in default.keys():
if not nms_param.has_key(f):
if f not in nms_param:
nms_param[f] = default[f]
nmsed_outs = fluid.layers.detection_output(
......
......@@ -2,7 +2,7 @@
more info can be found here: http://caffe.berkeleyvision.org/tutorial/layers/flatten.html
"""
from .register import register
from functools import reduce
def flatten_shape(input_shape, axis=1, end_axis=-1):
""" calculate the output shape of this layer using input shape
......@@ -29,6 +29,8 @@ def flatten_shape(input_shape, axis=1, end_axis=-1):
% (start_axis, end_axis)
output_shape = input_shape[0:start_axis]
flat_sz = reduce(lambda a, b: a * b, input_shape[start_axis:end_axis])
if flat_sz < 0:
flat_sz = -1
output_shape += [flat_sz]
output_shape += input_shape[end_axis:-1]
......@@ -52,9 +54,8 @@ def flatten_layer(input, name, axis=1, end_axis=-1):
input_shape = list(input.shape)
if input_shape[0] == -1:
input_shape[0] = 1
input_shape[0] = 0
output_shape = flatten_shape(input_shape, axis=axis, end_axis=end_axis)
output_shape[0] = -1
else:
output_shape = flatten_shape(input_shape, axis=axis, end_axis=end_axis)
......
......@@ -2,6 +2,7 @@
more info can be found here: http://caffe.berkeleyvision.org/tutorial/layers/reshape.html
"""
from .register import register
from functools import reduce
def import_fluid():
......@@ -61,43 +62,6 @@ def reshape_shape(input_sp, shape, axis=0, num_axes=-1):
assert len(output_shape) == num_axes_retained + num_new_axes,\
"[Reshape]invalid dims of output shape[%s]" % (str(output_shape))
inferred_axis = -1
copy_axes = []
constant_count = 1
for i in range(num_new_axes):
top_dim = shape['dim'][i]
if top_dim == 0:
copy_axes.append(i)
copy_axis_index = start_axis + i
output_shape[copy_axis_index] = input_shape[copy_axis_index]
elif top_dim == -1:
assert inferred_axis == -1, "[Reshape]new shape contains multiple -1 dims"
inferred_axis = i
else:
constant_count *= top_dim
if inferred_axis >= 0:
explicit_count = constant_count
l = input_shape[0:start_axis]
if len(l) > 0:
explicit_count *= count(l)
l = input_shape[end_axis:]
if len(l) > 0:
explicit_count *= count(l)
for i in range(len(copy_axes)):
explicit_count *= output_shape[start_axis + copy_axes[i]]
assert input_count % explicit_count == 0, "[Reshape]botom count[%d] "\
"must be divisible by product of the specified dimensions[%d] "\
% (input_count, explicit_count)
output_shape[start_axis + inferred_axis] = input_count / explicit_count
output_count = count(output_shape)
assert output_count == input_count, "[Reshape]output count[%d] must match input count[%d]" % (
output_count, input_count)
return output_shape
......@@ -115,19 +79,16 @@ def reshape_layer(input, name, shape, axis=0, num_axes=-1):
output (variable): output variable for this layer
"""
fluid = import_fluid()
input_shape = list(input.shape)
if input_shape[0] == -1:
input_shape[0] = 1
input_shape[0] = 0
output_shape = reshape_shape(input_shape, shape, axis, num_axes)
output_shape[0] = -1
else:
output_shape = reshape_shape(input_shape, shape, axis, num_axes)
output = fluid.layers.reshape(input, shape=output_shape, name=name)
return output
register(kind='Reshape', shape=reshape_shape, layer=reshape_layer)
......@@ -103,7 +103,7 @@ class Network(object):
place = self.paddle_env['place']
exe = self.paddle_env['exe']
data_dict = np.load(data_path).item()
data_dict = np.load(data_path, allow_pickle=True).item()
for op_name in data_dict:
if op_name == 'caffe2fluid_name_trace':
self.name_trace = data_dict[op_name]
......@@ -441,7 +441,7 @@ class Network(object):
need_transpose = True
if need_transpose:
in_order = range(dims)
in_order = list(range(dims))
in_order.remove(axis)
in_order.append(axis)
input = fluid.layers.transpose(
......
......@@ -3,6 +3,9 @@ from collections import namedtuple
from .errors import KaffeError
Tensor5DShape = namedtuple('Tensor5DShape',
['batch_size', 'data1', 'daat2', 'data3', 'data4'])
Tensor4DShape = namedtuple('Tensor4DShape',
['batch_size', 'channels', 'height', 'width'])
......
......@@ -103,6 +103,8 @@ tensorflow2fluid在如下tensorflow模型上测试了模型转换前后的diff
| | ResNet V1 50 | [code](https://github.com/tensorflow/models/blob/master/research/slim/nets/resnet_v1.py) | 1.31E-06 |
| | ResNet V1 101 | [code](https://github.com/tensorflow/models/blob/master/research/slim/nets/resnet_v1.py) | 4.74E-07 |
| | Inception V3 | [code](https://github.com/tensorflow/models/blob/master/research/slim/nets/inception_v3.py) | 1.55E-04 |
| | NASNet_Large | [code](https://github.com/tensorflow/models/blob/master/research/slim/nets/nasnet/nasnet.py) | - |
| | PNASNet_Large | [code](https://github.com/tensorflow/models/blob/master/research/slim/nets/nasnet/pnasnet.py) | - |
| 目标检测 | YOLO-Small | [code](https://github.com/gliese581gg/YOLO_tensorflow) | 1.40E-06 |
| | YOLO-V3 | [code](https://github.com/mystic123/tensorflow-yolo-v3) | 6.20E-04 |
| 语义分割 | Unet | [code](https://github.com/jakeret/tf_unet) | 4.17E-07 |
......
此差异已折叠。
......@@ -4,8 +4,8 @@
| TensorFlow接口 | PaddlePaddle接口 |
|--------------------------|-------------------------------------------------|
|[tf.math.less_equal](https://www.tensorflow.org/api_docs/python/tf/math/less_equal)|运算符`<=`|
|[tf.math.greater](https://www.tensorflow.org/api_docs/python/tf/math/greater)|运算符`>`|
|[tf.math.greater_equal](https://www.tensorflow.org/api_docs/python/tf/math/greater_equal)|运算符`>=`|
|[tf.math.equal](https://www.tensorflow.org/api_docs/python/tf/math/equal)|运算符`==`[paddle.fluid.layers.equal](http://paddlepaddle.org/documentation/docs/zh/1.3/api_cn/layers_cn.html#permalink-7-equal) |
|[tf.math.less](https://www.tensorflow.org/api_docs/python/tf/math/less)|运算符`<`[paddle.fluid.layers.less_than](http://paddlepaddle.org/documentation/docs/zh/1.3/api_cn/layers_cn.html#permalink-11-less_than) |
|[tf.math.less_equal](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/less_equal)|运算符`<=`|
|[tf.math.greater](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/greater)|运算符`>`|
|[tf.math.greater_equal](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/greater_equal)|运算符`>=`|
|[tf.math.equal](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/equal)|运算符`==`[paddle.fluid.layers.equal](http://paddlepaddle.org/documentation/docs/zh/1.3/api_cn/layers_cn.html#permalink-7-equal) |
|[tf.math.less](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/less)|运算符`<`[paddle.fluid.layers.less_than](http://paddlepaddle.org/documentation/docs/zh/1.3/api_cn/layers_cn.html#permalink-11-less_than) |
\ No newline at end of file
## tf.case
### [tf.case](https://www.tensorflow.org/api_docs/python/tf/case)
### [tf.case](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/case)
```python
tf.case(
......
## tf.clip_by_global_norm
### [tf.clip_by_global_norm](https://www.tensorflow.org/api_docs/python/tf/clip_by_global_norm)
### [tf.clip_by_global_norm](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/clip_by_global_norm)
```python
tf.clip_by_global_norm(
......
## tf.clip_by_norm
### [tf.clip_by_norm](https://www.tensorflow.org/api_docs/python/tf/clip_by_norm)
### [tf.clip_by_norm](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/clip_by_norm)
``` python
tf.clip_by_norm(
......
## tf.contrib.layers.flatten
### [tf.contrib.layers.flatten](https://www.tensorflow.org/api_docs/python/tf/contrib/layers/flatten)
### [tf.contrib.layers.flatten](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/contrib/layers/flatten)
```python
tf.contrib.layers.flatten(
......
## tf.expand_dims
### [tf.expand_dims](https://www.tensorflow.org/api_docs/python/tf/expand_dims)
### [tf.expand_dims](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/expand_dims)
``` python
tf.expand_dims(
input,
......@@ -40,4 +39,3 @@ out = fluid.layers.unsqueeze(t, [-1])
# 输出 tensor out 的 shape 为[1, 1,3, 4]
out = fluid.layers.unsqueeze(t, [0, 1])
```
\ No newline at end of file
## tf.image.non_max_suppression
### [tf.image.non_max_suppression](https://www.tensorflow.org/api_docs/python/tf/image/non_max_suppression)
### [tf.image.non_max_suppression](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/image/non_max_suppression)
``` python
tf.image.non_max_suppression(
boxes,
......
## tf.image.resize_images
### [tf.image.resize_images](https://www.tensorflow.org/api_docs/python/tf/image/resize_images)
### [tf.image.resize_images](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/image/resize_images)
``` python
tf.image.resize_images(
images,
......@@ -39,4 +38,3 @@ inputs = fluid.layers.data(dtype='float32', shape=[3, 300, 300], name='inputs')
# 输出shape为[3, 400, 500]
outputs = fluid.layers.image_reisze(inputs, [400, 500])
```
\ No newline at end of file
## tf.layers.conv2d
### [tf.layers.conv2d](https://www.tensorflow.org/api_docs/python/tf/layers/conv2d)
### [tf.layers.conv2d](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/layers/conv2d)
``` python
tf.layers.conv2d(
inputs,
......@@ -73,7 +72,7 @@ pad_right = pad_size - pad_left
PaddlePaddle:`padding`参数表示在输入图像四周padding的size大小。
#### 参数差异
TensorFlow:深度可分离卷积使用[tf.layers.separable_conv2d](https://www.tensorflow.org/api_docs/python/tf/layers/separable_conv2d)接口;
TensorFlow:深度可分离卷积使用[tf.layers.separable_conv2d](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/layers/separable_conv2d)接口;
PaddlePaddle: 使用`paddle.fluid.layers.conv2d`,可参考
[PaddlePaddle对卷积的说明文档](http://paddlepaddle.org/documentation/docs/zh/1.4/api_guides/low_level/layers/conv.html), 同时也可参考[tf.nn.separable_conv2d](https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.separable_conv2d.md)中的代码示例。
......
## tf.layers.dense
### [tf.layers.dense](https://www.tensorflow.org/api_docs/python/tf/layers/dense)
### [tf.layers.dense](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/layers/dense)
``` python
tf.layers.dense(
inputs,
......
## tf.losses.mean_and_squared_error
### [tf.losses.mean_and_squared_error](https://www.tensorflow.org/api_docs/python/tf/losses/mean_squared_error)
### [tf.losses.mean_and_squared_error](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/losses/mean_squared_error)
``` python
tf.losses.mean_squared_error(
......
## tf.losses.sigmoid_cross_entropy
### [tf.losses.sigmoid_cross_entropy](https://www.tensorflow.org/api_docs/python/tf/losses/sigmoid_cross_entropy)
### [tf.losses.sigmoid_cross_entropy](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/losses/sigmoid_cross_entropy)
```python
tf.losses.sigmoid_cross_entropy(
......
## tf.math.is_finite
### [tf.math.is_finite](https://www.tensorflow.org/api_docs/python/tf/math/is_finite)
### [tf.math.is_finite](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/is_finite)
``` python
tf.math.is_finite(
x,
......
## tf.math.rsqrt
### [tf.math.rsqrt](https://www.tensorflow.org/api_docs/python/tf/math/rsqrt)
### [tf.math.rsqrt](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/rsqrt)
``` python
tf.math.rsqrt(
x,
......
## tf.matmul
### [tf.matmul](https://www.tensorflow.org/api_docs/python/tf/linalg/matmul)
### [tf.matmul](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/linalg/matmul)
``` python
tf.matmul(
a,
......
## tf.nn.avg_pool
### [tf.nn.avg_pool](https://www.tensorflow.org/versions/r1.10/api_docs/python/tf/nn/avg_pool)
### [tf.nn.avg_pool](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/avg_pool)
``` python
tf.nn.avg_pool(
......
## tf.nn.bidirectional_dynamic_rnn
### [tf.nn.bidirectional_dynamic_rnn](https://www.tensorflow.org/api_docs/python/tf/nn/bidirectional_dynamic_rnn)
### [tf.nn.bidirectional_dynamic_rnn](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/bidirectional_dynamic_rnn)
```python
tf.nn.bidirectional_dynamic_rnn(
......
## tf.nn.conv2d
### [tf.nn.conv2d](https://www.tensorflow.org/api_docs/python/tf/nn/conv2d)
### [tf.nn.conv2d](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/conv2d)
```python
tf.nn.conv2d(
......
## tf.nn.conv2d_transpose
### [tf.nn.conv2d_transpose](https://www.tensorflow.org/api_docs/python/tf/nn/conv2d_transpose)
### [tf.nn.conv2d_transpose](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/conv2d_transpose)
``` python
tf.nn.conv2d_transpose(
value,
......
## tf.nn.conv3d_transpose
### [tf.nn.conv3d_transpose](https://www.tensorflow.org/api_docs/python/tf/nn/conv3d_transpose)
### [tf.nn.conv3d_transpose](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/conv3d_transpose)
``` python
tf.nn.conv3d_transpose(
value,
......
## tf.nn.depthwise_conv2d
### [tf.nn.depthwise_conv2d](https://www.tensorflow.org/api_docs/python/tf/nn/depthwise_conv2d)
### [tf.nn.depthwise_conv2d](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/depthwise_conv2d)
```python
tf.nn.depthwise_conv2d(
......
## tf.dropout
### [tf.nn.dropout](https://www.tensorflow.org/api_docs/python/tf/nn/dropout)
### [tf.nn.dropout](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/dropout)
``` python
tf.nn.dropout(
x,
......
## tf.nn.dynamic_rnn
### [tf.nn.dynamic_rnn](https://www.tensorflow.org/api_docs/python/tf/nn/dynamic_rnn)
### [tf.nn.dynamic_rnn](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/dynamic_rnn)
``` python
tf.nn.dynamic_rnn(
cell,
......
## tf.nn.l2_normalize
### [tf.nn.l2_normalize](https://www.tensorflow.org/api_docs/python/tf/math/l2_normalize)
### [tf.nn.l2_normalize](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/l2_normalize)
```python
tf.math.l2_normalize(
......
## tf.nn.lrn
### [tf.nn.lrn](https://www.tensorflow.org/api_docs/python/tf/nn/local_response_normalization)
### [tf.nn.lrn](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/local_response_normalization)
```python
tf.nn.local_response_normalization(
......
## tf.nn.max_pool
### [tf.nn.max_pool](https://www.tensorflow.org/api_docs/python/tf/nn/max_pool)
### [tf.nn.max_pool](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/max_pool)
``` python
tf.nn.max_pool(
......
## tf.math.reduce_logsumexp
### [tf.math.reduce_logsumexp](https://www.tensorflow.org/api_docs/python/tf/math/reduce_logsumexp)
### [tf.math.reduce_logsumexp](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/reduce_logsumexp)
``` python
tf.math.log_softmax(
logits,
......
## tf.contrib.rnn.GRUCell
### [tf.contrib.rnn.GRUCell](https://www.tensorflow.org/api_docs/python/tf/nn/rnn_cell/GRUCell)
### [tf.nn.rnn.GRUCell](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/rnn_cell/GRUCell)
```python
tf.contrib.rnn.GRUCell(
__init__(
num_units,
activation=None,
reuse=None,
......@@ -13,7 +13,6 @@ tf.contrib.rnn.GRUCell(
dtype=None,
**kwargs
)
```
### [paddle.fluid.layers.gru_unit](http://paddlepaddle.org/documentation/docs/zh/1.4/api_cn/layers_cn.html#gru-unit)
......
## tf.nn.rnn_cell.LSTMCell
### [tf.nn.rnn_cell.LSTMCell](https://www.tensorflow.org/api_docs/python/tf/nn/rnn_cell/LSTMCell)
### [tf.nn.rnn_cell.LSTMCell](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/rnn_cell/LSTMCell)
```python
tf.nn.rnn_cell.LSTMCell(
......
## tf.nn.rnn_cell.MultiRNNCell
### [tf.nn.rnn_cell.MultiRNNCell](https://www.tensorflow.org/api_docs/python/tf/nn/rnn_cell/MultiRNNCell)
### [tf.nn.rnn_cell.MultiRNNCell](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/rnn_cell/MultiRNNCell)
```python
tf.nn.rnn_cell.MultiRNNCell(
__init__(
cells,
state_is_tuple=True
)
......
## tf.nn.separable_conv2d
### [tf.nn.separable_conv2d](https://www.tensorflow.org/api_docs/python/tf/nn/separable_conv2d)
### [tf.nn.separable_conv2d](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/separable_conv2d)
``` python
tf.nn.separable_conv2d(
input,
......
## tf.nn.softmax_cross_entropy_with_logits
### [tf.nn.rnn_cell.MultiRNNCell](https://www.tensorflow.org/api_docs/python/tf/nn/softmax_cross_entropy_with_logits)
### [tf.nn.rnn_cell.MultiRNNCell](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/softmax_cross_entropy_with_logits)
```python
tf.nn.softmax_cross_entropy_with_logits(
......@@ -20,7 +20,8 @@ paddle.fluid.layers.softmax_with_cross_entropy(
soft_label=False,
ignore_index=-100,
numeric_stable_mode=False,
return_softmax=False
return_softmax=False,
axis=-1
)
```
......
## tf.nn.top_k
### [tf.nn.top_k](https://www.tensorflow.org/api_docs/python/tf/nn/top_k)
### [tf.nn.top_k](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/top_k)
``` python
tf.math.top_k(
input,
......
## tf.one_hot
### [tf.one_hot](https://www.tensorflow.org/api_docs/python/tf/one_hot)
### [tf.one_hot](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/one_hot)
``` python
tf.one_hot(
indices,
......
## tf.pad
### [tf.pad](https://www.tensorflow.org/api_docs/python/tf/pad)
### [tf.pad](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/pad)
``` python
tf.pad(
tensor,
......
## tf.placeholder
### [tf.placeholder](https://www.tensorflow.org/api_docs/python/tf/placeholder)
### [tf.placeholder](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/placeholder)
``` python
tf.placeholder(
dtype,
......
## tf.pow
### [tf.pow](https://www.tensorflow.org/api_docs/python/tf/math/pow)
### [tf.pow](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/pow)
```python
tf.math.pow(
......
## tf.print
### [tf.print](https://www.tensorflow.org/api_docs/python/tf/print)
### [tf.print](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/print)
```python
tf.print(
......
## tf.reshape
### [tf.reshape](https://www.tensorflow.org/api_docs/python/tf/reshape)
### [tf.reshape](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/reshape)
``` python
tf.reshape(
tensor,
......@@ -38,4 +37,3 @@ out = fluid.layers.reshape(t, [-1, 6])
# 输出 tensor out 的 shape 为[3, 2, 2]
out = fluid.layers.reshape(t, [0, 2, 2])
```
\ No newline at end of file
## tf.reverse_sequence
### [tf.reverse_sequence](https://www.tensorflow.org/api_docs/python/tf/reverse_sequence)
### [tf.reverse_sequence](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/reverse_sequence)
```python
tf.reverse_sequence(
......
## tf.scatter_update
### [tf.scatter_update](https://www.tensorflow.org/api_docs/python/tf/scatter_update)
### [tf.scatter_update](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/scatter_update)
```python
tf.scatter_update(
......@@ -19,7 +19,8 @@ paddle.fluid.layers.scatter(
input,
index,
updates,
name=None
name=None,
overwrite=True
)
```
......@@ -32,7 +33,7 @@ PaddlePaddle:`index`只支持1-d Variable。
#### 其他
Tensorflow:`updates`支持numpy-style broadcasting;
PaddlePaddle:`updates`要求其rank与`input`相同,同时`updates.shape[0]`等于`index.shape[0]`
PaddlePaddle:`updates`要求其rank与`input`相同,同时`updates.shape[0]`等于`index.shape[0]`此外`overwrite`参数提供了当存在重复index时,两种不同的梯度更新策略。
### 代码示例
```
......
## tf.slice
### [tf.slice](https://www.tensorflow.org/api_docs/python/tf/slice)
### [tf.slice](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/slice)
``` python
tf.slice(
input_,
......
## tf.split
### [tf.split](https://www.tensorflow.org/api_docs/python/tf/split)
### [tf.split](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/split)
```python
tf.split(
......
## tf.squared_difference
### [tf.squared_diffenrece](https://www.tensorflow.org/api_docs/python/tf/math/squared_difference)
### [tf.squared_diffenrece](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/math/squared_difference)
``` python
tf.math.squared_difference(
x,
......
## tf.stop_gradient
### [tf.stop_gradient](https://www.tensorflow.org/api_docs/python/tf/stop_gradient)
### [tf.stop_gradient](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/stop_gradient)
``` python
tf.stop_gradient(
input,
......
## tf.while_loop
### [tf.while_loop](https://www.tensorflow.org/api_docs/python/tf/while_loop)
### [tf.while_loop](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/while_loop)
```python
tf.while_loop(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册