基于Tensorflow keras的线性回归模型实现

首先参考这篇文章安装开发环境:

Win10上安装anaconda深度学习开发环境

吐槽一句,python语言以及基于python语言之上构建的深度学习开发环境虽然极大方便了学习和开发,但是处理包管理,以及包之间的依赖关系一团乱麻,简直让人崩溃,比如python的版本不同,算法包以及运行时环境包的版本就需要选择指定版本,而且这种包和python版本之间的依赖关系已经敏感到让人发指的地步,即使是python的小版本变化也会导致之前可用的包无法运行。更加雪上加霜的是,tensorflow,keras的版本管理也不必python好多少,经常是不同版本上的开发API都风格迥异,很多时候,费尽心血搭建的开发环境可能根本无法执行你的代码。说多了都是泪,希望未来的某个版本做一次整合吧,为环境安装操碎了心。

经过七七四十九天,历经九九八十一难,这是我验证成功的环境各主要包的运行版本:

基于Tensorflow keras的线性回归模型实现

开发keras程序:

这是一个线性回归的用例,下面的代码试图找到两笔数据之间的关系,算法过程首先使用这笔数据对模型进行500次训练,并输出LOSS值,之后,使用得到的模型预测当变量为10的时候的正确输出。

预先设计的的模型是

基于Tensorflow keras的线性回归模型实现

所以,如果模型正确,最后得到的10的预测值应该在19附近.

import numpy as np
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout

model = Sequential()
model.add(Dense(1, input_dim=1))
model.compile(optimizer="sgd", loss="mean_squared_error")
xs=np.array([-1.0,0.0,1.0,2.0,3.0,4.0],dtype=float)
ys=np.array([-3.0,-1.0,1.0,3.0,5.0,7.0],dtype=float)
model.fit(xs,ys, epochs=500)
model.summary()
model.predict(np.array([10.0]))

运行结果:

基于Tensorflow keras的线性回归模型实现

 计算过程中loss的变化:

Epoch 1/500
6/6 [==============================] - 0s - loss: 10.7663
Epoch 2/500
6/6 [==============================] - 0s - loss: 8.6860
Epoch 3/500
6/6 [==============================] - 0s - loss: 7.0449
Epoch 4/500
6/6 [==============================] - 0s - loss: 5.7494
Epoch 5/500
6/6 [==============================] - 0s - loss: 4.7259
Epoch 6/500
6/6 [==============================] - 0s - loss: 3.9165
Epoch 7/500
6/6 [==============================] - 0s - loss: 3.2757
Epoch 8/500
6/6 [==============================] - 0s - loss: 2.7675
Epoch 9/500
6/6 [==============================] - 0s - loss: 2.3638
Epoch 10/500
6/6 [==============================] - 0s - loss: 2.0423
Epoch 11/500
6/6 [==============================] - 0s - loss: 1.7857
Epoch 12/500
6/6 [==============================] - 0s - loss: 1.5800
Epoch 13/500
6/6 [==============================] - 0s - loss: 1.4147
Epoch 14/500
6/6 [==============================] - 0s - loss: 1.2811
Epoch 15/500
6/6 [==============================] - 0s - loss: 1.1725
Epoch 16/500
6/6 [==============================] - 0s - loss: 1.0837
Epoch 17/500
6/6 [==============================] - 0s - loss: 1.0105
Epoch 18/500
6/6 [==============================] - 0s - loss: 0.9497
Epoch 19/500
6/6 [==============================] - 0s - loss: 0.8987
Epoch 20/500
6/6 [==============================] - 0s - loss: 0.8554
Epoch 21/500
6/6 [==============================] - 0s - loss: 0.8183
Epoch 22/500
6/6 [==============================] - 0s - loss: 0.7862
Epoch 23/500
6/6 [==============================] - 0s - loss: 0.7580
Epoch 24/500
6/6 [==============================] - 0s - loss: 0.7329
Epoch 25/500
6/6 [==============================] - 0s - loss: 0.7104
Epoch 26/500
6/6 [==============================] - 0s - loss: 0.6899
Epoch 27/500
6/6 [==============================] - 0s - loss: 0.6711
Epoch 28/500
6/6 [==============================] - 0s - loss: 0.6537
Epoch 29/500
6/6 [==============================] - 0s - loss: 0.6374
Epoch 30/500
6/6 [==============================] - 0s - loss: 0.6220
Epoch 31/500
6/6 [==============================] - 0s - loss: 0.6075
Epoch 32/500
6/6 [==============================] - 0s - loss: 0.5936
Epoch 33/500
6/6 [==============================] - 0s - loss: 0.5803
Epoch 34/500
6/6 [==============================] - 0s - loss: 0.5675
Epoch 35/500
6/6 [==============================] - 0s - loss: 0.5552
Epoch 36/500
6/6 [==============================] - 0s - loss: 0.5433
Epoch 37/500
6/6 [==============================] - 0s - loss: 0.5317
Epoch 38/500
6/6 [==============================] - 0s - loss: 0.5204
Epoch 39/500
6/6 [==============================] - 0s - loss: 0.5095
Epoch 40/500
6/6 [==============================] - 0s - loss: 0.4988
Epoch 41/500
6/6 [==============================] - 0s - loss: 0.4884
Epoch 42/500
6/6 [==============================] - 0s - loss: 0.4782
Epoch 43/500
6/6 [==============================] - 0s - loss: 0.4683
Epoch 44/500
6/6 [==============================] - 0s - loss: 0.4586
Epoch 45/500
6/6 [==============================] - 0s - loss: 0.4491
Epoch 46/500
6/6 [==============================] - 0s - loss: 0.4399
Epoch 47/500
6/6 [==============================] - 0s - loss: 0.4308
Epoch 48/500
6/6 [==============================] - 0s - loss: 0.4219
Epoch 49/500
6/6 [==============================] - 0s - loss: 0.4132
Epoch 50/500
6/6 [==============================] - 0s - loss: 0.4047
Epoch 51/500
6/6 [==============================] - 0s - loss: 0.3964
Epoch 52/500
6/6 [==============================] - 0s - loss: 0.3882
Epoch 53/500
6/6 [==============================] - 0s - loss: 0.3802
Epoch 54/500
6/6 [==============================] - 0s - loss: 0.3724
Epoch 55/500
6/6 [==============================] - 0s - loss: 0.3648
Epoch 56/500
6/6 [==============================] - 0s - loss: 0.3573
Epoch 57/500
6/6 [==============================] - 0s - loss: 0.3499
Epoch 58/500
6/6 [==============================] - 0s - loss: 0.3427
Epoch 59/500
6/6 [==============================] - 0s - loss: 0.3357
Epoch 60/500
6/6 [==============================] - 0s - loss: 0.3288
Epoch 61/500
6/6 [==============================] - 0s - loss: 0.3221
Epoch 62/500
6/6 [==============================] - 0s - loss: 0.3154
Epoch 63/500
6/6 [==============================] - 0s - loss: 0.3090
Epoch 64/500
6/6 [==============================] - 0s - loss: 0.3026
Epoch 65/500
6/6 [==============================] - 0s - loss: 0.2964
Epoch 66/500
6/6 [==============================] - 0s - loss: 0.2903
Epoch 67/500
6/6 [==============================] - 0s - loss: 0.2843
Epoch 68/500
6/6 [==============================] - 0s - loss: 0.2785
Epoch 69/500
6/6 [==============================] - 0s - loss: 0.2728
Epoch 70/500
6/6 [==============================] - 0s - loss: 0.2672
Epoch 71/500
6/6 [==============================] - 0s - loss: 0.2617
Epoch 72/500
6/6 [==============================] - 0s - loss: 0.2563
Epoch 73/500
6/6 [==============================] - 0s - loss: 0.2510
Epoch 74/500
6/6 [==============================] - 0s - loss: 0.2459
Epoch 75/500
6/6 [==============================] - 0s - loss: 0.2408
Epoch 76/500
6/6 [==============================] - 0s - loss: 0.2359
Epoch 77/500
6/6 [==============================] - 0s - loss: 0.2310
Epoch 78/500
6/6 [==============================] - 0s - loss: 0.2263
Epoch 79/500
6/6 [==============================] - 0s - loss: 0.2217
Epoch 80/500
6/6 [==============================] - 0s - loss: 0.2171
Epoch 81/500
6/6 [==============================] - 0s - loss: 0.2126
Epoch 82/500
6/6 [==============================] - 0s - loss: 0.2083
Epoch 83/500
6/6 [==============================] - 0s - loss: 0.2040
Epoch 84/500
6/6 [==============================] - 0s - loss: 0.1998
Epoch 85/500
6/6 [==============================] - 0s - loss: 0.1957
Epoch 86/500
6/6 [==============================] - 0s - loss: 0.1917
Epoch 87/500
6/6 [==============================] - 0s - loss: 0.1877
Epoch 88/500
6/6 [==============================] - 0s - loss: 0.1839
Epoch 89/500
6/6 [==============================] - 0s - loss: 0.1801
Epoch 90/500
6/6 [==============================] - 0s - loss: 0.1764
Epoch 91/500
6/6 [==============================] - 0s - loss: 0.1728
Epoch 92/500
6/6 [==============================] - 0s - loss: 0.1692
Epoch 93/500
6/6 [==============================] - 0s - loss: 0.1658
Epoch 94/500
6/6 [==============================] - 0s - loss: 0.1624
Epoch 95/500
6/6 [==============================] - 0s - loss: 0.1590
Epoch 96/500
6/6 [==============================] - 0s - loss: 0.1558
Epoch 97/500
6/6 [==============================] - 0s - loss: 0.1526
Epoch 98/500
6/6 [==============================] - 0s - loss: 0.1494
Epoch 99/500
6/6 [==============================] - 0s - loss: 0.1464
Epoch 100/500
6/6 [==============================] - 0s - loss: 0.1433
Epoch 101/500
6/6 [==============================] - 0s - loss: 0.1404
Epoch 102/500
6/6 [==============================] - 0s - loss: 0.1375
Epoch 103/500
6/6 [==============================] - 0s - loss: 0.1347
Epoch 104/500
6/6 [==============================] - 0s - loss: 0.1319
Epoch 105/500
6/6 [==============================] - 0s - loss: 0.1292
Epoch 106/500
6/6 [==============================] - 0s - loss: 0.1266
Epoch 107/500
6/6 [==============================] - 0s - loss: 0.1240
Epoch 108/500
6/6 [==============================] - 0s - loss: 0.1214
Epoch 109/500
6/6 [==============================] - 0s - loss: 0.1189
Epoch 110/500
6/6 [==============================] - 0s - loss: 0.1165
Epoch 111/500
6/6 [==============================] - 0s - loss: 0.1141
Epoch 112/500
6/6 [==============================] - 0s - loss: 0.1117
Epoch 113/500
6/6 [==============================] - 0s - loss: 0.1094
Epoch 114/500
6/6 [==============================] - 0s - loss: 0.1072
Epoch 115/500
6/6 [==============================] - 0s - loss: 0.1050
Epoch 116/500
6/6 [==============================] - 0s - loss: 0.1028
Epoch 117/500
6/6 [==============================] - 0s - loss: 0.1007
Epoch 118/500
6/6 [==============================] - 0s - loss: 0.0987
Epoch 119/500
6/6 [==============================] - 0s - loss: 0.0966
Epoch 120/500
6/6 [==============================] - 0s - loss: 0.0946
Epoch 121/500
6/6 [==============================] - 0s - loss: 0.0927
Epoch 122/500
6/6 [==============================] - 0s - loss: 0.0908
Epoch 123/500
6/6 [==============================] - 0s - loss: 0.0889
Epoch 124/500
6/6 [==============================] - 0s - loss: 0.0871
Epoch 125/500
6/6 [==============================] - 0s - loss: 0.0853
Epoch 126/500
6/6 [==============================] - 0s - loss: 0.0836
Epoch 127/500
6/6 [==============================] - 0s - loss: 0.0819
Epoch 128/500
6/6 [==============================] - 0s - loss: 0.0802
Epoch 129/500
6/6 [==============================] - 0s - loss: 0.0785
Epoch 130/500
6/6 [==============================] - 0s - loss: 0.0769
Epoch 131/500
6/6 [==============================] - 0s - loss: 0.0753
Epoch 132/500
6/6 [==============================] - 0s - loss: 0.0738
Epoch 133/500
6/6 [==============================] - 0s - loss: 0.0723
Epoch 134/500
6/6 [==============================] - 0s - loss: 0.0708
Epoch 135/500
6/6 [==============================] - 0s - loss: 0.0693
Epoch 136/500
6/6 [==============================] - 0s - loss: 0.0679
Epoch 137/500
6/6 [==============================] - 0s - loss: 0.0665
Epoch 138/500
6/6 [==============================] - 0s - loss: 0.0651
Epoch 139/500
6/6 [==============================] - 0s - loss: 0.0638
Epoch 140/500
6/6 [==============================] - 0s - loss: 0.0625
Epoch 141/500
6/6 [==============================] - 0s - loss: 0.0612
Epoch 142/500
6/6 [==============================] - 0s - loss: 0.0600
Epoch 143/500
6/6 [==============================] - 0s - loss: 0.0587
Epoch 144/500
6/6 [==============================] - 0s - loss: 0.0575
Epoch 145/500
6/6 [==============================] - 0s - loss: 0.0563
Epoch 146/500
6/6 [==============================] - 0s - loss: 0.0552
Epoch 147/500
6/6 [==============================] - 0s - loss: 0.0540
Epoch 148/500
6/6 [==============================] - 0s - loss: 0.0529
Epoch 149/500
6/6 [==============================] - 0s - loss: 0.0518
Epoch 150/500
6/6 [==============================] - 0s - loss: 0.0508
Epoch 151/500
6/6 [==============================] - 0s - loss: 0.0497
Epoch 152/500
6/6 [==============================] - 0s - loss: 0.0487
Epoch 153/500
6/6 [==============================] - 0s - loss: 0.0477
Epoch 154/500
6/6 [==============================] - 0s - loss: 0.0467
Epoch 155/500
6/6 [==============================] - 0s - loss: 0.0458
Epoch 156/500
6/6 [==============================] - 0s - loss: 0.0448
Epoch 157/500
6/6 [==============================] - 0s - loss: 0.0439
Epoch 158/500
6/6 [==============================] - 0s - loss: 0.0430
Epoch 159/500
6/6 [==============================] - 0s - loss: 0.0421
Epoch 160/500
6/6 [==============================] - 0s - loss: 0.0413
Epoch 161/500
6/6 [==============================] - 0s - loss: 0.0404
Epoch 162/500
6/6 [==============================] - 0s - loss: 0.0396
Epoch 163/500
6/6 [==============================] - 0s - loss: 0.0388
Epoch 164/500
6/6 [==============================] - 0s - loss: 0.0380
Epoch 165/500
6/6 [==============================] - 0s - loss: 0.0372
Epoch 166/500
6/6 [==============================] - 0s - loss: 0.0364
Epoch 167/500
6/6 [==============================] - 0s - loss: 0.0357
Epoch 168/500
6/6 [==============================] - 0s - loss: 0.0350
Epoch 169/500
6/6 [==============================] - 0s - loss: 0.0342
Epoch 170/500
6/6 [==============================] - 0s - loss: 0.0335
Epoch 171/500
6/6 [==============================] - 0s - loss: 0.0328
Epoch 172/500
6/6 [==============================] - 0s - loss: 0.0322
Epoch 173/500
6/6 [==============================] - 0s - loss: 0.0315
Epoch 174/500
6/6 [==============================] - 0s - loss: 0.0309
Epoch 175/500
6/6 [==============================] - 0s - loss: 0.0302
Epoch 176/500
6/6 [==============================] - 0s - loss: 0.0296
Epoch 177/500
6/6 [==============================] - 0s - loss: 0.0290
Epoch 178/500
6/6 [==============================] - 0s - loss: 0.0284
Epoch 179/500
6/6 [==============================] - 0s - loss: 0.0278
Epoch 180/500
6/6 [==============================] - 0s - loss: 0.0272
Epoch 181/500
6/6 [==============================] - 0s - loss: 0.0267
Epoch 182/500
6/6 [==============================] - 0s - loss: 0.0261
Epoch 183/500
6/6 [==============================] - 0s - loss: 0.0256
Epoch 184/500
6/6 [==============================] - 0s - loss: 0.0251
Epoch 185/500
6/6 [==============================] - 0s - loss: 0.0246
Epoch 186/500
6/6 [==============================] - 0s - loss: 0.0241
Epoch 187/500
6/6 [==============================] - 0s - loss: 0.0236
Epoch 188/500
6/6 [==============================] - 0s - loss: 0.0231
Epoch 189/500
6/6 [==============================] - 0s - loss: 0.0226
Epoch 190/500
6/6 [==============================] - 0s - loss: 0.0221
Epoch 191/500
6/6 [==============================] - 0s - loss: 0.0217
Epoch 192/500
6/6 [==============================] - 0s - loss: 0.0212
Epoch 193/500
6/6 [==============================] - 0s - loss: 0.0208
Epoch 194/500
6/6 [==============================] - 0s - loss: 0.0204
Epoch 195/500
6/6 [==============================] - 0s - loss: 0.0200
Epoch 196/500
6/6 [==============================] - 0s - loss: 0.0195
Epoch 197/500
6/6 [==============================] - 0s - loss: 0.0191
Epoch 198/500
6/6 [==============================] - 0s - loss: 0.0188
Epoch 199/500
6/6 [==============================] - 0s - loss: 0.0184
Epoch 200/500
6/6 [==============================] - 0s - loss: 0.0180
Epoch 201/500
6/6 [==============================] - 0s - loss: 0.0176
Epoch 202/500
6/6 [==============================] - 0s - loss: 0.0173
Epoch 203/500
6/6 [==============================] - 0s - loss: 0.0169
Epoch 204/500
6/6 [==============================] - 0s - loss: 0.0166
Epoch 205/500
6/6 [==============================] - 0s - loss: 0.0162
Epoch 206/500
6/6 [==============================] - 0s - loss: 0.0159
Epoch 207/500
6/6 [==============================] - 0s - loss: 0.0156
Epoch 208/500
6/6 [==============================] - 0s - loss: 0.0152
Epoch 209/500
6/6 [==============================] - 0s - loss: 0.0149
Epoch 210/500
6/6 [==============================] - 0s - loss: 0.0146
Epoch 211/500
6/6 [==============================] - 0s - loss: 0.0143
Epoch 212/500
6/6 [==============================] - 0s - loss: 0.0140
Epoch 213/500
6/6 [==============================] - 0s - loss: 0.0137
Epoch 214/500
6/6 [==============================] - 0s - loss: 0.0135
Epoch 215/500
6/6 [==============================] - 0s - loss: 0.0132
Epoch 216/500
6/6 [==============================] - 0s - loss: 0.0129
Epoch 217/500
6/6 [==============================] - 0s - loss: 0.0126
Epoch 218/500
6/6 [==============================] - 0s - loss: 0.0124
Epoch 219/500
6/6 [==============================] - 0s - loss: 0.0121
Epoch 220/500
6/6 [==============================] - 0s - loss: 0.0119
Epoch 221/500
6/6 [==============================] - 0s - loss: 0.0116
Epoch 222/500
6/6 [==============================] - 0s - loss: 0.0114
Epoch 223/500
6/6 [==============================] - 0s - loss: 0.0112
Epoch 224/500
6/6 [==============================] - 0s - loss: 0.0109
Epoch 225/500
6/6 [==============================] - 0s - loss: 0.0107
Epoch 226/500
6/6 [==============================] - 0s - loss: 0.0105
Epoch 227/500
6/6 [==============================] - 0s - loss: 0.0103
Epoch 228/500
6/6 [==============================] - 0s - loss: 0.0101
Epoch 229/500
6/6 [==============================] - 0s - loss: 0.0099
Epoch 230/500
6/6 [==============================] - 0s - loss: 0.0097
Epoch 231/500
6/6 [==============================] - 0s - loss: 0.0095
Epoch 232/500
6/6 [==============================] - 0s - loss: 0.0093
Epoch 233/500
6/6 [==============================] - 0s - loss: 0.0091
Epoch 234/500
6/6 [==============================] - 0s - loss: 0.0089
Epoch 235/500
6/6 [==============================] - 0s - loss: 0.0087
Epoch 236/500
6/6 [==============================] - 0s - loss: 0.0085
Epoch 237/500
6/6 [==============================] - 0s - loss: 0.0083
Epoch 238/500
6/6 [==============================] - 0s - loss: 0.0082
Epoch 239/500
6/6 [==============================] - 0s - loss: 0.0080
Epoch 240/500
6/6 [==============================] - 0s - loss: 0.0078
Epoch 241/500
6/6 [==============================] - 0s - loss: 0.0077
Epoch 242/500
6/6 [==============================] - 0s - loss: 0.0075
Epoch 243/500
6/6 [==============================] - 0s - loss: 0.0074
Epoch 244/500
6/6 [==============================] - 0s - loss: 0.0072
Epoch 245/500
6/6 [==============================] - 0s - loss: 0.0071
Epoch 246/500
6/6 [==============================] - 0s - loss: 0.0069
Epoch 247/500
6/6 [==============================] - 0s - loss: 0.0068
Epoch 248/500
6/6 [==============================] - 0s - loss: 0.0066
Epoch 249/500
6/6 [==============================] - 0s - loss: 0.0065
Epoch 250/500
6/6 [==============================] - 0s - loss: 0.0064
Epoch 251/500
6/6 [==============================] - 0s - loss: 0.0062
Epoch 252/500
6/6 [==============================] - 0s - loss: 0.0061
Epoch 253/500
6/6 [==============================] - 0s - loss: 0.0060
Epoch 254/500
6/6 [==============================] - 0s - loss: 0.0059
Epoch 255/500
6/6 [==============================] - 0s - loss: 0.0057
Epoch 256/500
6/6 [==============================] - 0s - loss: 0.0056
Epoch 257/500
6/6 [==============================] - 0s - loss: 0.0055
Epoch 258/500
6/6 [==============================] - 0s - loss: 0.0054
Epoch 259/500
6/6 [==============================] - 0s - loss: 0.0053
Epoch 260/500
6/6 [==============================] - 0s - loss: 0.0052
Epoch 261/500
6/6 [==============================] - 0s - loss: 0.0051
Epoch 262/500
6/6 [==============================] - 0s - loss: 0.0050
Epoch 263/500
6/6 [==============================] - 0s - loss: 0.0049
Epoch 264/500
6/6 [==============================] - 0s - loss: 0.0048
Epoch 265/500
6/6 [==============================] - 0s - loss: 0.0047
Epoch 266/500
6/6 [==============================] - 0s - loss: 0.0046
Epoch 267/500
6/6 [==============================] - 0s - loss: 0.0045
Epoch 268/500
6/6 [==============================] - 0s - loss: 0.0044
Epoch 269/500
6/6 [==============================] - 0s - loss: 0.0043
Epoch 270/500
6/6 [==============================] - 0s - loss: 0.0042
Epoch 271/500
6/6 [==============================] - 0s - loss: 0.0041
Epoch 272/500
6/6 [==============================] - 0s - loss: 0.0040
Epoch 273/500
6/6 [==============================] - 0s - loss: 0.0040
Epoch 274/500
6/6 [==============================] - 0s - loss: 0.0039
Epoch 275/500
6/6 [==============================] - 0s - loss: 0.0038
Epoch 276/500
6/6 [==============================] - 0s - loss: 0.0037
Epoch 277/500
6/6 [==============================] - 0s - loss: 0.0036
Epoch 278/500
6/6 [==============================] - 0s - loss: 0.0036
Epoch 279/500
6/6 [==============================] - 0s - loss: 0.0035
Epoch 280/500
6/6 [==============================] - 0s - loss: 0.0034
Epoch 281/500
6/6 [==============================] - 0s - loss: 0.0033
Epoch 282/500
6/6 [==============================] - 0s - loss: 0.0033
Epoch 283/500
6/6 [==============================] - 0s - loss: 0.0032
Epoch 284/500
6/6 [==============================] - 0s - loss: 0.0031
Epoch 285/500
6/6 [==============================] - 0s - loss: 0.0031
Epoch 286/500
6/6 [==============================] - 0s - loss: 0.0030
Epoch 287/500
6/6 [==============================] - 0s - loss: 0.0030
Epoch 288/500
6/6 [==============================] - 0s - loss: 0.0029
Epoch 289/500
6/6 [==============================] - 0s - loss: 0.0028
Epoch 290/500
6/6 [==============================] - 0s - loss: 0.0028
Epoch 291/500
6/6 [==============================] - 0s - loss: 0.0027
Epoch 292/500
6/6 [==============================] - 0s - loss: 0.0027
Epoch 293/500
6/6 [==============================] - 0s - loss: 0.0026
Epoch 294/500
6/6 [==============================] - 0s - loss: 0.0026
Epoch 295/500
6/6 [==============================] - 0s - loss: 0.0025
Epoch 296/500
6/6 [==============================] - 0s - loss: 0.0025
Epoch 297/500
6/6 [==============================] - 0s - loss: 0.0024
Epoch 298/500
6/6 [==============================] - 0s - loss: 0.0024
Epoch 299/500
6/6 [==============================] - 0s - loss: 0.0023
Epoch 300/500
6/6 [==============================] - 0s - loss: 0.0023
Epoch 301/500
6/6 [==============================] - 0s - loss: 0.0022
Epoch 302/500
6/6 [==============================] - 0s - loss: 0.0022
Epoch 303/500
6/6 [==============================] - 0s - loss: 0.0021
Epoch 304/500
6/6 [==============================] - 0s - loss: 0.0021
Epoch 305/500
6/6 [==============================] - 0s - loss: 0.0020
Epoch 306/500
6/6 [==============================] - 0s - loss: 0.0020
Epoch 307/500
6/6 [==============================] - 0s - loss: 0.0020
Epoch 308/500
6/6 [==============================] - 0s - loss: 0.0019
Epoch 309/500
6/6 [==============================] - 0s - loss: 0.0019
Epoch 310/500
6/6 [==============================] - 0s - loss: 0.0018
Epoch 311/500
6/6 [==============================] - 0s - loss: 0.0018
Epoch 312/500
6/6 [==============================] - 0s - loss: 0.0018
Epoch 313/500
6/6 [==============================] - 0s - loss: 0.0017
Epoch 314/500
6/6 [==============================] - 0s - loss: 0.0017
Epoch 315/500
6/6 [==============================] - 0s - loss: 0.0017
Epoch 316/500
6/6 [==============================] - 0s - loss: 0.0016
Epoch 317/500
6/6 [==============================] - 0s - loss: 0.0016
Epoch 318/500
6/6 [==============================] - 0s - loss: 0.0016
Epoch 319/500
6/6 [==============================] - 0s - loss: 0.0015
Epoch 320/500
6/6 [==============================] - 0s - loss: 0.0015
Epoch 321/500
6/6 [==============================] - 0s - loss: 0.0015
Epoch 322/500
6/6 [==============================] - 0s - loss: 0.0014
Epoch 323/500
6/6 [==============================] - 0s - loss: 0.0014
Epoch 324/500
6/6 [==============================] - 0s - loss: 0.0014
Epoch 325/500
6/6 [==============================] - 0s - loss: 0.0013
Epoch 326/500
6/6 [==============================] - 0s - loss: 0.0013
Epoch 327/500
6/6 [==============================] - 0s - loss: 0.0013
Epoch 328/500
6/6 [==============================] - 0s - loss: 0.0013
Epoch 329/500
6/6 [==============================] - 0s - loss: 0.0012
Epoch 330/500
6/6 [==============================] - 0s - loss: 0.0012
Epoch 331/500
6/6 [==============================] - 0s - loss: 0.0012
Epoch 332/500
6/6 [==============================] - 0s - loss: 0.0012
Epoch 333/500
6/6 [==============================] - 0s - loss: 0.0011
Epoch 334/500
6/6 [==============================] - 0s - loss: 0.0011
Epoch 335/500
6/6 [==============================] - 0s - loss: 0.0011
Epoch 336/500
6/6 [==============================] - 0s - loss: 0.0011
Epoch 337/500
6/6 [==============================] - 0s - loss: 0.0010
Epoch 338/500
6/6 [==============================] - 0s - loss: 0.0010
Epoch 339/500
6/6 [==============================] - 0s - loss: 0.0010
Epoch 340/500
6/6 [==============================] - 0s - loss: 9.8431e-04
Epoch 341/500
6/6 [==============================] - 0s - loss: 9.6409e-04
Epoch 342/500
6/6 [==============================] - 0s - loss: 9.4429e-04
Epoch 343/500
6/6 [==============================] - 0s - loss: 9.2489e-04
Epoch 344/500
6/6 [==============================] - 0s - loss: 9.0590e-04
Epoch 345/500
6/6 [==============================] - 0s - loss: 8.8729e-04
Epoch 346/500
6/6 [==============================] - 0s - loss: 8.6906e-04
Epoch 347/500
6/6 [==============================] - 0s - loss: 8.5121e-04
Epoch 348/500
6/6 [==============================] - 0s - loss: 8.3372e-04
Epoch 349/500
6/6 [==============================] - 0s - loss: 8.1660e-04
Epoch 350/500
6/6 [==============================] - 0s - loss: 7.9983e-04
Epoch 351/500
6/6 [==============================] - 0s - loss: 7.8340e-04
Epoch 352/500
6/6 [==============================] - 0s - loss: 7.6730e-04
Epoch 353/500
6/6 [==============================] - 0s - loss: 7.5155e-04
Epoch 354/500
6/6 [==============================] - 0s - loss: 7.3610e-04
Epoch 355/500
6/6 [==============================] - 0s - loss: 7.2099e-04
Epoch 356/500
6/6 [==============================] - 0s - loss: 7.0618e-04
Epoch 357/500
6/6 [==============================] - 0s - loss: 6.9167e-04
Epoch 358/500
6/6 [==============================] - 0s - loss: 6.7746e-04
Epoch 359/500
6/6 [==============================] - 0s - loss: 6.6354e-04
Epoch 360/500
6/6 [==============================] - 0s - loss: 6.4992e-04
Epoch 361/500
6/6 [==============================] - 0s - loss: 6.3657e-04
Epoch 362/500
6/6 [==============================] - 0s - loss: 6.2349e-04
Epoch 363/500
6/6 [==============================] - 0s - loss: 6.1068e-04
Epoch 364/500
6/6 [==============================] - 0s - loss: 5.9814e-04
Epoch 365/500
6/6 [==============================] - 0s - loss: 5.8585e-04
Epoch 366/500
6/6 [==============================] - 0s - loss: 5.7382e-04
Epoch 367/500
6/6 [==============================] - 0s - loss: 5.6203e-04
Epoch 368/500
6/6 [==============================] - 0s - loss: 5.5049e-04
Epoch 369/500
6/6 [==============================] - 0s - loss: 5.3918e-04
Epoch 370/500
6/6 [==============================] - 0s - loss: 5.2811e-04
Epoch 371/500
6/6 [==============================] - 0s - loss: 5.1726e-04
Epoch 372/500
6/6 [==============================] - 0s - loss: 5.0664e-04
Epoch 373/500
6/6 [==============================] - 0s - loss: 4.9623e-04
Epoch 374/500
6/6 [==============================] - 0s - loss: 4.8604e-04
Epoch 375/500
6/6 [==============================] - 0s - loss: 4.7606e-04
Epoch 376/500
6/6 [==============================] - 0s - loss: 4.6628e-04
Epoch 377/500
6/6 [==============================] - 0s - loss: 4.5670e-04
Epoch 378/500
6/6 [==============================] - 0s - loss: 4.4732e-04
Epoch 379/500
6/6 [==============================] - 0s - loss: 4.3813e-04
Epoch 380/500
6/6 [==============================] - 0s - loss: 4.2913e-04
Epoch 381/500
6/6 [==============================] - 0s - loss: 4.2032e-04
Epoch 382/500
6/6 [==============================] - 0s - loss: 4.1169e-04
Epoch 383/500
6/6 [==============================] - 0s - loss: 4.0323e-04
Epoch 384/500
6/6 [==============================] - 0s - loss: 3.9494e-04
Epoch 385/500
6/6 [==============================] - 0s - loss: 3.8683e-04
Epoch 386/500
6/6 [==============================] - 0s - loss: 3.7889e-04
Epoch 387/500
6/6 [==============================] - 0s - loss: 3.7110e-04
Epoch 388/500
6/6 [==============================] - 0s - loss: 3.6348e-04
Epoch 389/500
6/6 [==============================] - 0s - loss: 3.5602e-04
Epoch 390/500
6/6 [==============================] - 0s - loss: 3.4870e-04
Epoch 391/500
6/6 [==============================] - 0s - loss: 3.4154e-04
Epoch 392/500
6/6 [==============================] - 0s - loss: 3.3453e-04
Epoch 393/500
6/6 [==============================] - 0s - loss: 3.2765e-04
Epoch 394/500
6/6 [==============================] - 0s - loss: 3.2092e-04
Epoch 395/500
6/6 [==============================] - 0s - loss: 3.1433e-04
Epoch 396/500
6/6 [==============================] - 0s - loss: 3.0788e-04
Epoch 397/500
6/6 [==============================] - 0s - loss: 3.0155e-04
Epoch 398/500
6/6 [==============================] - 0s - loss: 2.9536e-04
Epoch 399/500
6/6 [==============================] - 0s - loss: 2.8929e-04
Epoch 400/500
6/6 [==============================] - 0s - loss: 2.8335e-04
Epoch 401/500
6/6 [==============================] - 0s - loss: 2.7753e-04
Epoch 402/500
6/6 [==============================] - 0s - loss: 2.7183e-04
Epoch 403/500
6/6 [==============================] - 0s - loss: 2.6625e-04
Epoch 404/500
6/6 [==============================] - 0s - loss: 2.6078e-04
Epoch 405/500
6/6 [==============================] - 0s - loss: 2.5542e-04
Epoch 406/500
6/6 [==============================] - 0s - loss: 2.5017e-04
Epoch 407/500
6/6 [==============================] - 0s - loss: 2.4503e-04
Epoch 408/500
6/6 [==============================] - 0s - loss: 2.4000e-04
Epoch 409/500
6/6 [==============================] - 0s - loss: 2.3507e-04
Epoch 410/500
6/6 [==============================] - 0s - loss: 2.3024e-04
Epoch 411/500
6/6 [==============================] - 0s - loss: 2.2552e-04
Epoch 412/500
6/6 [==============================] - 0s - loss: 2.2088e-04
Epoch 413/500
6/6 [==============================] - 0s - loss: 2.1635e-04
Epoch 414/500
6/6 [==============================] - 0s - loss: 2.1190e-04
Epoch 415/500
6/6 [==============================] - 0s - loss: 2.0755e-04
Epoch 416/500
6/6 [==============================] - 0s - loss: 2.0329e-04
Epoch 417/500
6/6 [==============================] - 0s - loss: 1.9911e-04
Epoch 418/500
6/6 [==============================] - 0s - loss: 1.9502e-04
Epoch 419/500
6/6 [==============================] - 0s - loss: 1.9102e-04
Epoch 420/500
6/6 [==============================] - 0s - loss: 1.8709e-04
Epoch 421/500
6/6 [==============================] - 0s - loss: 1.8325e-04
Epoch 422/500
6/6 [==============================] - 0s - loss: 1.7949e-04
Epoch 423/500
6/6 [==============================] - 0s - loss: 1.7580e-04
Epoch 424/500
6/6 [==============================] - 0s - loss: 1.7219e-04
Epoch 425/500
6/6 [==============================] - 0s - loss: 1.6865e-04
Epoch 426/500
6/6 [==============================] - 0s - loss: 1.6519e-04
Epoch 427/500
6/6 [==============================] - 0s - loss: 1.6179e-04
Epoch 428/500
6/6 [==============================] - 0s - loss: 1.5847e-04
Epoch 429/500
6/6 [==============================] - 0s - loss: 1.5521e-04
Epoch 430/500
6/6 [==============================] - 0s - loss: 1.5203e-04
Epoch 431/500
6/6 [==============================] - 0s - loss: 1.4890e-04
Epoch 432/500
6/6 [==============================] - 0s - loss: 1.4584e-04
Epoch 433/500
6/6 [==============================] - 0s - loss: 1.4285e-04
Epoch 434/500
6/6 [==============================] - 0s - loss: 1.3991e-04
Epoch 435/500
6/6 [==============================] - 0s - loss: 1.3704e-04
Epoch 436/500
6/6 [==============================] - 0s - loss: 1.3422e-04
Epoch 437/500
6/6 [==============================] - 0s - loss: 1.3147e-04
Epoch 438/500
6/6 [==============================] - 0s - loss: 1.2877e-04
Epoch 439/500
6/6 [==============================] - 0s - loss: 1.2612e-04
Epoch 440/500
6/6 [==============================] - 0s - loss: 1.2353e-04
Epoch 441/500
6/6 [==============================] - 0s - loss: 1.2099e-04
Epoch 442/500
6/6 [==============================] - 0s - loss: 1.1851e-04
Epoch 443/500
6/6 [==============================] - 0s - loss: 1.1607e-04
Epoch 444/500
6/6 [==============================] - 0s - loss: 1.1369e-04
Epoch 445/500
6/6 [==============================] - 0s - loss: 1.1135e-04
Epoch 446/500
6/6 [==============================] - 0s - loss: 1.0907e-04
Epoch 447/500
6/6 [==============================] - 0s - loss: 1.0683e-04
Epoch 448/500
6/6 [==============================] - 0s - loss: 1.0463e-04
Epoch 449/500
6/6 [==============================] - 0s - loss: 1.0248e-04
Epoch 450/500
6/6 [==============================] - 0s - loss: 1.0038e-04
Epoch 451/500
6/6 [==============================] - 0s - loss: 9.8316e-05
Epoch 452/500
6/6 [==============================] - 0s - loss: 9.6296e-05
Epoch 453/500
6/6 [==============================] - 0s - loss: 9.4319e-05
Epoch 454/500
6/6 [==============================] - 0s - loss: 9.2383e-05
Epoch 455/500
6/6 [==============================] - 0s - loss: 9.0484e-05
Epoch 456/500
6/6 [==============================] - 0s - loss: 8.8627e-05
Epoch 457/500
6/6 [==============================] - 0s - loss: 8.6807e-05
Epoch 458/500
6/6 [==============================] - 0s - loss: 8.5023e-05
Epoch 459/500
6/6 [==============================] - 0s - loss: 8.3275e-05
Epoch 460/500
6/6 [==============================] - 0s - loss: 8.1566e-05
Epoch 461/500
6/6 [==============================] - 0s - loss: 7.9891e-05
Epoch 462/500
6/6 [==============================] - 0s - loss: 7.8248e-05
Epoch 463/500
6/6 [==============================] - 0s - loss: 7.6642e-05
Epoch 464/500
6/6 [==============================] - 0s - loss: 7.5066e-05
Epoch 465/500
6/6 [==============================] - 0s - loss: 7.3524e-05
Epoch 466/500
6/6 [==============================] - 0s - loss: 7.2015e-05
Epoch 467/500
6/6 [==============================] - 0s - loss: 7.0536e-05
Epoch 468/500
6/6 [==============================] - 0s - loss: 6.9085e-05
Epoch 469/500
6/6 [==============================] - 0s - loss: 6.7667e-05
Epoch 470/500
6/6 [==============================] - 0s - loss: 6.6277e-05
Epoch 471/500
6/6 [==============================] - 0s - loss: 6.4916e-05
Epoch 472/500
6/6 [==============================] - 0s - loss: 6.3583e-05
Epoch 473/500
6/6 [==============================] - 0s - loss: 6.2277e-05
Epoch 474/500
6/6 [==============================] - 0s - loss: 6.0997e-05
Epoch 475/500
6/6 [==============================] - 0s - loss: 5.9745e-05
Epoch 476/500
6/6 [==============================] - 0s - loss: 5.8518e-05
Epoch 477/500
6/6 [==============================] - 0s - loss: 5.7315e-05
Epoch 478/500
6/6 [==============================] - 0s - loss: 5.6139e-05
Epoch 479/500
6/6 [==============================] - 0s - loss: 5.4986e-05
Epoch 480/500
6/6 [==============================] - 0s - loss: 5.3856e-05
Epoch 481/500
6/6 [==============================] - 0s - loss: 5.2750e-05
Epoch 482/500
6/6 [==============================] - 0s - loss: 5.1666e-05
Epoch 483/500
6/6 [==============================] - 0s - loss: 5.0605e-05
Epoch 484/500
6/6 [==============================] - 0s - loss: 4.9566e-05
Epoch 485/500
6/6 [==============================] - 0s - loss: 4.8548e-05
Epoch 486/500
6/6 [==============================] - 0s - loss: 4.7551e-05
Epoch 487/500
6/6 [==============================] - 0s - loss: 4.6574e-05
Epoch 488/500
6/6 [==============================] - 0s - loss: 4.5617e-05
Epoch 489/500
6/6 [==============================] - 0s - loss: 4.4679e-05
Epoch 490/500
6/6 [==============================] - 0s - loss: 4.3762e-05
Epoch 491/500
6/6 [==============================] - 0s - loss: 4.2862e-05
Epoch 492/500
6/6 [==============================] - 0s - loss: 4.1983e-05
Epoch 493/500
6/6 [==============================] - 0s - loss: 4.1120e-05
Epoch 494/500
6/6 [==============================] - 0s - loss: 4.0276e-05
Epoch 495/500
6/6 [==============================] - 0s - loss: 3.9448e-05
Epoch 496/500
6/6 [==============================] - 0s - loss: 3.8638e-05
Epoch 497/500
6/6 [==============================] - 0s - loss: 3.7844e-05
Epoch 498/500
6/6 [==============================] - 0s - loss: 3.7068e-05
Epoch 499/500
6/6 [==============================] - 0s - loss: 3.6305e-05
Epoch 500/500
6/6 [==============================] - 0s - loss: 3.5560e-05
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_32 (Dense)             (None, 1)                 2         
=================================================================
Total params: 2
Trainable params: 2
Non-trainable params: 0
_________________________________________________________________
array([[18.982601]], dtype=float32)

从输出可以看出,在不停的训练迭代过程中,LOSS输出值不断减小,最后得到一个非常小的LOSS值,我们用这个模型预测10的输出,得到的是18.982601,非常接近真实的19. 


结束!

上一篇:使用FFmpeg截取视频封面图片(完整例子)


下一篇:【k8s】deploy-RollingUpdate