Tensorflow2.0 -搭建模型的多种方式

Tensorflow1.0 搭建模型

一、搭建深度学习模型的区别(背过!!!)

Tensorflow1.x

Tensorflow1.x最重要的在于Graph的概念,个人认为搭建相对较为麻烦,但是tf1.x也较为灵活。

Tensorflow2.x

Tensorflow2.x兼容keras,非常好用。

对于Tensorflow1.0

        step 01 :准备输入数据

        step 02:定义输入PlaceHolder

        step 03:搭建模型

        step 04:定义损失函数及优化器

        step 05:初始化所有变量

        step 06:创建会话session

        step 07:传参计算session.run()

对于Tensorflow 2.0

        step 01 :准备输入数据

         step 02:定义输入PlaceHolder

        step 03:搭建模型

        step 04:定义损失函数及优化器

        step 05:初始化所有变量

        step 06:创建会话session

        step 07:传参计算model()

二、TensorFlow 2.0 相比于TensorFlow 1.0 的其他区别

1. TensorFlow 2.0 动态图机制默认开启,方便开发者调试。

        TensorFlow 1.0 默认是静态图,需要手动开启动态图。

2. tf.keras模块上的区别

  •  Keras是对TensorFlow的更高一层封装,简化了TensorFlow的使用。

  • TensorFlow 2.0中搭建网络,官方推荐使用Keras提供的方法。有两种搭建风格:Keras Function API (tf1中搭建模型的风格)和 Model Subclassing API(类似于Pytorch中搭建模型的风格)

  • TensorFlow 2.0 删除了重复、废弃的API。而在TensorFlow 1.0,同一个功能可以找到多个API实现,会给开发者造成疑惑。

3.在TensorFlow 2.0 中使用 @tf.function 装饰器,构造高效的Python代码

TesorFlow2.0推荐使用tf.keras,tf.data 等高层库:

  • 用Eager模式搭建原型
  • 用tf.data处理数据
  • 用tf.feature_column提取特征
  • 用tf.keras搭建模型
  • 用tf.saved_model打包模型

TF1.0 搭建模型


import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import os
os.environ["CUDA_DEVICE_ORDER"] = "0,1"
 
 
mnist = input_data.read_data_sets("MNIS
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值