ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.8 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://blog.csdn.net/hustqb/article/details/80222055 |
| Last Crawled | 2026-03-16 10:26:45 (25 days ago) |
| First Indexed | 2018-05-07 14:34:33 (7 years ago) |
| HTTP Status Code | 200 |
| Meta Title | 比官方更简洁的Tensorflow入门教程-CSDN博客 |
| Meta Description | 文章浏览阅读10w+次,点赞64次,收藏388次。本文介绍TensorFlow的基本概念,包括数据流图、张量、变量和占位符等,并通过实例展示如何构建和训练神经网络。 |
| Meta Canonical | null |
| Boilerpipe Text | 声明:
参考自
Python TensorFlow Tutorial – Build a Neural Network
,本文简化了文字部分
文中有很多到官方文档的链接,毕竟有些官方文档是中文的,而且写的很好。
Tensorflow入门
资源:
付费tensorflow教程
Tensorflow graphs
Tensorflow是基于graph的并行计算模型。关于graph的理解可以参考
官方文档
。举个例子,计算
a
=
(
b
+
c
)
∗
(
c
+
2
)
a=(b + c) * (c + 2)
a
=
(
b
+
c
)
∗
(
c
+
2
)
,我们可以将算式拆分成一下:
d = b + c
e = c + 2
a = d * e
1
2
3
转换成graph后的形式为:
[外链图片转存失败(img-a63KWKIy-1565154313869)(http://adventuresinmachinelearning.com/wp-content/uploads/2017/03/Simple-graph-example.png)]
> 讲一个简单的算式搞成这样确实大材小用,但是我们可以通过这个例子发现:
d
=
b
+
c
和
e
=
c
+
2
是不相关的,也就是可以**并行计算**。对于更复杂的CNN和RNN,graph的并行计算的能力将得到更好的展现。
实际中,基于Tensorflow构建的三层(单隐层)神经网络如下图所示:
[外链图片转存失败(img-jDD9Cbqi-1565154313870)(http://adventuresinmachinelearning.com/wp-content/uploads/2017/03/TensorFlow-data-flow-graph.gif)] **Tensorflow data flow graph**
上图中,
圆形或方形的节点被称为node,在node中流动的数据流被称为张量(tensor)
。更多关于tensor的描述见
官方文档
。
0阶张量 == 标量
1阶张量 == 向量(一维数组)
2阶张量 == 二维数组
…
n阶张量 == n维数组
tensor与node之间的关系:
如果输入tensor的维度是
5000
×
64
5000 \times 64
5
0
0
0
×
6
4
,表示有5000个训练样本,每个样本有64个特征,则输入层必须有64个node来接受这些特征。
上图表示的三层网络包括:输入层(图中的input)、隐藏层(这里取名为ReLU layer表示它的激活函数是ReLU)、输出层(图中的Logit Layer)。
可以看到,每一层中都有相关tensor流入Gradient节点计算梯度,然后这些梯度tensor进入SGD Trainer节点进行网络优化(也就是update网络参数)。
Tensorflow正是通过graph表示神经网络,实现网络的并行计算,提高效率。下面我们将通过一个简单的例子来介绍TensorFlow的基础语法。
A Simple TensorFlow example
用Tensorflow计算
a
=
(
b
+
c
)
∗
(
c
+
2
)
a = (b + c) * (c + 2)
a
=
(
b
+
c
)
∗
(
c
+
2
)
,
1. 定义数据:
import
tensorflow
as
tf
# 首先,创建一个TensorFlow常量=>2
const
=
tf
.
constant
(
2.0
,
name
=
'const'
)
# 创建TensorFlow变量b和c
b
=
tf
.
Variable
(
2.0
,
name
=
'b'
)
c
=
tf
.
Variable
(
1.0
,
dtype
=
tf
.
float32
,
name
=
'c'
)
python
1
2
3
4
5
6
7
8
如上,TensorFlow中,使用
tf.constant()
定义常量,使用
tf.Variable()
定义变量。Tensorflow可以自动进行数据类型检测,比如:赋值2.0就默认为
tf.float32
,但最好还是显式地定义。更多关于TensorFlow数据类型的介绍查看
官方文档
。
2. 定义运算(也称TensorFlow operation):
# 创建operation
d
=
tf
.
add
(
b
,
c
,
name
=
'd'
)
e
=
tf
.
add
(
c
,
const
,
name
=
'e'
)
a
=
tf
.
multiply
(
d
,
e
,
name
=
'a'
)
python
1
2
3
4
发现了没,在TensorFlow中,
+
−
×
÷
+-\times \div
+
−
×
÷
都有其特殊的函数表示。实际上,TensorFlow定义了足够多的函数来表示所有的数学运算,当然也对部分数学运算进行了运算符重载,但保险起见,我还是建议你使用函数代替运算符。
**!!TensorFlow中所有的变量必须经过初始化才能使用,**初始化方式分两步:
定义初始化operation
运行初始化operation
# 1. 定义init operation
init_op
=
tf
.
global_variables_initializer
(
)
python
1
2
以上已经完成TensorFlow graph的搭建
,下一步即计算并输出。
运行graph需要先调用
tf.Session()
函数创建一个会话(session)。session就是我们与graph交互的handle。更多关于session的介绍见
官方文档
。
# session
with
tf
.
Session
(
)
as
sess
:
# 2. 运行init operation
sess
.
run
(
init_op
)
# 计算
a_out
=
sess
.
run
(
a
)
print
(
"Variable a is {}"
.
format
(
a_out
)
)
python
1
2
3
4
5
6
7
值得一提的是,TensorFlow有一个极好的可视化工具TensorBoard,详见
官方文档
。将上面例子的graph可视化之后的结果为:
[外链图片转存失败(img-kgV7Bu4I-1565154313870)(http://adventuresinmachinelearning.com/wp-content/uploads/2017/04/Simple-TensorFlow-graph.png)]
The TensorFlow placeholder
对上面例子的改进:使变量b可以接收任意值。TensorFlow中接收值的方式为占位符(placeholder),通过
tf.placeholder()
创建。
# 创建placeholder
b = tf.placeholder(tf.float32, [None, 1], name='b')
1
2
第二个参数值为[None, 1],其中None表示不确定,即不确定第一个维度的大小,第一维可以是任意大小。特别对应tensor数量(或者样本数量),输入的tensor数目可以是32、64…
现在,如果得到计算结果,需要在运行过程中feed占位符b的值,具体为将
a_out = sess.run(a)
改为:
a_out
=
sess
.
run
(
a
,
feed_dict
=
{
b
:
np
.
arange
(
0
,
10
)
[
:
,
np
.
newaxis
]
}
)
python
1
输出:
Variable a is [[ 3.]
[ 6.]
[ 9.]
[ 12.]
[ 15.]
[ 18.]
[ 21.]
[ 24.]
[ 27.]
[ 30.]]
1
2
3
4
5
6
7
8
9
10
A Neural Network Example
神经网络的例子,数据集为MNIST数据集。
1. 加载数据:
from
tensorflow
.
examples
.
tutorials
.
mnist
import
input_data
mnist
=
input_data
.
read_data_sets
(
"MNIST_data/"
,
one_hot
=
True
)
python
1
2
one_hot=True
表示对label进行one-hot编码,比如标签4可以表示为[0, 0, 0, 0, 1, 0, 0, 0, 0, 0]。这是神经网络输出层要求的格式。
Setting things up
2. 定义超参数和placeholder
# 超参数
learning_rate
=
0.5
epochs
=
10
batch_size
=
100
# placeholder
# 输入图片为28 x 28 像素 = 784
x
=
tf
.
placeholder
(
tf
.
float32
,
[
None
,
784
]
)
# 输出为0-9的one-hot编码
y
=
tf
.
placeholder
(
tf
.
float32
,
[
None
,
10
]
)
python
1
2
3
4
5
6
7
8
9
10
再次强调,[None, 784]中的None表示任意值,特别对应tensor数目。
3. 定义参数w和b
# hidden layer => w, b
W1
=
tf
.
Variable
(
tf
.
random_normal
(
[
784
,
300
]
,
stddev
=
0.03
)
,
name
=
'W1'
)
b1
=
tf
.
Variable
(
tf
.
random_normal
(
[
300
]
)
,
name
=
'b1'
)
# output layer => w, b
W2
=
tf
.
Variable
(
tf
.
random_normal
(
[
300
,
10
]
,
stddev
=
0.03
)
,
name
=
'W2'
)
b2
=
tf
.
Variable
(
tf
.
random_normal
(
[
10
]
)
,
name
=
'b2'
)
python
1
2
3
4
5
6
在这里,要了解全连接层的两个参数
w
和
b
都是需要随机初始化的,
tf.random_normal()
生成正态分布的随机数。
4. 构造隐层网络
# hidden layer
hidden_out = tf.add(tf.matmul(x, W1), b1)
hidden_out = tf.nn.relu(hidden_out)
1
2
3
上面代码对应于公式:
z
=
w
x
+
b
z = wx + b
z
=
w
x
+
b
h
=
r
e
l
u
(
z
)
h = relu(z)
h
=
r
e
l
u
(
z
)
5. 构造输出(预测值)
# 计算输出
y_ = tf.nn.softmax(tf.add(tf.matmul(hidden_out, W2), b2))
1
2
对于单标签多分类任务,输出层的激活函数都是
tf.nn.softmax()
。更多关于softmax的知识见
维基百科
。
6. BP部分—定义loss
损失为交叉熵,公式为
J
=
−
1
m
∑
i
=
1
m
∑
j
=
1
n
y
j
i
l
o
g
(
y
j
(
i
)
)
+
(
1
−
y
j
(
i
)
l
o
g
(
1
−
y
j
(
i
)
)
J=- \frac 1m \sum_{i=1}^m\sum_{j=1}^n y_j^{i}log(y_j^{(i)}) + (1 - y_j^{(i)}log(1-y_j^{(i)})
J
=
−
m
1
i
=
1
∑
m
j
=
1
∑
n
y
j
i
l
o
g
(
y
j
(
i
)
)
+
(
1
−
y
j
(
i
)
l
o
g
(
1
−
y
j
(
i
)
)
公式分为两步:
对n个标签计算交叉熵
对m个样本取平均
y_clipped
=
tf
.
clip_by_value
(
y_
,
1e
-
10
,
0.9999999
)
cross_entropy
=
-
tf
.
reduce_mean
(
tf
.
reduce_sum
(
y
*
tf
.
log
(
y_clipped
)
+
(
1
-
y
)
*
tf
.
log
(
1
-
y_clipped
)
,
axis
=
1
)
)
python
1
2
7. BP部分—定义优化算法
# 创建优化器,确定优化目标
optimizer = tf.train.GradientDescentOptimizer(learning_rate=learning_rate).minimize(cross_entropy)
1
2
TensorFlow中更多优化算法详见
官方文档
。
8. 定义初始化operation和准确率node
# init operator
init_op = tf.global_variables_initializer()
# 创建准确率节点
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
1
2
3
4
5
6
correct_predicion
会返回一个
m
×
1
m\times 1
m
×
1
的tensor,tensor的值为True/False表示是否正确预测。
Setting up the training
9. 开始训练
# 创建session
with
tf
.
Session
(
)
as
sess
:
# 变量初始化
sess
.
run
(
init_op
)
total_batch
=
int
(
len
(
mnist
.
train
.
labels
)
/
batch_size
)
for
epoch
in
range
(
epochs
)
:
avg_cost
=
0
for
i
in
range
(
total_batch
)
:
batch_x
,
batch_y
=
mnist
.
train
.
next_batch
(
batch_size
=
batch_size
)
_
,
c
=
sess
.
run
(
[
optimizer
,
cross_entropy
]
,
feed_dict
=
{
x
:
batch_x
,
y
:
batch_y
}
)
avg_cost
+=
c
/
total_batch
print
(
"Epoch:"
,
(
epoch
+
1
)
,
"cost = "
,
"{:.3f}"
.
format
(
avg_cost
)
)
print
(
sess
.
run
(
accuracy
,
feed_dict
=
{
x
:
mnist
.
test
.
images
,
y
:
mnist
.
test
.
labels
}
)
)
python
1
2
3
4
5
6
7
8
9
10
11
12
13
输出:
Epoch: 1 cost = 0.586
Epoch: 2 cost = 0.213
Epoch: 3 cost = 0.150
Epoch: 4 cost = 0.113
Epoch: 5 cost = 0.094
Epoch: 6 cost = 0.073
Epoch: 7 cost = 0.058
Epoch: 8 cost = 0.045
Epoch: 9 cost = 0.036
Epoch: 10 cost = 0.027
Training complete!
0.9787
1
2
3
4
5
6
7
8
9
10
11
12
13
通过TensorBoard可视化训练过程:
[外链图片转存失败(img-5NxdHJph-1565154313871)(
http://adventuresinmachinelearning.com/wp-content/uploads/2017/04/TensorBoard-increase-in-accuracy-NN.png
)] |
| Markdown | [](https://www.csdn.net/)
- [博客](https://blog.csdn.net/)
- [下载](https://download.csdn.net/)
- [社区](https://devpress.csdn.net/)
- [![]()GitCode](https://link.csdn.net/?target=https%3A%2F%2Fgitcode.com%3Futm_source%3Dcsdn_toolbar)
- [![]()GPU算力 ![]()](https://ai.csdn.net/)
- [更多]()
[会议](https://www.bagevent.com/event/9117243 "会议") [学习](https://edu.csdn.net/?utm_source=zhuzhantoolbar "高质量课程·大会云会员") [![]()InsCode](https://inscode.net/?utm_source=csdn_blog_top_bar "InsCode")
搜索
AI 搜索
[登录]()
登录后您可以:
- 复制代码和一键运行
- 与博主大V深度互动
- 解锁海量精选资源
- 获取前沿技术资讯
[立即登录]()
[新客开通会员 立减60](https://mall.csdn.net/vip?utm_source=dl_hover)
[会员·新人礼包 ![]()](https://mall.csdn.net/vip?utm_source=260309_vip_toolbarhyzx_hy)
[消息](https://i.csdn.net/#/msg/index)
[创作中心](https://mp.csdn.net/ "创作中心")
[创作](https://mp.csdn.net/edit)
[](https://mp.csdn.net/edit)  
# 比官方更简洁的Tensorflow入门教程
最新推荐文章于 2026-01-18 21:27:44 发布
翻译 于 2018-05-07 14:50:43 发布 · 10w+ 阅读
·   64
· [  388]()
[ MCP技术社区 文章已被社区收录]("MCP技术社区")
[加入社区]()
[ TensorFlow 专栏收录该内容](https://blog.csdn.net/hustqb/category_7645851.html "TensorFlow")
14 篇文章
[订阅专栏]()
本文介绍TensorFlow的基本概念,包括数据流图、张量、变量和占位符等,并通过实例展示如何构建和训练神经网络。

TensorFlow-v2.9
TensorFlow
TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型
一键部署运行
声明:
1. 参考自[Python TensorFlow Tutorial – Build a Neural Network](http://adventuresinmachinelearning.com/python-tensorflow-tutorial/),本文简化了文字部分
2. 文中有很多到官方文档的链接,毕竟有些官方文档是中文的,而且写的很好。
## Tensorflow入门
资源:[付费tensorflow教程](https://click.linksynergy.com/link?id=Jbc0N5ZkDzk&offerid=323058.1326292&type=2&murl=https://www.udemy.com/complete-guide-to-tensorflow-for-deep-learning-with-python/)
### Tensorflow graphs
Tensorflow是基于graph的并行计算模型。关于graph的理解可以参考[官方文档](https://tensorflow.google.cn/programmers_guide/graphs)。举个例子,计算 a = ( b + c ) ∗ ( c + 2 ) a=(b + c) \* (c + 2) a\=(b\+c)∗(c\+2),我们可以将算式拆分成一下:
```
一键获取完整项目代码1 2 3
```
转换成graph后的形式为:
\[外链图片转存失败(img-a63KWKIy-1565154313869)(http://adventuresinmachinelearning.com/wp-content/uploads/2017/03/Simple-graph-example.png)\]
\> 讲一个简单的算式搞成这样确实大材小用,但是我们可以通过这个例子发现:
𝑑\=𝑏\+𝑐
d
\=
b
\+
c
和
𝑒\=𝑐\+2
e
\=
c
\+
2
是不相关的,也就是可以\*\*并行计算\*\*。对于更复杂的CNN和RNN,graph的并行计算的能力将得到更好的展现。
实际中,基于Tensorflow构建的三层(单隐层)神经网络如下图所示:
\[外链图片转存失败(img-jDD9Cbqi-1565154313870)(http://adventuresinmachinelearning.com/wp-content/uploads/2017/03/TensorFlow-data-flow-graph.gif)\] \*\*Tensorflow data flow graph\*\*
上图中,**圆形或方形的节点被称为node,在node中流动的数据流被称为张量(tensor)**。更多关于tensor的描述见[官方文档](https://tensorflow.google.cn/programmers_guide/tensors)。
> 0阶张量 == 标量
> 1阶张量 == 向量(一维数组)
> 2阶张量 == 二维数组
> …
> n阶张量 == n维数组
**tensor与node之间的关系:**
如果输入tensor的维度是 5000 × 64 5000 \\times 64 5000×64,表示有5000个训练样本,每个样本有64个特征,则输入层必须有64个node来接受这些特征。
上图表示的三层网络包括:输入层(图中的input)、隐藏层(这里取名为ReLU layer表示它的激活函数是ReLU)、输出层(图中的Logit Layer)。
可以看到,每一层中都有相关tensor流入Gradient节点计算梯度,然后这些梯度tensor进入SGD Trainer节点进行网络优化(也就是update网络参数)。
Tensorflow正是通过graph表示神经网络,实现网络的并行计算,提高效率。下面我们将通过一个简单的例子来介绍TensorFlow的基础语法。
### A Simple TensorFlow example
**用Tensorflow计算 a = ( b + c ) ∗ ( c + 2 ) a = (b + c) \* (c + 2) a\=(b\+c)∗(c\+2)**, 1\. 定义数据:
```
一键获取完整项目代码 python 运行1 2 3 4 5 6 7 8
```
如上,TensorFlow中,使用`tf.constant()`定义常量,使用`tf.Variable()`定义变量。Tensorflow可以自动进行数据类型检测,比如:赋值2.0就默认为`tf.float32`,但最好还是显式地定义。更多关于TensorFlow数据类型的介绍查看[官方文档](https://www.tensorflow.org/api_docs/python/tf/DType)。
2\. 定义运算(也称TensorFlow operation):
```
一键获取完整项目代码 python 运行1 2 3 4
```
发现了没,在TensorFlow中, + − × ÷ +-\\times \\div \+−×÷都有其特殊的函数表示。实际上,TensorFlow定义了足够多的函数来表示所有的数学运算,当然也对部分数学运算进行了运算符重载,但保险起见,我还是建议你使用函数代替运算符。
\*\*!!TensorFlow中所有的变量必须经过初始化才能使用,\*\*初始化方式分两步:
1. 定义初始化operation
2. 运行初始化operation
```
一键获取完整项目代码 python 运行1 2
```
**以上已经完成TensorFlow graph的搭建**,下一步即计算并输出。
运行graph需要先调用`tf.Session()`函数创建一个会话(session)。session就是我们与graph交互的handle。更多关于session的介绍见[官方文档](https://tensorflow.google.cn/programmers_guide/graphs)。
```
一键获取完整项目代码 python 运行1 2 3 4 5 6 7
```
值得一提的是,TensorFlow有一个极好的可视化工具TensorBoard,详见[官方文档](https://tensorflow.google.cn/programmers_guide/summaries_and_tensorboard)。将上面例子的graph可视化之后的结果为:
\[外链图片转存失败(img-kgV7Bu4I-1565154313870)(http://adventuresinmachinelearning.com/wp-content/uploads/2017/04/Simple-TensorFlow-graph.png)\]
#### The TensorFlow placeholder
对上面例子的改进:使变量b可以接收任意值。TensorFlow中接收值的方式为占位符(placeholder),通过`tf.placeholder()`创建。
```
一键获取完整项目代码1 2
```
> 第二个参数值为\[None, 1\],其中None表示不确定,即不确定第一个维度的大小,第一维可以是任意大小。特别对应tensor数量(或者样本数量),输入的tensor数目可以是32、64…
现在,如果得到计算结果,需要在运行过程中feed占位符b的值,具体为将`a_out = sess.run(a)`改为:
```
a_out = sess.run(a, feed_dict={b: np.arange(0, 10)[:, np.newaxis]})一键获取完整项目代码 python 运行1
```
输出:
```
一键获取完整项目代码1 2 3 4 5 6 7 8 9 10
```
### A Neural Network Example
神经网络的例子,数据集为MNIST数据集。
1\. 加载数据:
```
一键获取完整项目代码 python 运行1 2
```
> `one_hot=True`表示对label进行one-hot编码,比如标签4可以表示为\[0, 0, 0, 0, 1, 0, 0, 0, 0, 0\]。这是神经网络输出层要求的格式。
#### Setting things up
2\. 定义超参数和placeholder
```
一键获取完整项目代码 python 运行1 2 3 4 5 6 7 8 9 10
```
> 再次强调,\[None, 784\]中的None表示任意值,特别对应tensor数目。
3\. 定义参数w和b
```
一键获取完整项目代码 python 运行1 2 3 4 5 6
```
在这里,要了解全连接层的两个参数**w**和**b**都是需要随机初始化的,`tf.random_normal()`生成正态分布的随机数。
4\. 构造隐层网络
```
一键获取完整项目代码1 2 3
```
上面代码对应于公式:
z = w x + b z = wx + b z\=wx\+b
h = r e l u ( z ) h = relu(z) h\=relu(z)
5\. 构造输出(预测值)
```
一键获取完整项目代码1 2
```
对于单标签多分类任务,输出层的激活函数都是`tf.nn.softmax()`。更多关于softmax的知识见[维基百科](https://en.wikipedia.org/wiki/Softmax_function)。
6\. BP部分—定义loss
损失为交叉熵,公式为
J = − 1 m ∑ i = 1 m ∑ j = 1 n y j i l o g ( y j ( i ) ) + ( 1 − y j ( i ) l o g ( 1 − y j ( i ) ) J=- \\frac 1m \\sum\_{i=1}^m\\sum\_{j=1}^n y\_j^{i}log(y\_j^{(i)}) + (1 - y\_j^{(i)}log(1-y\_j^{(i)}) J\=−m1i\=1∑mj\=1∑nyjilog(yj(i))\+(1−yj(i)log(1−yj(i))
公式分为两步:
1. 对n个标签计算交叉熵
2. 对m个样本取平均
```
一键获取完整项目代码 python 运行1 2
```
7\. BP部分—定义优化算法
```
一键获取完整项目代码1 2
```
TensorFlow中更多优化算法详见[官方文档](https://www.tensorflow.org/api_guides/python/train)。
8\. 定义初始化operation和准确率node
```
一键获取完整项目代码1 2 3 4 5 6
```
`correct_predicion`会返回一个 m × 1 m\\times 1 m×1的tensor,tensor的值为True/False表示是否正确预测。
#### Setting up the training
9\. 开始训练
```
一键获取完整项目代码 python 运行1 2 3 4 5 6 7 8 9 10 11 12 13
```
输出:
```
一键获取完整项目代码1 2 3 4 5 6 7 8 9 10 11 12 13
```
通过TensorBoard可视化训练过程:
\[外链图片转存失败(img-5NxdHJph-1565154313871)(<http://adventuresinmachinelearning.com/wp-content/uploads/2017/04/TensorBoard-increase-in-accuracy-NN.png>)\]
您可能感兴趣的与本文相关的镜像

TensorFlow-v2.9
TensorFlow
TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型
一键部署运行

确定要放弃本次机会?
福利倒计时
*:* *:*
 立减 ¥
普通VIP年卡可用
[立即使用](https://mall.csdn.net/vip)
[ hustqb](https://blog.csdn.net/hustqb)
[关注]() [关注]()
- [   64]()
点赞
- [ ]()
踩
- [   388]()
收藏
觉得还不错? 一键收藏 
- [ 34](https://blog.csdn.net/hustqb/article/details/80222055#commentBox)
评论
- [ 分享]()
[复制链接]()
[分享到 QQ]()
[分享到新浪微博]()
扫一扫
- []()
[ 举报]()
[ 举报]()
[专栏目录]()
[*Tensorflow*入门](https://blog.csdn.net/qq_56246012/article/details/141390153)
[qq\_56246012的博客](https://blog.csdn.net/qq_56246012)
08-25  4864
[文章简单介绍了*tensorflow*和keras,并用鸢尾花(iris)分类案例,介绍tf.keras的基本使用流程。](https://blog.csdn.net/qq_56246012/article/details/141390153)
[*tensorflow**入门教程*之mnist识别手写数字.rar](https://download.csdn.net/download/qq_37591637/12020671)
12-09
[在本教程中,我们将深入探讨如何使用*TensorFlow*库进行手写数字识别,特别是基于MNIST数据集。MNIST是机器学习领域的一个经典数据集,它包含60,000个训练样本和10,000个测试样本,每个样本都是28x28像素的手写数字...](https://download.csdn.net/download/qq_37591637/12020671)
34 条评论 您还未登录,请先 登录 后发表或查看评论
[【*TensorFlow*】*tensorflow*简介和环境搭建、入门](https://blog.csdn.net/u014608435/article/details/144710865)
2-23
[\# *Tensorflow*1\.0实现import*tensorflow*astf\# 构建计算图x=tf.Variable(0.)y=tf.Variable(1.)add\_op=x.assign(x+y)\# x = x + ydiv\_op=y.assign(y/2)\# y = y / 2\# *TensorFlow*1\.0中必须先打开会话,才能计算数据流图withtf.Session()assess:sess.run(](https://blog.csdn.net/u014608435/article/details/144710865)
[*TensorFlow*与PyTorch:神经网络构建双雄](https://blog.csdn.net/2601_95543611/article/details/159122016)
3-16
[*TensorFlow*:谷歌的深度学习框架 *TensorFlow*由谷歌开发,是一个开源的机器学习框架,支持从研究到生产的全流程开发。其核心特点是静态计算图和分布式计算能力,适合大规模部署。 静态计算图与即时执行模式 *TensorFlow*最初采用静态计算图的设计,开发者需要先定义计算图的结构,再通过会话(Session)执行计算。这种设计优化了计算效率...](https://blog.csdn.net/2601_95543611/article/details/159122016)
[*TensorFlow*教程](https://download.csdn.net/download/mjl20100/11079377)
04-01
[1\.*TensorFlow*安装、技巧、教材 2.*TensorFlow**官方*文档 3.*TensorFlow*图像识别应用 4.深度学习基础教程](https://download.csdn.net/download/mjl20100/11079377)
[*Tensorflow*简单教程 热门推荐](https://devpress.csdn.net/v1/article/detail/51052770)
[凌风探梅的专栏](https://blog.csdn.net/Real_Myth)
04-03  1万+
[Google将其机器学习框架*Tensorflow*开源后引起了世界风暴,本文主要阐述如何在日常数据科学中使用该框架。 为什么使用*Tensorflow*? 作为一个数据科学研究者,已经有很多工具如R语言、Scikit等学习工具,为什么还要使用*Tensorflow*呢? 1. *TensorFlow*的深度学习部分能够在一个模型中堆积了许多不同的模型和转换,你能够在一个模型中方便地处理文本 图片和](https://devpress.csdn.net/v1/article/detail/51052770)
[一文读懂 *TensorFlow* 深度学习框架:从基础到实战\!](https://blog.csdn.net/Stuomasi_xiaoxin/article/details/145307078)
3-15
[高度灵活性:*TensorFlow* 允许用户在 CPU、GPU 甚至是分布式系统上轻松构建和训练模型,无论是简单的线性回归还是复杂的卷积神经网络,都能游刃有余地处理。 可视化工具:TensorBoard 是 *TensorFlow* 自带的可视化工具,它可以帮助用户理解模型的训练过程,比如查看损失函数的变化趋势、可视化网络结构等。 社区支持:拥有庞大的开源社...](https://blog.csdn.net/Stuomasi_xiaoxin/article/details/145307078)
[*TensorFlow*掩码传递机制全解析](https://blog.csdn.net/2601_95511303/article/details/159011888)
3-13
[*TensorFlow*通过内置的掩码传递机制,实现了从输入层到中间层再到输出层的自动掩码传播,简化了模型开发流程。 掩码的基本概念与作用 掩码用于标识序列数据中的有效部分和填充部分。例如,在文本数据中,短句会被填充(Padding)到与最长句相同的长度,掩码标记这些填充位置,使模型忽略它们。*TensorFlow*中掩码通常是一个布尔张量,Tr...](https://blog.csdn.net/2601_95511303/article/details/159011888)
[*TensorFlow* 2.x 实战,从环境搭建到深度学习模型落地 最新发布](https://devpress.csdn.net/v1/article/detail/157103172)
[2501\_93482746的博客](https://blog.csdn.net/2501_93482746)
01-18  674
[*TensorFlow* 2.x 实战,从环境搭建到深度学习模型落地](https://devpress.csdn.net/v1/article/detail/157103172)
[*TensorFlow*入门](https://blog.csdn.net/itscarrot/article/details/52329182)
[itscarrot的博客](https://blog.csdn.net/itscarrot)
08-26  3939
[uda与*tensorflow*安装 按以往经验,*tensorflow*安装一条pip命令就可以解决,前提是有fq工具,没有的话去找找墙内别人分享的地址。而坑多在安装支持gpu,需预先安装英伟达的cuda,这里坑比较多,推荐使用ubuntu deb的安装方式来安装cuda,run.sh的方式总感觉有很多问题,cuda的安装具体可以参考。 注意链接里面的*tensorflow*版本是以前的,tensorfl](https://blog.csdn.net/itscarrot/article/details/52329182)
[【AI】*TensorFlow* 框架](https://blog.csdn.net/weixin_40970718/article/details/159014830)
3-14
[(*TensorFlow* Core) │││ Eager Mode(默认): ││ • 命令式编程,像NumPy一样立即执行 ││ • Pythonic调试,支持pdb/ipdb断点 │││ @tf.function(转换器): ││ • Python函数 → 图函数(Graph Function) ││ • 原理:AutoGraph将Python控制流转为TF控制流 ││ (if → tf.cond, for → t...](https://blog.csdn.net/weixin_40970718/article/details/159014830)
[*TensorFlow* 保姆级教程:安装步骤、使用示例及常见问题应对\_*tensorflow*...](https://blog.csdn.net/mng123/article/details/144842102)
3-10
[一、*TensorFlow*安装 (一)安装前准备 环境要求 Python版本:*TensorFlow*支持Python 3.7 - 3.11。确保你的Python环境已经正确安装并且可以正常使用。你可以在命令行(Windows下是cmd,Linux和Mac下是终端)中输入python --version(对于Python 3)或者python3 --version来检查Python版本。](https://blog.csdn.net/mng123/article/details/144842102)
[*TensorFlow*入门(一)](https://blog.csdn.net/xxy0118/article/details/77688006)
[xxy\_的博客](https://blog.csdn.net/xxy0118)
08-29  1351
[一、*TensorFlow*基本概念 1.张量(Tensor):张量是数学的一个分支学科,发展起源和历史请自行百度。在*TensorFlow*里,张量是矢量的扩展,张量是一个可用来表示在一些矢量、标量和其他张量之间的线性关系的多线性函数。例如,①3.14,标量,0维;②\[1,2,3\],矢量,1维数组,1阶张量;③\[1,2,3;4,5,6;7,8,9\],二维矩阵,2维数组,2阶张量;以此类推,张量可以扩展](https://blog.csdn.net/xxy0118/article/details/77688006)
[*tensorflow*教程](https://download.csdn.net/download/weiliang_handan/10750109)
10-29
[stanford-*tensorflow*\-tutorials; course CS 20: *TensorFlow* for Deep Learning Research.](https://download.csdn.net/download/weiliang_handan/10750109)
[*tensorflow*使用详解](https://blog.csdn.net/zhangzehai2234/article/details/147571490)
3-2
[一、*TensorFlow*基础环境搭建 安装与验证 \# 安装CPU版本pipinstall*tensorflow*\# 安装GPU版本(需CUDA 11.x和cuDNN 8.x)pipinstall*tensorflow*\-gpu\# 验证安装python -c"import *tensorflow* as tf; print(tf.\_\_version\_\_)" 一键获取完整项目代码bash 1 2 3](https://blog.csdn.net/zhangzehai2234/article/details/147571490)
[*TensorFlow* 的基本概念和使用场景的简单介绍\_*tensorflow*概念-CSDN...](https://blog.csdn.net/qq_45657541/article/details/146445869)
3-3
[一、*TensorFlow* 的基本概念 1. 什么是 *TensorFlow*? • 定义:由 Google 开发的开源机器学习框架,基于 计算图(Computational Graph) 构建模型,支持多种编程语言(Python、C++、Java 等)。 • 核心理念:通过灵活的API和高效的底层优化,简化从研究到生产的机器学习流程。](https://blog.csdn.net/qq_45657541/article/details/146445869)
[深度学习与*TensorFlow* 2入门实战-视频教程网盘链接提取码下载.txt](https://download.csdn.net/download/m0_66047725/88469291)
10-25
[《深度学习与*TensorFlow* 2入门实战》是一门适合初学者的课程,旨在帮助学员快速入门深度学习和*TensorFlow* 2框架。课程内容涵盖了深度学习基础知识、*TensorFlow* 2的安装与配置、神经网络的构建与训练等方面。通过本...](https://download.csdn.net/download/m0_66047725/88469291)
[*TensorFlow* *入门教程*和示例(支持 TF v1 和 v2)](https://download.csdn.net/download/weixin_43846408/88976409)
03-16
[这个*入门教程*和示例集合是为那些想要了解或深化 *TensorFlow* 技能的学习者准备的,无论你是初学者还是有一定经验的开发者,都能从中受益。该资源特别强调了对 *TensorFlow* v1 和 v2 的支持,让你能同时掌握这两个版本...](https://download.csdn.net/download/weixin_43846408/88976409)
[机器学习18-*tensorflow*3](https://blog.csdn.net/qq_41810539/article/details/158948032)
3-14
[TensorBoard是*TensorFlow**官方*配套的可视化工具,核心作用是将模型训练过程中的指标(损失、准确率)、计算图、权重分布、嵌入向量等“可视化”,帮助你直观监控训练过程、调试模型、分析性能瓶颈。 简单来说:没有TensorBoard时,你只能看到终端里枯燥的数字;有了TensorBoard,你能看到训练曲线、模型结构、参数变化等可视化图表,快速...](https://blog.csdn.net/qq_41810539/article/details/158948032)
[*TensorFlow*\-v2.15简单教程:小白也能懂的GPU内存增长模式设置](https://blog.csdn.net/weixin_36304957/article/details/159062180)
3-15
[*TensorFlow*\-v2.15简单教程:小白也能懂的GPU内存增长模式设置 1. 为什么需要关注GPU内存管理 当你开始使用*TensorFlow*进行深度学习训练时,可能会遇到一个常见问题:程序突然崩溃并显示"Out Of Memory"错误。这通常是因为GPU显存被过度占用导致的。理解和管理GPU内存是每个深度学习开发者必备的技能。](https://blog.csdn.net/weixin_36304957/article/details/159062180)
[*Tensorflow* 教程](https://blog.csdn.net/jhy10202008/article/details/85004671)
[jhy10202008的博客](https://blog.csdn.net/jhy10202008)
12-14  274
[*Tensorflow*教程网址: https://github.com/osforscience/*TensorFlow*\-Course\#what-is-*tensorflow*](https://blog.csdn.net/jhy10202008/article/details/85004671)
[*Tensorflow*教程](https://blog.csdn.net/weixin_46720482/article/details/124076439)
[weixin\_46720482的博客](https://blog.csdn.net/weixin_46720482)
04-10  8090
[前言 1、*TensorFlow* 是由 Google Brain 团队为深度神经网络(DNN)开发的功能强大的开源软件库; 2、*TensorFlow* 允许将深度神经网络的计算部署到任意数量的 CPU 或 GPU 的服务器、PC 或移动设备上,且只利用一个 *TensorFlow* API。 3、那 *TensorFlow* 与其他深度学习库,如 Torch、Theano、Caffe 和 MxNet的区别在哪里呢? 包括 *TensorFlow* 在内的大多数深度学习库能够自动求导(自动求导 (Automatic](https://blog.csdn.net/weixin_46720482/article/details/124076439)
[*tensorflow*教程(一)](https://blog.csdn.net/weixin_38203090/article/details/105914568)
[奋斗应该是年轻的状态!](https://blog.csdn.net/weixin_38203090)
05-05  375
[一、利用*tensorflow*输出hello world import *tensorflow* as tf def main(): opertion\_me = tf.constant("Hello world") with tf.Session() as sess: print(sess.run(opertion\_me).decode()) if \_\_name\_\_=="...](https://blog.csdn.net/weixin_38203090/article/details/105914568)
[*TensorFlow*相关教程(概念版)](https://huahuaboy.blog.csdn.net/article/details/122591376)
[IT菜鸟](https://blog.csdn.net/m0_37605642)
01-23  2588
[*TensorFlow*相关教程(概念版)](https://huahuaboy.blog.csdn.net/article/details/122591376)
[*tensorflow*简易教程](https://blog.csdn.net/weixin_40248634/article/details/106503869)
[weixin\_40248634的博客](https://blog.csdn.net/weixin_40248634)
06-02  317
[tf对话create two matrixes层数据输入占位符 对话 import *tensorflow* as tf create two matrixes matrix1 = tf.constant(\[\[3,3\]\]) matrix2 = tf.constant(\[\[2\], \[2\]\]) product = tf.matmul(matrix1,matrix2) \# method 1 sess = tf.Session() result = sess.run(pr](https://blog.csdn.net/weixin_40248634/article/details/106503869)
[*Tensorflow*简明教程](https://blog.csdn.net/weixin_47532216/article/details/121597953)
[weixin\_47532216的博客](https://blog.csdn.net/weixin_47532216)
11-28  2587
[一直以来没有系统学习过TF,为了*更*加高效的投入到近期的关系抽取比赛中,所以准备系统学习一下,系统学习的内容是李理老师的《*Tensorflow*简明教程》,地址为 http://fancyerii.github.io/books/tf 。以下为老师的TF教程,以及自己做的一些笔记和标注。 1. 概述 *TensorFlow*中计算的定义和计算的执行是分开的。这句话究竟怎么理解呢?可能指的是两者是在不同的context下完成的。 我们编写*TensorFlow*程序通常分为两步:定义计算图;使用session](https://blog.csdn.net/weixin_47532216/article/details/121597953)
[*Tensorflow*教程(附完整代码)](https://blog.csdn.net/wangqianqianya/article/details/86584676)
[wangqianqianya的博客](https://blog.csdn.net/wangqianqianya)
01-22  2550
[综述 *TensorFlow*是一个编程系统,用图来表示计算任务,描述了计算过程 图中结点表示为op(operation),一个op获得0或多个tersor tensor是一个多维数组,在图中表示边 图必须在会话Session里启动 变量需初始化tf.global\_variables\_initializer() *TensorFlow*程序可以看做独立的两部分:构建计算图与运行计算图 1、...](https://blog.csdn.net/wangqianqianya/article/details/86584676)
[*tensorflow**入门教程*](https://wenku.csdn.net/answer/2fq9q7461v)
01-21
[\### *TensorFlow* 初学者教程 对于希望学习 *TensorFlow* 的初学者来说,*官方*提供了一个非常适合入门的教程\[^1\]。此教程不仅介绍了如何加载数据集并构建简单的神经网络模型,还展示了如何使用softmax回归进行分类。 在这个初级教程中,MNIST手写数字识别被作为案例研究。通过Python脚本实现了基本的数据预处理、模型定义、损失函数设定以及优化过程。下面是一个简化版的例子: \```python import *tensorflow* as tf from *tensorflow*.examples.tutorials.mnist import input\_data mnist = input\_data.read\_data\_sets('MNIST\_data', one\_hot=True) x = tf.placeholder(tf.float32, \[None, 784\]) W = tf.Variable(tf.zeros(\[784, 10\])) b = tf.Variable(tf.zeros(\[10\])) y = tf.nn.softmax(tf.matmul(x, W) + b) y\_ = tf.placeholder(tf.float32, \[None, 10\]) cross\_entropy = -tf.reduce\_sum(y\_\*tf.log(y)) train\_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross\_entropy) sess = tf.Session() init = tf.global\_variables\_initializer() sess.run(init) for i in range(1000): batch\_xs, batch\_ys = mnist.train.next\_batch(100) sess.run(train\_step, feed\_dict={x: batch\_xs, y\_: batch\_ys}) correct\_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y\_,1)) accuracy = tf.reduce\_mean(tf.cast(correct\_prediction, "float")) print(sess.run(accuracy, feed\_dict={x: mnist.test.images, y\_: mnist.test.labels})) \``` 这段代码首先导入必要的库,并读取MNIST数据集。接着定义了占位符\`x\`用于输入图像特征向量,变量\`W\`代表权重矩阵而\`b\`表示偏置项。随后建立了Softmax层来进行预测输出。为了评估模型性能,引入交叉熵作为代价函数并通过梯度下降法最小化它。最后,在测试集中验证了所学得参数的有效性。 除了上述基础内容外,还有*更*多关于*TensorFlow*的基础概念介绍可供进一步了解,比如计算图的概念和张量的操作等\[^3\]。](https://wenku.csdn.net/answer/2fq9q7461v)
- [关于我们](https://www.csdn.net/company/index.html#about)
- [招贤纳士](https://www.csdn.net/company/index.html#recruit)
- [商务合作](https://fsc-p05.txscrm.com/T8PN8SFII7W)
- [寻求报道](https://marketing.csdn.net/questions/Q2202181748074189855)
-  400-660-0108
-  [kefu@csdn.net](mailto:webmaster@csdn.net)
-  [在线客服](https://csdn.s2.udesk.cn/im_client/?web_plugin_id=29181)
- 工作时间 8:30-22:00
- [公安备案号11010502030143](http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11010502030143)
- [京ICP备19004658号](http://beian.miit.gov.cn/publish/query/indexFirst.action)
- [京网文〔2020〕1039-165号](https://csdnimg.cn/release/live_fe/culture_license.png)
- [经营性网站备案信息](https://csdnimg.cn/cdn/content-toolbar/csdn-ICP.png)
- [北京互联网违法和不良信息举报中心](http://www.bjjubao.org/)
- [家长监护](https://download.csdn.net/tutelage/home)
- [网络110报警服务](https://cyberpolice.mps.gov.cn/)
- [中国互联网举报中心](http://www.12377.cn/)
- [Chrome商店下载](https://chrome.google.com/webstore/detail/csdn%E5%BC%80%E5%8F%91%E8%80%85%E5%8A%A9%E6%89%8B/kfkdboecolemdjodhmhmcibjocfopejo?hl=zh-CN)
- [账号管理规范](https://blog.csdn.net/blogdevteam/article/details/126135357)
- [版权与免责声明](https://www.csdn.net/company/index.html#statement)
- [版权申诉](https://blog.csdn.net/blogdevteam/article/details/90369522)
- [出版物许可证](https://img-home.csdnimg.cn/images/20250103023206.png)
- [营业执照](https://img-home.csdnimg.cn/images/20250103023201.png)
- ©1999-2026北京创新乐知网络技术有限公司
[](https://blog.csdn.net/hustqb)
[hustqb](https://blog.csdn.net/hustqb "hustqb")
博客等级 
码龄10年
[58 原创](https://blog.csdn.net/hustqb)
1317
点赞
4149
收藏
641
粉丝
[关注]()
[私信](https://im.csdn.net/chat/hustqb)
[](https://ai.csdn.net/workbench/wallet?utm_source=xtai_slb_bloglb)
### 热门文章
- [Python中numpy数组的合并  269949](https://blog.csdn.net/hustqb/article/details/78090365)
- [数据降维与可视化——t-SNE  139362](https://blog.csdn.net/hustqb/article/details/78144384)
- [比官方更简洁的Tensorflow入门教程  127054](https://blog.csdn.net/hustqb/article/details/80222055)
- [超全面的协方差矩阵介绍  98705](https://blog.csdn.net/hustqb/article/details/90264432)
- [图文并茂的Python散点图教程  96471](https://blog.csdn.net/hustqb/article/details/77869076)
### 分类专栏
- [ 小样本学习](https://blog.csdn.net/hustqb/category_9282291.html)
- [ Git](https://blog.csdn.net/hustqb/category_9462216.html)
1篇
- [ 数据库](https://blog.csdn.net/hustqb/category_9461421.html)
1篇
- [ 机器学习](https://blog.csdn.net/hustqb/category_6897623.html)
21篇
- [ TensorFlow](https://blog.csdn.net/hustqb/category_7645851.html)
14篇
- [ Deep Learning](https://blog.csdn.net/hustqb/category_7648155.html)
12篇
- [ 7天微课堂——时间序列](https://blog.csdn.net/hustqb/category_7737111.html)
8篇
- [ Python](https://blog.csdn.net/hustqb/category_6841151.html)
21篇
- [ 图文并茂](https://blog.csdn.net/hustqb/category_7213652.html)
4篇
- [ 算法](https://blog.csdn.net/hustqb/category_6906697.html)
2篇
- [ Python绘图](https://blog.csdn.net/hustqb/category_7213664.html)
5篇
- [ C++](https://blog.csdn.net/hustqb/category_7459423.html)
5篇
- [ Android](https://blog.csdn.net/hustqb/category_6841152.html)
1篇
- [ Deeplearning花书学习笔记](https://blog.csdn.net/hustqb/category_8036382.html)
6篇
- [ 设计模式](https://blog.csdn.net/hustqb/category_8512459.html)
1篇
- [ 数学](https://blog.csdn.net/hustqb/category_8954334.html)
- [ NLP](https://blog.csdn.net/hustqb/category_9235708.html)
4篇
[展开全部 ]() [收起 ]()
上一篇:
[Python3.6.5 argparse官方文档翻译](https://blog.csdn.net/hustqb/article/details/80166449)
下一篇:
[Tensorflow卷积网络教程——Alexnet, VGG, Inceptionv3, Resnet and squeezeNet](https://blog.csdn.net/hustqb/article/details/80228627)
### 最新评论
- [超全面的协方差矩阵介绍](https://blog.csdn.net/hustqb/article/details/90264432#comments_36884429)
[水光山:](https://blog.csdn.net/2202_75454924) 正定负定是建立在二次型上的,即对称矩阵上,实对称不一定是半正定的,需要勘误
### 大家在看
- [从零到一:我设计了一个抗量子计算的哈希函数 REV-512  411](https://blog.csdn.net/2403_86846691/article/details/159079551)
- [REV-512 的数学原理详解  140](https://blog.csdn.net/2403_86846691/article/details/159086687)
- [玩转Python OpenCV:从命令行参数解析到模板匹配实战](https://blog.csdn.net/F_leshy_/article/details/159127545)
- [出海账号稳定秘籍:养号必备住宅IP代理怎么用?](https://blog.csdn.net/wenxin1111111/article/details/159127767)
- [5-10两数之和](https://blog.csdn.net/XW0105999/article/details/159127664)
### 最新文章
- [Tensorflow实现Embedding Layer](https://blog.csdn.net/hustqb/article/details/117523417)
- [给模型热身——深度学习中的warm up](https://blog.csdn.net/hustqb/article/details/105741250)
- [Tensorflow中的masking和padding](https://blog.csdn.net/hustqb/article/details/104457706)
[2021年1篇](https://blog.csdn.net/hustqb?type=blog&year=2021&month=06)
[2020年5篇](https://blog.csdn.net/hustqb?type=blog&year=2020&month=04)
[2019年11篇](https://blog.csdn.net/hustqb?type=blog&year=2019&month=11)
[2018年48篇](https://blog.csdn.net/hustqb?type=blog&year=2018&month=12)
[2017年41篇](https://blog.csdn.net/hustqb?type=blog&year=2017&month=11)
[2016年2篇](https://blog.csdn.net/hustqb?type=blog&year=2016&month=11)
官方同款运行环境
TensorFlow-v2.9
TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型
TensorFlow
显存大小
24GB
CPU
10核心
内存
120GB
系统盘/数据盘
40GB
一键部署
无需本地环境部署,可直接运行
### 目录
1. [Tensorflow入门](https://blog.csdn.net/hustqb/article/details/80222055#t0)
2. 1. [Tensorflow graphs](https://blog.csdn.net/hustqb/article/details/80222055#t1)
2. [A Simple TensorFlow example](https://blog.csdn.net/hustqb/article/details/80222055#t2)
3. 1. [The TensorFlow placeholder](https://blog.csdn.net/hustqb/article/details/80222055#t3)
4. [A Neural Network Example](https://blog.csdn.net/hustqb/article/details/80222055#t4)
5. 1. [Setting things up](https://blog.csdn.net/hustqb/article/details/80222055#t5)
2. [Setting up the training](https://blog.csdn.net/hustqb/article/details/80222055#t6)
展开全部 
收起 
官方同款运行环境
TensorFlow-v2.9
TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型
TensorFlow
显存大小
24GB
CPU
10核心
内存
120GB
系统盘/数据盘
40GB
一键部署
无需本地环境部署,可直接运行
### 目录
1. [Tensorflow入门](https://blog.csdn.net/hustqb/article/details/80222055#t0)
2. 1. [Tensorflow graphs](https://blog.csdn.net/hustqb/article/details/80222055#t1)
2. [A Simple TensorFlow example](https://blog.csdn.net/hustqb/article/details/80222055#t2)
3. 1. [The TensorFlow placeholder](https://blog.csdn.net/hustqb/article/details/80222055#t3)
4. [A Neural Network Example](https://blog.csdn.net/hustqb/article/details/80222055#t4)
5. 1. [Setting things up](https://blog.csdn.net/hustqb/article/details/80222055#t5)
2. [Setting up the training](https://blog.csdn.net/hustqb/article/details/80222055#t6)
展开全部 
收起 
上一篇:
[Python3.6.5 argparse官方文档翻译](https://blog.csdn.net/hustqb/article/details/80166449)
下一篇:
[Tensorflow卷积网络教程——Alexnet, VGG, Inceptionv3, Resnet and squeezeNet](https://blog.csdn.net/hustqb/article/details/80228627)
### 分类专栏
- [ 小样本学习](https://blog.csdn.net/hustqb/category_9282291.html)
- [ Git](https://blog.csdn.net/hustqb/category_9462216.html)
1篇
- [ 数据库](https://blog.csdn.net/hustqb/category_9461421.html)
1篇
- [ 机器学习](https://blog.csdn.net/hustqb/category_6897623.html)
21篇
- [ TensorFlow](https://blog.csdn.net/hustqb/category_7645851.html)
14篇
- [ Deep Learning](https://blog.csdn.net/hustqb/category_7648155.html)
12篇
- [ 7天微课堂——时间序列](https://blog.csdn.net/hustqb/category_7737111.html)
8篇
- [ Python](https://blog.csdn.net/hustqb/category_6841151.html)
21篇
- [ 图文并茂](https://blog.csdn.net/hustqb/category_7213652.html)
4篇
- [ 算法](https://blog.csdn.net/hustqb/category_6906697.html)
2篇
- [ Python绘图](https://blog.csdn.net/hustqb/category_7213664.html)
5篇
- [ C++](https://blog.csdn.net/hustqb/category_7459423.html)
5篇
- [ Android](https://blog.csdn.net/hustqb/category_6841152.html)
1篇
- [ Deeplearning花书学习笔记](https://blog.csdn.net/hustqb/category_8036382.html)
6篇
- [ 设计模式](https://blog.csdn.net/hustqb/category_8512459.html)
1篇
- [ 数学](https://blog.csdn.net/hustqb/category_8954334.html)
- [ NLP](https://blog.csdn.net/hustqb/category_9235708.html)
4篇
[展开全部 ]() [收起 ]()
登录后您可以享受以下权益:
- 免费复制代码
- 和博主大V互动
- 下载海量资源
- 发动态/写文章/加入社区
×
立即登录
评论 34

被折叠的 条评论 [为什么被折叠?](https://blogdev.blog.csdn.net/article/details/122245662) [到【灌水乐园】发言](https://bbs.csdn.net/forums/FreeZone)
[查看更多评论]()
添加红包
![]()
成就一亿技术人\!
领取后你会自动成为博主和红包主的粉丝 [规则](https://blogdev.blog.csdn.net/article/details/128932621)
[](https://blog.csdn.net/hustqb/article/details/80222055)
hope\_wisdom
发出的红包
实付元
[使用余额支付]()
 点击重新获取
扫码支付
钱包余额 0

抵扣说明:
1\.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。
[余额充值](https://i.csdn.net/#/wallet/balance/recharge)
![]()
确定取消
举报

选择你想要举报的内容(必选)
- 内容涉黄
- 政治相关
- 内容抄袭
- 涉嫌广告
- 内容侵权
- 侮辱谩骂
- 样式问题
- 其他
原文链接(必填)
请选择具体原因(必选)
- 包含不实信息
- 涉及个人隐私
请选择具体原因(必选)
- 侮辱谩骂
- 诽谤
请选择具体原因(必选)
- 搬家样式
- 博文样式
补充说明(选填)
取消
确定
[](https://ai.csdn.net/workbench/wallet?utm_source=xtai_slb_blogxf_ty) [ 点击体验 DeepSeekR1满血版](https://ai.csdn.net/chat?utm_source=cknow_pc_blogdetail&spm=1001.2101.3001.10583)
[ 下载APP  程序员都在用的中文IT技术交流社区 公众号  专业的中文 IT 技术社区,与千万技术人共成长 视频号  关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!]()
[ 客服]()
新手引导
[ 返回顶部]() |
| Readable Markdown | 声明:
1. 参考自[Python TensorFlow Tutorial – Build a Neural Network](http://adventuresinmachinelearning.com/python-tensorflow-tutorial/),本文简化了文字部分
2. 文中有很多到官方文档的链接,毕竟有些官方文档是中文的,而且写的很好。
## Tensorflow入门
资源:[付费tensorflow教程](https://click.linksynergy.com/link?id=Jbc0N5ZkDzk&offerid=323058.1326292&type=2&murl=https://www.udemy.com/complete-guide-to-tensorflow-for-deep-learning-with-python/)
### Tensorflow graphs
Tensorflow是基于graph的并行计算模型。关于graph的理解可以参考[官方文档](https://tensorflow.google.cn/programmers_guide/graphs)。举个例子,计算 a = ( b + c ) ∗ ( c + 2 ) a=(b + c) \* (c + 2) a\=(b\+c)∗(c\+2),我们可以将算式拆分成一下:
```
1 2 3
```
转换成graph后的形式为:
\[外链图片转存失败(img-a63KWKIy-1565154313869)(http://adventuresinmachinelearning.com/wp-content/uploads/2017/03/Simple-graph-example.png)\]
\> 讲一个简单的算式搞成这样确实大材小用,但是我们可以通过这个例子发现:d \= b \+ c和e \= c \+ 2是不相关的,也就是可以\*\*并行计算\*\*。对于更复杂的CNN和RNN,graph的并行计算的能力将得到更好的展现。
实际中,基于Tensorflow构建的三层(单隐层)神经网络如下图所示:
\[外链图片转存失败(img-jDD9Cbqi-1565154313870)(http://adventuresinmachinelearning.com/wp-content/uploads/2017/03/TensorFlow-data-flow-graph.gif)\] \*\*Tensorflow data flow graph\*\*
上图中,**圆形或方形的节点被称为node,在node中流动的数据流被称为张量(tensor)**。更多关于tensor的描述见[官方文档](https://tensorflow.google.cn/programmers_guide/tensors)。
> 0阶张量 == 标量
> 1阶张量 == 向量(一维数组)
> 2阶张量 == 二维数组
> …
> n阶张量 == n维数组
**tensor与node之间的关系:**
如果输入tensor的维度是 5000 × 64 5000 \\times 64 5000×64,表示有5000个训练样本,每个样本有64个特征,则输入层必须有64个node来接受这些特征。
上图表示的三层网络包括:输入层(图中的input)、隐藏层(这里取名为ReLU layer表示它的激活函数是ReLU)、输出层(图中的Logit Layer)。
可以看到,每一层中都有相关tensor流入Gradient节点计算梯度,然后这些梯度tensor进入SGD Trainer节点进行网络优化(也就是update网络参数)。
Tensorflow正是通过graph表示神经网络,实现网络的并行计算,提高效率。下面我们将通过一个简单的例子来介绍TensorFlow的基础语法。
### A Simple TensorFlow example
**用Tensorflow计算 a = ( b + c ) ∗ ( c + 2 ) a = (b + c) \* (c + 2) a\=(b\+c)∗(c\+2)**, 1\. 定义数据:
```
python1 2 3 4 5 6 7 8
```
如上,TensorFlow中,使用`tf.constant()`定义常量,使用`tf.Variable()`定义变量。Tensorflow可以自动进行数据类型检测,比如:赋值2.0就默认为`tf.float32`,但最好还是显式地定义。更多关于TensorFlow数据类型的介绍查看[官方文档](https://www.tensorflow.org/api_docs/python/tf/DType)。
2\. 定义运算(也称TensorFlow operation):
```
python1 2 3 4
```
发现了没,在TensorFlow中, + − × ÷ +-\\times \\div \+−×÷都有其特殊的函数表示。实际上,TensorFlow定义了足够多的函数来表示所有的数学运算,当然也对部分数学运算进行了运算符重载,但保险起见,我还是建议你使用函数代替运算符。
\*\*!!TensorFlow中所有的变量必须经过初始化才能使用,\*\*初始化方式分两步:
1. 定义初始化operation
2. 运行初始化operation
```
python1 2
```
**以上已经完成TensorFlow graph的搭建**,下一步即计算并输出。
运行graph需要先调用`tf.Session()`函数创建一个会话(session)。session就是我们与graph交互的handle。更多关于session的介绍见[官方文档](https://tensorflow.google.cn/programmers_guide/graphs)。
```
python1 2 3 4 5 6 7
```
值得一提的是,TensorFlow有一个极好的可视化工具TensorBoard,详见[官方文档](https://tensorflow.google.cn/programmers_guide/summaries_and_tensorboard)。将上面例子的graph可视化之后的结果为:
\[外链图片转存失败(img-kgV7Bu4I-1565154313870)(http://adventuresinmachinelearning.com/wp-content/uploads/2017/04/Simple-TensorFlow-graph.png)\]
#### The TensorFlow placeholder
对上面例子的改进:使变量b可以接收任意值。TensorFlow中接收值的方式为占位符(placeholder),通过`tf.placeholder()`创建。
```
1 2
```
> 第二个参数值为\[None, 1\],其中None表示不确定,即不确定第一个维度的大小,第一维可以是任意大小。特别对应tensor数量(或者样本数量),输入的tensor数目可以是32、64…
现在,如果得到计算结果,需要在运行过程中feed占位符b的值,具体为将`a_out = sess.run(a)`改为:
```
a_out = sess.run(a, feed_dict={b: np.arange(0, 10)[:, np.newaxis]})python1
```
输出:
```
1 2 3 4 5 6 7 8 9 10
```
### A Neural Network Example
神经网络的例子,数据集为MNIST数据集。
1\. 加载数据:
```
python1 2
```
> `one_hot=True`表示对label进行one-hot编码,比如标签4可以表示为\[0, 0, 0, 0, 1, 0, 0, 0, 0, 0\]。这是神经网络输出层要求的格式。
#### Setting things up
2\. 定义超参数和placeholder
```
python1 2 3 4 5 6 7 8 9 10
```
> 再次强调,\[None, 784\]中的None表示任意值,特别对应tensor数目。
3\. 定义参数w和b
```
python1 2 3 4 5 6
```
在这里,要了解全连接层的两个参数**w**和**b**都是需要随机初始化的,`tf.random_normal()`生成正态分布的随机数。
4\. 构造隐层网络
```
1 2 3
```
上面代码对应于公式:
z = w x + b z = wx + b z\=wx\+b
h = r e l u ( z ) h = relu(z) h\=relu(z)
5\. 构造输出(预测值)
```
1 2
```
对于单标签多分类任务,输出层的激活函数都是`tf.nn.softmax()`。更多关于softmax的知识见[维基百科](https://en.wikipedia.org/wiki/Softmax_function)。
6\. BP部分—定义loss
损失为交叉熵,公式为
J = − 1 m ∑ i = 1 m ∑ j = 1 n y j i l o g ( y j ( i ) ) + ( 1 − y j ( i ) l o g ( 1 − y j ( i ) ) J=- \\frac 1m \\sum\_{i=1}^m\\sum\_{j=1}^n y\_j^{i}log(y\_j^{(i)}) + (1 - y\_j^{(i)}log(1-y\_j^{(i)}) J\=−m1i\=1∑mj\=1∑nyjilog(yj(i))\+(1−yj(i)log(1−yj(i))
公式分为两步:
1. 对n个标签计算交叉熵
2. 对m个样本取平均
```
python1 2
```
7\. BP部分—定义优化算法
```
1 2
```
TensorFlow中更多优化算法详见[官方文档](https://www.tensorflow.org/api_guides/python/train)。
8\. 定义初始化operation和准确率node
```
1 2 3 4 5 6
```
`correct_predicion`会返回一个 m × 1 m\\times 1 m×1的tensor,tensor的值为True/False表示是否正确预测。
#### Setting up the training
9\. 开始训练
```
python1 2 3 4 5 6 7 8 9 10 11 12 13
```
输出:
```
1 2 3 4 5 6 7 8 9 10 11 12 13
```
通过TensorBoard可视化训练过程:
\[外链图片转存失败(img-5NxdHJph-1565154313871)(<http://adventuresinmachinelearning.com/wp-content/uploads/2017/04/TensorBoard-increase-in-accuracy-NN.png>)\] |
| Shard | 8 (laksa) |
| Root Hash | 14895566225899102208 |
| Unparsed URL | net,csdn!blog,/hustqb/article/details/80222055 s443 |