Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
54a9f315
B
book
项目概览
PaddlePaddle
/
book
通知
16
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
40
列表
看板
标记
里程碑
合并请求
37
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
B
book
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
40
Issue
40
列表
看板
标记
里程碑
合并请求
37
合并请求
37
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
54a9f315
编写于
9月 21, 2020
作者:
T
TC.Long
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix model loss
上级
8c1aa4e6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
66 deletion
+52
-66
paddle2.0_docs/image_classification/mnist_lenet_classification.ipynb
...ocs/image_classification/mnist_lenet_classification.ipynb
+52
-66
未找到文件。
paddle2.0_docs/image_classification/mnist_lenet_classification.ipynb
浏览文件 @
54a9f315
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
3
,
"execution_count":
1
,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -47,7 +47,7 @@
...
@@ -47,7 +47,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
4
,
"execution_count":
3
,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -75,7 +75,7 @@
...
@@ -75,7 +75,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
5
,
"execution_count":
4
,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -118,7 +118,7 @@
...
@@ -118,7 +118,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
7
,
"execution_count":
6
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -162,33 +162,23 @@
...
@@ -162,33 +162,23 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1
0
,
"execution_count": 1
2
,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"output_type": "stream",
"text": [
"text": [
"epoch: 0, batch_id: 0, loss is: [2.3037894], acc is: [0.140625]\n",
"epoch: 0, batch_id: 0, loss is: [2.3017962], acc is: [0.28125]\n",
"epoch: 0, batch_id: 100, loss is: [1.6175328], acc is: [0.9375]\n",
"epoch: 0, batch_id: 200, loss is: [1.5294291], acc is: [0.96875]\n",
"epoch: 0, batch_id: 200, loss is: [1.5388051], acc is: [0.96875]\n",
"epoch: 0, batch_id: 400, loss is: [1.4693298], acc is: [1.]\n",
"epoch: 0, batch_id: 300, loss is: [1.5251061], acc is: [0.96875]\n",
"epoch: 0, batch_id: 600, loss is: [1.5237448], acc is: [0.984375]\n",
"epoch: 0, batch_id: 400, loss is: [1.4678856], acc is: [1.]\n",
"epoch: 0, batch_id: 800, loss is: [1.4795951], acc is: [0.984375]\n",
"epoch: 0, batch_id: 500, loss is: [1.4944503], acc is: [0.984375]\n",
"epoch: 1, batch_id: 0, loss is: [1.5161536], acc is: [0.96875]\n",
"epoch: 0, batch_id: 600, loss is: [1.5365536], acc is: [0.96875]\n",
"epoch: 1, batch_id: 200, loss is: [1.4763479], acc is: [1.]\n",
"epoch: 0, batch_id: 700, loss is: [1.4885054], acc is: [0.984375]\n",
"epoch: 1, batch_id: 400, loss is: [1.4929678], acc is: [1.]\n",
"epoch: 0, batch_id: 800, loss is: [1.4872254], acc is: [0.984375]\n",
"epoch: 1, batch_id: 600, loss is: [1.4999642], acc is: [1.]\n",
"epoch: 0, batch_id: 900, loss is: [1.4884174], acc is: [0.984375]\n",
"epoch: 1, batch_id: 800, loss is: [1.5029153], acc is: [0.984375]\n"
"epoch: 1, batch_id: 0, loss is: [1.4776722], acc is: [1.]\n",
"epoch: 1, batch_id: 100, loss is: [1.4751343], acc is: [1.]\n",
"epoch: 1, batch_id: 200, loss is: [1.4772581], acc is: [1.]\n",
"epoch: 1, batch_id: 300, loss is: [1.4918218], acc is: [0.984375]\n",
"epoch: 1, batch_id: 400, loss is: [1.5038397], acc is: [0.96875]\n",
"epoch: 1, batch_id: 500, loss is: [1.5088196], acc is: [0.96875]\n",
"epoch: 1, batch_id: 600, loss is: [1.4961376], acc is: [0.984375]\n",
"epoch: 1, batch_id: 700, loss is: [1.4755756], acc is: [1.]\n",
"epoch: 1, batch_id: 800, loss is: [1.4921497], acc is: [0.984375]\n",
"epoch: 1, batch_id: 900, loss is: [1.4944404], acc is: [1.]\n"
]
]
}
}
],
],
...
@@ -209,11 +199,9 @@
...
@@ -209,11 +199,9 @@
" loss = paddle.nn.functional.cross_entropy(predicts, y_data)\n",
" loss = paddle.nn.functional.cross_entropy(predicts, y_data)\n",
" # 计算损失\n",
" # 计算损失\n",
" acc = paddle.metric.accuracy(predicts, y_data, k=2)\n",
" acc = paddle.metric.accuracy(predicts, y_data, k=2)\n",
" avg_loss = paddle.mean(loss)\n",
" loss.backward()\n",
" avg_acc = paddle.mean(acc)\n",
" if batch_id % 200 == 0:\n",
" avg_loss.backward()\n",
" print(\"epoch: {}, batch_id: {}, loss is: {}, acc is: {}\".format(epoch, batch_id, loss.numpy(), acc.numpy()))\n",
" if batch_id % 100 == 0:\n",
" print(\"epoch: {}, batch_id: {}, loss is: {}, acc is: {}\".format(epoch, batch_id, avg_loss.numpy(), avg_acc.numpy()))\n",
" optim.step()\n",
" optim.step()\n",
" optim.clear_grad()\n",
" optim.clear_grad()\n",
"model = LeNet()\n",
"model = LeNet()\n",
...
@@ -230,21 +218,21 @@
...
@@ -230,21 +218,21 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1
1
,
"execution_count": 1
4
,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"output_type": "stream",
"text": [
"text": [
"batch_id: 0, loss is: [1.4
915928
], acc is: [1.]\n",
"batch_id: 0, loss is: [1.4
616354
], acc is: [1.]\n",
"batch_id: 20, loss is: [1.4
818308], acc is: [1.
]\n",
"batch_id: 20, loss is: [1.4
927294], acc is: [0.984375
]\n",
"batch_id: 40, loss is: [1.
5006062], acc is: [0.984375
]\n",
"batch_id: 40, loss is: [1.
4990321], acc is: [1.
]\n",
"batch_id: 60, loss is: [1.
521233
], acc is: [1.]\n",
"batch_id: 60, loss is: [1.
4892884
], acc is: [1.]\n",
"batch_id: 80, loss is: [1.47
72738
], acc is: [1.]\n",
"batch_id: 80, loss is: [1.47
67071
], acc is: [1.]\n",
"batch_id: 100, loss is: [1.4
755945
], acc is: [1.]\n",
"batch_id: 100, loss is: [1.4
611524
], acc is: [1.]\n",
"batch_id: 120, loss is: [1.4
746133
], acc is: [1.]\n",
"batch_id: 120, loss is: [1.4
613531
], acc is: [1.]\n",
"batch_id: 140, loss is: [1.4
78634
5], acc is: [1.]\n"
"batch_id: 140, loss is: [1.4
92831
5], acc is: [1.]\n"
]
]
}
}
],
],
...
@@ -262,11 +250,9 @@
...
@@ -262,11 +250,9 @@
" # 获取预测结果\n",
" # 获取预测结果\n",
" loss = paddle.nn.functional.cross_entropy(predicts, y_data)\n",
" loss = paddle.nn.functional.cross_entropy(predicts, y_data)\n",
" acc = paddle.metric.accuracy(predicts, y_data, k=2)\n",
" acc = paddle.metric.accuracy(predicts, y_data, k=2)\n",
" avg_loss = paddle.mean(loss)\n",
" loss.backward()\n",
" avg_acc = paddle.mean(acc)\n",
" avg_loss.backward()\n",
" if batch_id % 20 == 0:\n",
" if batch_id % 20 == 0:\n",
" print(\"batch_id: {}, loss is: {}, acc is: {}\".format(batch_id,
avg_loss.numpy(), avg_
acc.numpy()))\n",
" print(\"batch_id: {}, loss is: {}, acc is: {}\".format(batch_id,
loss.numpy(),
acc.numpy()))\n",
"test(model)"
"test(model)"
]
]
},
},
...
@@ -288,7 +274,7 @@
...
@@ -288,7 +274,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1
2
,
"execution_count": 1
5
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -316,7 +302,7 @@
...
@@ -316,7 +302,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1
6
,
"execution_count": 1
8
,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -324,17 +310,17 @@
...
@@ -324,17 +310,17 @@
"output_type": "stream",
"output_type": "stream",
"text": [
"text": [
"Epoch 1/2\n",
"Epoch 1/2\n",
"step 200/938 - loss: 1.
5219 - acc_top1: 0.9829 - acc_top2: 0.9965
- 14ms/step\n",
"step 200/938 - loss: 1.
4868 - acc_top1: 0.9805 - acc_top2: 0.9951
- 14ms/step\n",
"step 400/938 - loss: 1.4
765 - acc_top1: 0.9825 - acc_top2: 0.9958 - 13
ms/step\n",
"step 400/938 - loss: 1.4
643 - acc_top1: 0.9802 - acc_top2: 0.9944 - 14
ms/step\n",
"step 600/938 - loss: 1.46
24 - acc_top1: 0.9823 - acc_top2: 0.9953
- 13ms/step\n",
"step 600/938 - loss: 1.46
38 - acc_top1: 0.9799 - acc_top2: 0.9942
- 13ms/step\n",
"step 800/938 - loss: 1.476
8 - acc_top1: 0.9829 - acc_top2: 0.9955
- 13ms/step\n",
"step 800/938 - loss: 1.476
7 - acc_top1: 0.9801 - acc_top2: 0.9944
- 13ms/step\n",
"step 938/938 - loss: 1.461
2 - acc_top1: 0.9836 - acc_top2: 0.9956
- 13ms/step\n",
"step 938/938 - loss: 1.461
4 - acc_top1: 0.9804 - acc_top2: 0.9945
- 13ms/step\n",
"Epoch 2/2\n",
"Epoch 2/2\n",
"step 200/938 - loss: 1.4
705 - acc_top1: 0.9834 - acc_top2: 0.9959
- 13ms/step\n",
"step 200/938 - loss: 1.4
618 - acc_top1: 0.9812 - acc_top2: 0.9956
- 13ms/step\n",
"step 400/938 - loss: 1.4
620 - acc_top1: 0.9833 - acc_top2: 0.9960
- 13ms/step\n",
"step 400/938 - loss: 1.4
778 - acc_top1: 0.9804 - acc_top2: 0.9952
- 13ms/step\n",
"step 600/938 - loss: 1.46
13 - acc_top1: 0.9830 - acc_top2: 0.9960
- 13ms/step\n",
"step 600/938 - loss: 1.46
98 - acc_top1: 0.9810 - acc_top2: 0.9954
- 13ms/step\n",
"step 800/938 - loss: 1.4
763 - acc_top1: 0.9831 - acc_top2: 0.9960
- 13ms/step\n",
"step 800/938 - loss: 1.4
621 - acc_top1: 0.9815 - acc_top2: 0.9957
- 13ms/step\n",
"step 938/938 - loss: 1.4
924 - acc_top1: 0.9834 - acc_top2: 0.9959
- 13ms/step\n"
"step 938/938 - loss: 1.4
847 - acc_top1: 0.9814 - acc_top2: 0.9958
- 13ms/step\n"
]
]
}
}
],
],
...
@@ -355,7 +341,7 @@
...
@@ -355,7 +341,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1
7
,
"execution_count": 1
9
,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -363,24 +349,24 @@
...
@@ -363,24 +349,24 @@
"output_type": "stream",
"output_type": "stream",
"text": [
"text": [
"Eval begin...\n",
"Eval begin...\n",
"step 20/157 - loss: 1.5
246 - acc_top1: 0.9773 - acc_top2: 0.9969 - 6
ms/step\n",
"step 20/157 - loss: 1.5
160 - acc_top1: 0.9805 - acc_top2: 0.9930 - 7
ms/step\n",
"step 40/157 - loss: 1.46
22 - acc_top1: 0.9758 - acc_top2: 0.9961
- 6ms/step\n",
"step 40/157 - loss: 1.46
12 - acc_top1: 0.9793 - acc_top2: 0.9949
- 6ms/step\n",
"step 60/157 - loss: 1.5
241 - acc_top1: 0.9763 - acc_top2: 0.9951
- 6ms/step\n",
"step 60/157 - loss: 1.5
095 - acc_top1: 0.9792 - acc_top2: 0.9943
- 6ms/step\n",
"step 80/157 - loss: 1.4612 - acc_top1: 0.978
7 - acc_top2: 0.9959
- 6ms/step\n",
"step 80/157 - loss: 1.4612 - acc_top1: 0.978
5 - acc_top2: 0.9941
- 6ms/step\n",
"step 100/157 - loss: 1.4612 - acc_top1: 0.98
23 - acc_top2: 0.9967 - 5
ms/step\n",
"step 100/157 - loss: 1.4612 - acc_top1: 0.98
16 - acc_top2: 0.9950 - 6
ms/step\n",
"step 120/157 - loss: 1.4
612 - acc_top1: 0.9835 - acc_top2: 0.9966 - 5
ms/step\n",
"step 120/157 - loss: 1.4
763 - acc_top1: 0.9832 - acc_top2: 0.9954 - 6
ms/step\n",
"step 140/157 - loss: 1.4612 - acc_top1: 0.984
4 - acc_top2: 0.9969 - 5
ms/step\n",
"step 140/157 - loss: 1.4612 - acc_top1: 0.984
9 - acc_top2: 0.9959 - 6
ms/step\n",
"step 157/157 - loss: 1.4612 - acc_top1: 0.98
38 - acc_top2: 0.9966 - 5
ms/step\n",
"step 157/157 - loss: 1.4612 - acc_top1: 0.98
44 - acc_top2: 0.9959 - 6
ms/step\n",
"Eval samples: 10000\n"
"Eval samples: 10000\n"
]
]
},
},
{
{
"data": {
"data": {
"text/plain": [
"text/plain": [
"{'loss': [1.4611504], 'acc_top1': 0.98
38, 'acc_top2': 0.9966
}"
"{'loss': [1.4611504], 'acc_top1': 0.98
44, 'acc_top2': 0.9959
}"
]
]
},
},
"execution_count": 1
7
,
"execution_count": 1
9
,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录