当前位置:网站首页>Tensorflow模型整体构建流程
Tensorflow模型整体构建流程
2022-08-09 21:35:00 【phac123】
TF构造八股文
- Import: 导入相关的包
- train and test: 处理好训练与测试数据集,包括乱序等操作
- models.Sequential: 搭建网络模型
- model.compile: 设置优化算法,配置训练方法
- model.fit: 设置训练时的学习率,迭代次数,batch_size,对模型进行训练;
- model.summary:打印出网络结构和参数统计
简单实现
# 1. import
import tensorflow as tf
# 2. train and test
w = tf.Variable(tf.constant(5, dtype=tf.float32))
# 3. model.sequential
# 4. model.compile and 5. model.fit
lr = 0.2
epochs = 40
for epoch in range(epochs):
with tf.GradientTape() as tape:
loss = tf.square(w + 1) # 定义loss函数
grads = tape.gradient(loss, w) # 求loss对w的梯度
w.assign_sub(lr * grads)
print("After %s epoch, w is %f, loss is %f" % (epoch, w.numpy(), loss)) # 6. model.summary()
边栏推荐
- Install Mysql8.0 on windos, and solve the problem of re-login exception ERROR 1045 (28000)
- PMP每日一练 | 考试不迷路-8.9(包含敏捷+多选)
- 【双链表增删查改接口的实现】
- cad图纸怎么复制到word文档里面?Word里插CAD图怎么弄?
- mysql多表左链接查询
- 数独 | 回溯-7
- Referenced file contains errors 完美解决方法
- hdu 1333 Smith Numbers(暴力思路)
- Definition and Basic Operations of Sequence Tables
- 一千以内的水仙花数
猜你喜欢
CMake installation upgrade higher version
Install Mysql8.0 on windos, and solve the problem of re-login exception ERROR 1045 (28000)
一千以内的水仙花数
小黑leetcode之旅:94. 二叉树的中序遍历(补充Morris 中序遍历)
Ankerui supports Ethernet communication, profibus communication embedded energy meter APM guiding technical requirements-Susie Week
fixed investment fund
SQL语句及索引的优化
How are data integration APIs key to enterprise digital transformation?
What are the benefits of enterprise data integration?How do different industries solve the problem of data access?
微软word怎么转换成pdf文件?微软word转换为pdf格式的方法
随机推荐
Deceptive Dice(期望计算)
安科瑞支持以太网通讯、profibus通讯嵌入式电能表APM指导性技术要求-Susie 周
URL Protocol 网页打开应用程序
抽象类 or 接口
哪款C语言编译器(IDE)适合初学者?
Hessian Matrix 海森矩阵
Word第一页不要页眉怎么设置?设置Word首页不要页眉方法教程
leetcode: the Kth largest element in the array
Cholesterol-PEG-Thiol, CLS-PEG-SH, Cholesterol-PEG-Sulfhydryl for improved solubility
DSPE-PEG-Silane,DSPE-PEG-SIL,磷脂-聚乙二醇-硅烷修饰二氧化硅颗粒用
6个规则去净化你的代码
LeetCode Daily Question (321. Create Maximum Number)
Don't use array.length-1 to get the last item of the array
人人都可以DIY的大玩具,宏光MINIEV GAMEBOY产品力强,出行新装备
PHP 二维数组根据某个字段排序
韩国网络安全体系特征与发展前景
POWER SOURCE ETA埃塔电源维修FHG24SX-U概述
基于网络数据流的未知密码协议逆向分析
DSPE-PEG-Azide, DSPE-PEG-N3, phospholipid-polyethylene glycol-azide can react directly with DBCO
buuctf (Adventure 2)