tensorflow为Google主推的深度学习框架,在更新至2.0版本后,tensorflow内部中集合了keras,变得更加简单易用。
而 paddlepaddle为百度推出的深度学习框架,为了推广paddlepaddle,百度提供了免费的算力(Tesla V100,这个还是蛮给力的,google的colab虽然免费提供了Tesla T4,之前是Tesla K80,但还是差点意思,难得白嫖百度,嘻嘻)及相关的项目和比赛。在一些特定的领域,为工业界提供了相对成熟的方案,如PaddleOCR、PaddleDetection。
目前刚刚接触paddlepaddle,在此初步记录两个框架的差异(待更新)
1.
先以最简单的tensor向量相加为例
tensorflow
import tensorflow as tf
a=tf.constant(5.)
b=tf.constant(7.)
c=a+b
print(c)
paddlepaddle
import paddle.fluid as fluid
import numpy
a = fluid.data(name="a",shape=[1],dtype='float32')
b = fluid.data(name="b",shape=[1],dtype='float32')
result = fluid.layers.elementwise_add(a,b)
# 定义执行器,并且制定执行的设备为CPU
cpu = fluid.core.CPUPlace()
exe = fluid.Executor(cpu)
exe.run(fluid.default_startup_program())
x = numpy.array([5]).astype("float32")
y = numpy.array([7]).astype("float32")
outs = exe.run(
feed={'a':x,'b':y},
fetch_list=[result])
# 打印输出结果,[array([12.], dtype=float32)]
print( outs )
在 Paddle 中存在三种 Variable,
基本等价于 Tensor
a.模型中的可学习参数:
fluid.layers.create_parameter
b.占位 Variable:
fluid.data
c. 常量 Variable
fluid.layers.fill_constant
参考链接:https://www.paddlepaddle.org.cn/documentation/docs/zh/beginners_guide/basic_concept/variable.html