当前位置:网站首页>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()
边栏推荐
- 小黑leetcode清爽雨天之旅,刚吃完宇飞牛肉面、麻辣烫和啤酒:112. 路径总和
- 什么是源文件?
- Byte side: Can TCP and UDP use the same port?
- DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine reduce the immunogenicity of peptides
- mysql多表左链接查询
- [Graphic and textual] How to reinstall Win7 system
- MySQL笔记-06 基础SQL操作
- Don't tell me to play, I'm taking the PMP exam: what you need to know about choosing an institution for the PMP exam
- Excel如何打出正负号?Excel打出正负号的方法
- 【Efficient Tools】Remote Control Software ToDesk (Favorites)
猜你喜欢

URL Protocol 网页打开应用程序
![[Generic Programming] Full Detailed Explanation of Templates](/img/9d/7864f999cb2e4edda2ee7723558135.png)
[Generic Programming] Full Detailed Explanation of Templates

What to do if Windows 11 can't find Internet Explorer

Ankerui supports Ethernet communication, profibus communication embedded energy meter APM guiding technical requirements-Susie Week

数据集成API如何成为企业数字化转型的关键?

Excel如何打出正负号?Excel打出正负号的方法

数独 | 回溯-7

编程时请选择正确的输入法,严格区分中英文

抽象类 or 接口

安科瑞无线物联网智能电表ADW300指导性技术要求-Susie 周
随机推荐
【随笔】致19期的小伙伴们
DSPE-PEG-PDP,DSPE-PEG-OPSS,磷脂-聚乙二醇-巯基吡啶可减少肽的免疫原性
痛击面试官 CURD系统也能做出技术含量
威纶通触摸屏制作自定义弹出窗口的具体方法(3种)
cadence中复制一部分PCB到另一个PCB中去
Deceptive Dice(期望计算)
Word怎么设置图片衬于文字下方?两种方法教你设置Word图片衬于文字下方
Puyuan Jingdian turned losses into profits in the first half of the year, and high-end products continued to develop!Are you optimistic about "Huawei" in the instrument industry?
字节一面:TCP 和 UDP 可以使用同一个端口吗?
哪款C语言编译器(IDE)适合初学者?
Simulation of Water Temperature Control System Based on Fuzzy PID Controller
DSPE-PEG-Azide,DSPE-PEG-N3,磷脂-聚乙二醇-叠氮可和DBCO直接反应
leetcode: the Kth largest element in the array
Jmeter 使用正则表达式提取器将返回值全部保存到一个文件中
Cholesterol-PEG-Thiol, CLS-PEG-SH, Cholesterol-PEG-Sulfhydryl for improved solubility
NetCore路由的Endpoint模式
mysql配置参数详解[通俗易懂]
DSPE-PEG-Silane,DSPE-PEG-SIL,磷脂-聚乙二醇-硅烷修饰二氧化硅颗粒用
Byte side: Can TCP and UDP use the same port?
基于网络数据流的未知密码协议逆向分析