Tensorflow学习笔记:VGG16训练——Finetuning,猫狗大战,VGGNet的重新针对训练

前面我们介绍了猫狗大战的数据集的整理已经转换成Tensorflow专用格式https://blog.csdn.net/nvidiacuda/article/details/83413837

以及介绍了vgg16模型https://blog.csdn.net/nvidiacuda/article/details/83414293

这篇介绍如何用数据对vgg16进行训练

Finetuning最重要的一个步骤就是模型的重新训练与存储。 
首先对于模型的值的输出,在类中已经做了定义,因此只需要将定义的模型类初始化后输出赋予一个特定的变量即可。

vgg = model.vgg16(x_imgs)
fc3_cat_and_dog = vgg.probs
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=fc3_cat_and_dog, labels=y_imgs))
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001).minimize(loss)

这里同时定义了损失函数已经最小化方法,完整代码如下:

完整代码 train.py文件

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

import tensorflow as tf
import VGG16_model as model
import create_and_read_TFRecord2 as reader2

if __name__ == '__main__':

    X_train, y_train = reader2.get_file('./train')
    image_batch, label_batch = reader2.get_batch(X_train, y_train, 224, 224, 25, 256)

    x_imgs = tf.placeholder(tf.float32, [None, 224, 224, 3])
    y_imgs = tf.placeholder(tf.int32, [None, 2])

    vgg = model.vgg16(x_imgs)
    fc3_cat_and_dog = vgg.probs
    loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=fc3_cat_and_dog, labels=y_imgs))
    optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001).minimize(loss)

    correct_prediction = tf.equal(tf.arg_max(y_imgs, 1), tf.arg_max(fc3_cat_and_dog, 1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

    sess = tf.Session()
    sess.run(tf.global_variables_initializer())
    vgg.load_weights('./vgg16_weights.npz', sess)
    saver = vgg.saver()

    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord, sess=sess)

    import time
    start_time = time.time()

    for i in range(200):
        image, label = sess.run([image_batch, label_batch])
        labels = reader2.onehot(label)
        sess.run(optimizer, feed_dict={x_imgs: image, y_imgs: labels})
        loss_record = sess.run(loss, feed_dict={x_imgs: image, y_imgs: labels})
        accuracy_record = sess.run(accuracy, feed_dict={x_imgs: image, y_imgs: labels})
        print("the loss is %f " % loss_record, "the accuracy is %f" % accuracy_record)
        end_time = time.time()
        print('time: ', (end_time - start_time))
        start_time = end_time
        print("----------epoch %d is finished---------------" % i)

    saver.save(sess, "./model/")
    print("Optimization Finished!")


在训练函数中使用了Tensorflow的队列方式进行数据输入,而对于权重的重新载入也使用的是前面文章类似的方式,最终数据进行200次迭代,存储模型在model文件夹中。

训练的结果如下:

C:\Users\303\Anaconda3\python.exe C:/Users/303/Desktop/vgg/train.py
-----------all done---------------
the loss is 0.758111  the accuracy is 0.520000
time:  93.22740054130554
----------epoch 0 is finished---------------
the loss is 0.700010  the accuracy is 0.400000
time:  37.96240019798279
----------epoch 1 is finished---------------
the loss is 0.661964  the accuracy is 0.480000
time:  27.612000226974487
----------epoch 2 is finished---------------
the loss is 0.696854  the accuracy is 0.440000
time:  27.752400159835815
----------epoch 3 is finished---------------
the loss is 0.692208  the accuracy is 0.560000
time:  27.409200191497803
----------epoch 4 is finished---------------
the loss is 0.695500  the accuracy is 0.600000
time:  27.69000005722046
----------epoch 5 is finished---------------
the loss is 0.690480  the accuracy is 0.440000
time:  27.346800565719604
----------epoch 6 is finished---------------
the loss is 0.673299  the accuracy is 0.400000
time:  27.299999952316284
----------epoch 7 is finished---------------
the loss is 0.685414  the accuracy is 0.560000
time:  27.159600257873535
----------epoch 8 is finished---------------
the loss is 0.678527  the accuracy is 0.560000
time:  27.36240005493164
----------epoch 9 is finished---------------
the loss is 0.703208  the accuracy is 0.560000
time:  27.300000190734863
----------epoch 10 is finished---------------
the loss is 0.678527  the accuracy is 0.440000
time:  28.25160026550293
----------epoch 11 is finished---------------
the loss is 0.693578  the accuracy is 0.680000
time:  28.14240026473999
----------epoch 12 is finished---------------
the loss is 0.688089  the accuracy is 0.560000
time:  28.25160002708435
----------epoch 13 is finished---------------
the loss is 0.691666  the accuracy is 0.520000
time:  27.93560028076172
----------epoch 14 is finished---------------
the loss is 0.695733  the accuracy is 0.360000
time:  27.705600261688232
----------epoch 15 is finished---------------
the loss is 0.676656  the accuracy is 0.560000
time:  27.76800012588501
----------epoch 16 is finished---------------
the loss is 0.680016  the accuracy is 0.760000
time:  27.783600091934204
----------epoch 17 is finished---------------
the loss is 0.675143  the accuracy is 0.680000
time:  27.82360029220581
----------epoch 18 is finished---------------
the loss is 0.674448  the accuracy is 0.400000
time:  27.721199989318848
----------epoch 19 is finished---------------
the loss is 0.683596  the accuracy is 0.640000
time:  27.556400060653687
----------epoch 20 is finished---------------
the loss is 0.685636  the accuracy is 0.760000
time:  27.816800355911255
----------epoch 21 is finished---------------
the loss is 0.667558  the accuracy is 0.560000
time:  27.721200227737427
----------epoch 22 is finished---------------
the loss is 0.647418  the accuracy is 0.720000
time:  27.87720012664795
----------epoch 23 is finished---------------
the loss is 0.688498  the accuracy is 0.680000
time:  27.861600160598755
----------epoch 24 is finished---------------
the loss is 0.693147  the accuracy is 0.680000
time:  27.80120015144348
----------epoch 25 is finished---------------
the loss is 0.672804  the accuracy is 0.600000
time:  27.6326003074646
----------epoch 26 is finished---------------
the loss is 0.670962  the accuracy is 0.640000
time:  27.752400159835815
----------epoch 27 is finished---------------
the loss is 0.689062  the accuracy is 0.600000
time:  27.666800022125244
----------epoch 28 is finished---------------
the loss is 0.673509  the accuracy is 0.640000
time:  27.675600290298462
----------epoch 29 is finished---------------
the loss is 0.654030  the accuracy is 0.760000
time:  27.58080005645752
----------epoch 30 is finished---------------
the loss is 0.602225  the accuracy is 0.640000
time:  27.783600330352783
----------epoch 31 is finished---------------
the loss is 0.611574  the accuracy is 0.640000
time:  27.600600242614746
----------epoch 32 is finished---------------
the loss is 0.637754  the accuracy is 0.720000
time:  27.720799922943115
----------epoch 33 is finished---------------
the loss is 0.639839  the accuracy is 0.720000
time:  27.215200185775757
----------epoch 34 is finished---------------
the loss is 0.548652  the accuracy is 0.640000
time:  27.306600332260132
----------epoch 35 is finished---------------
the loss is 0.648707  the accuracy is 0.640000
time:  27.30780005455017
----------epoch 36 is finished---------------
the loss is 0.673585  the accuracy is 0.760000
time:  27.269400358200073
----------epoch 37 is finished---------------
the loss is 0.567087  the accuracy is 0.800000
time:  27.429999828338623
----------epoch 38 is finished---------------
the loss is 0.652346  the accuracy is 0.920000
time:  27.326200246810913
----------epoch 39 is finished---------------
the loss is 0.580749  the accuracy is 0.680000
time:  28.331400156021118
----------epoch 40 is finished---------------
the loss is 0.619812  the accuracy is 0.760000
time:  29.592000007629395
----------epoch 41 is finished---------------
the loss is 0.676218  the accuracy is 0.680000
time:  29.66480040550232
----------epoch 42 is finished---------------
the loss is 0.523080  the accuracy is 0.760000
time:  30.444000244140625
----------epoch 43 is finished---------------
the loss is 0.636938  the accuracy is 0.680000
time:  29.430800199508667
----------epoch 44 is finished---------------
the loss is 0.565380  the accuracy is 0.720000
time:  29.14680004119873
----------epoch 45 is finished---------------
the loss is 0.607241  the accuracy is 0.760000
time:  29.552000284194946
----------epoch 46 is finished---------------
the loss is 0.668076  the accuracy is 0.720000
time:  30.087400197982788
----------epoch 47 is finished---------------
the loss is 0.615282  the accuracy is 0.760000
time:  29.361200094223022
----------epoch 48 is finished---------------
the loss is 0.572243  the accuracy is 0.680000
time:  28.427799940109253
----------epoch 49 is finished---------------
the loss is 0.626822  the accuracy is 0.720000
time:  29.176600217819214
----------epoch 50 is finished---------------
the loss is 0.600773  the accuracy is 0.720000
time:  28.78540015220642
----------epoch 51 is finished---------------
the loss is 0.573486  the accuracy is 0.720000
time:  28.928600311279297
----------epoch 52 is finished---------------
the loss is 0.598439  the accuracy is 0.680000
time:  28.34980010986328
----------epoch 53 is finished---------------
the loss is 0.575304  the accuracy is 0.800000
time:  28.56060028076172
----------epoch 54 is finished---------------
the loss is 0.449136  the accuracy is 0.760000
time:  27.85759997367859
----------epoch 55 is finished---------------
the loss is 0.584953  the accuracy is 0.720000
time:  27.222000122070312
----------epoch 56 is finished---------------
the loss is 0.534731  the accuracy is 0.800000
time:  27.420000314712524
----------epoch 57 is finished---------------
the loss is 0.523127  the accuracy is 0.720000
time:  27.40619993209839
----------epoch 58 is finished---------------
the loss is 0.579338  the accuracy is 0.680000
time:  27.410800218582153
----------epoch 59 is finished---------------
the loss is 0.533000  the accuracy is 0.760000
time:  27.298800230026245
----------epoch 60 is finished---------------
the loss is 0.610720  the accuracy is 0.800000
time:  27.620800256729126
----------epoch 61 is finished---------------
the loss is 0.626162  the accuracy is 0.760000
time:  27.49239993095398
----------epoch 62 is finished---------------
the loss is 0.589299  the accuracy is 0.840000
time:  27.429200172424316
----------epoch 63 is finished---------------
the loss is 0.496789  the accuracy is 0.760000
time:  27.400400161743164
----------epoch 64 is finished---------------
the loss is 0.569393  the accuracy is 0.680000
time:  27.337600231170654
----------epoch 65 is finished---------------
the loss is 0.448170  the accuracy is 0.840000
time:  27.45860004425049
----------epoch 66 is finished---------------
the loss is 0.587917  the accuracy is 0.680000
time:  27.365400314331055
----------epoch 67 is finished---------------
the loss is 0.554151  the accuracy is 0.880000
time:  27.627599954605103
----------epoch 68 is finished---------------
the loss is 0.635504  the accuracy is 0.920000
time:  27.450200080871582
----------epoch 69 is finished---------------
the loss is 0.526137  the accuracy is 0.800000
time:  27.54040026664734
----------epoch 70 is finished---------------
the loss is 0.487640  the accuracy is 0.800000
time:  27.451200246810913
----------epoch 71 is finished---------------
the loss is 0.494419  the accuracy is 0.760000
time:  27.231199979782104
----------epoch 72 is finished---------------
the loss is 0.601800  the accuracy is 0.840000
time:  27.487000226974487
----------epoch 73 is finished---------------
the loss is 0.414525  the accuracy is 0.720000
time:  27.597599983215332
----------epoch 74 is finished---------------
the loss is 0.530127  the accuracy is 0.880000
time:  27.871800422668457
----------epoch 75 is finished---------------
the loss is 0.472716  the accuracy is 0.760000
time:  27.755200147628784
----------epoch 76 is finished---------------
the loss is 0.581156  the accuracy is 0.760000
time:  27.348999977111816
----------epoch 77 is finished---------------
the loss is 0.588855  the accuracy is 0.840000
time:  27.505800247192383
----------epoch 78 is finished---------------
the loss is 0.442660  the accuracy is 0.800000
time:  27.877000093460083
----------epoch 79 is finished---------------
the loss is 0.513920  the accuracy is 0.760000
time:  27.692400217056274
----------epoch 80 is finished---------------
the loss is 0.570069  the accuracy is 0.800000
time:  27.851400136947632
----------epoch 81 is finished---------------
the loss is 0.574013  the accuracy is 0.720000
time:  27.560199975967407
----------epoch 82 is finished---------------
the loss is 0.621346  the accuracy is 0.960000
time:  28.02780032157898
----------epoch 83 is finished---------------
the loss is 0.491623  the accuracy is 0.800000
time:  27.84940004348755
----------epoch 84 is finished---------------
the loss is 0.549356  the accuracy is 0.680000
time:  27.50480031967163
----------epoch 85 is finished---------------
the loss is 0.605569  the accuracy is 0.720000
time:  27.891799926757812
----------epoch 86 is finished---------------
the loss is 0.489809  the accuracy is 0.720000
time:  27.671600341796875
----------epoch 87 is finished---------------
the loss is 0.548903  the accuracy is 0.760000
time:  27.834800004959106
----------epoch 88 is finished---------------
the loss is 0.557381  the accuracy is 0.800000
time:  27.87980031967163
----------epoch 89 is finished---------------
the loss is 0.614677  the accuracy is 0.720000
time:  27.79800009727478
----------epoch 90 is finished---------------
the loss is 0.487653  the accuracy is 0.920000
time:  27.67300033569336
----------epoch 91 is finished---------------
the loss is 0.439404  the accuracy is 0.720000
time:  27.524999856948853
----------epoch 92 is finished---------------
the loss is 0.514191  the accuracy is 0.760000
time:  27.502800464630127
----------epoch 93 is finished---------------
the loss is 0.608245  the accuracy is 0.880000
time:  27.73099994659424
----------epoch 94 is finished---------------
the loss is 0.351427  the accuracy is 0.840000
time:  27.83899998664856
----------epoch 95 is finished---------------
the loss is 0.643810  the accuracy is 0.800000
time:  27.814600229263306
----------epoch 96 is finished---------------
the loss is 0.382391  the accuracy is 0.880000
time:  27.59920024871826
----------epoch 97 is finished---------------
the loss is 0.514393  the accuracy is 0.800000
time:  27.685400247573853
----------epoch 98 is finished---------------
the loss is 0.389810  the accuracy is 0.800000
time:  28.022000074386597
----------epoch 99 is finished---------------
the loss is 0.455801  the accuracy is 0.760000
time:  27.57540011405945
----------epoch 100 is finished---------------
the loss is 0.419581  the accuracy is 0.800000
time:  27.84120011329651
----------epoch 101 is finished---------------
the loss is 0.471398  the accuracy is 0.840000
time:  27.59599995613098
----------epoch 102 is finished---------------
the loss is 0.456360  the accuracy is 0.840000
time:  27.46400022506714
----------epoch 103 is finished---------------
the loss is 0.528342  the accuracy is 0.800000
time:  27.807400226593018
----------epoch 104 is finished---------------
the loss is 0.523615  the accuracy is 0.880000
time:  27.818000316619873
----------epoch 105 is finished---------------
the loss is 0.467946  the accuracy is 0.880000
time:  27.59220004081726
----------epoch 106 is finished---------------
the loss is 0.557764  the accuracy is 0.840000
time:  27.674400329589844
----------epoch 107 is finished---------------
the loss is 0.572827  the accuracy is 0.920000
time:  27.546200037002563
----------epoch 108 is finished---------------
the loss is 0.506509  the accuracy is 0.720000
time:  27.511000156402588
----------epoch 109 is finished---------------
the loss is 0.483258  the accuracy is 0.760000
time:  27.842000246047974
----------epoch 110 is finished---------------
the loss is 0.588461  the accuracy is 0.840000
time:  27.560999870300293
----------epoch 111 is finished---------------
the loss is 0.395232  the accuracy is 0.680000
time:  28.07260036468506
----------epoch 112 is finished---------------
the loss is 0.573396  the accuracy is 0.880000
time:  27.79580020904541
----------epoch 113 is finished---------------
the loss is 0.378605  the accuracy is 0.920000
time:  27.718600034713745
----------epoch 114 is finished---------------
the loss is 0.516754  the accuracy is 0.920000
time:  27.76640009880066
----------epoch 115 is finished---------------
the loss is 0.486750  the accuracy is 0.920000
time:  27.51260018348694
----------epoch 116 is finished---------------
the loss is 0.449040  the accuracy is 0.880000
time:  27.76200032234192
----------epoch 117 is finished---------------
the loss is 0.564241  the accuracy is 0.920000
time:  27.56940007209778
----------epoch 118 is finished---------------
the loss is 0.476609  the accuracy is 0.880000
time:  27.84000015258789
----------epoch 119 is finished---------------
the loss is 0.442881  the accuracy is 0.840000
time:  27.701200246810913
----------epoch 120 is finished---------------
the loss is 0.410049  the accuracy is 0.840000
time:  27.618799924850464
----------epoch 121 is finished---------------
the loss is 0.486768  the accuracy is 0.840000
time:  27.57740020751953
----------epoch 122 is finished---------------
the loss is 0.438721  the accuracy is 0.800000
time:  27.670600175857544
----------epoch 123 is finished---------------
the loss is 0.555945  the accuracy is 0.960000
time:  27.57260012626648
----------epoch 124 is finished---------------
the loss is 0.376361  the accuracy is 0.840000
time:  27.803800344467163
----------epoch 125 is finished---------------
the loss is 0.384597  the accuracy is 0.880000
time:  27.729599952697754
----------epoch 126 is finished---------------
the loss is 0.393353  the accuracy is 0.880000
time:  27.59500026702881
----------epoch 127 is finished---------------
the loss is 0.582737  the accuracy is 0.920000
time:  27.850000143051147
----------epoch 128 is finished---------------
the loss is 0.530217  the accuracy is 0.880000
time:  27.79579997062683
----------epoch 129 is finished---------------
the loss is 0.505465  the accuracy is 0.920000
time:  27.616400241851807
----------epoch 130 is finished---------------
the loss is 0.454727  the accuracy is 0.840000
time:  27.714800357818604
----------epoch 131 is finished---------------
the loss is 0.478746  the accuracy is 0.760000
time:  27.530200004577637
----------epoch 132 is finished---------------
the loss is 0.460549  the accuracy is 0.880000
time:  27.57480025291443
----------epoch 133 is finished---------------
the loss is 0.549542  the accuracy is 0.880000
time:  27.84220004081726
----------epoch 134 is finished---------------
the loss is 0.519628  the accuracy is 0.880000
time:  27.43340015411377
----------epoch 135 is finished---------------
the loss is 0.546381  the accuracy is 0.880000
time:  27.611600160598755
----------epoch 136 is finished---------------
the loss is 0.564635  the accuracy is 0.840000
time:  27.526400089263916
----------epoch 137 is finished---------------
the loss is 0.365546  the accuracy is 0.920000
time:  27.882800340652466
----------epoch 138 is finished---------------
the loss is 0.487230  the accuracy is 0.800000
time:  27.65059995651245
----------epoch 139 is finished---------------
the loss is 0.522421  the accuracy is 0.880000
time:  27.713800191879272
----------epoch 140 is finished---------------
the loss is 0.417020  the accuracy is 0.800000
time:  27.84060001373291
----------epoch 141 is finished---------------
the loss is 0.319831  the accuracy is 0.880000
time:  27.86180019378662
----------epoch 142 is finished---------------
the loss is 0.477082  the accuracy is 0.760000
time:  27.462600231170654
----------epoch 143 is finished---------------
the loss is 0.510756  the accuracy is 0.840000
time:  27.606200218200684
----------epoch 144 is finished---------------
the loss is 0.458786  the accuracy is 0.880000
time:  27.80500030517578
----------epoch 145 is finished---------------
the loss is 0.472080  the accuracy is 0.840000
time:  27.635599851608276
----------epoch 146 is finished---------------
the loss is 0.584948  the accuracy is 0.840000
time:  27.65820026397705
----------epoch 147 is finished---------------
the loss is 0.492688  the accuracy is 0.920000
time:  27.647400379180908
----------epoch 148 is finished---------------
the loss is 0.465814  the accuracy is 0.960000
time:  27.7221999168396
----------epoch 149 is finished---------------
the loss is 0.629802  the accuracy is 0.840000
time:  27.763800144195557
----------epoch 150 is finished---------------
the loss is 0.566602  the accuracy is 0.800000
time:  27.61579990386963
----------epoch 151 is finished---------------
the loss is 0.480911  the accuracy is 0.800000
time:  27.80180048942566
----------epoch 152 is finished---------------
the loss is 0.550858  the accuracy is 0.800000
time:  27.554399967193604
----------epoch 153 is finished---------------
the loss is 0.472405  the accuracy is 0.920000
time:  27.86620020866394
----------epoch 154 is finished---------------
the loss is 0.555857  the accuracy is 0.840000
time:  27.531800270080566
----------epoch 155 is finished---------------
the loss is 0.544163  the accuracy is 0.920000
time:  27.48580002784729
----------epoch 156 is finished---------------
the loss is 0.447131  the accuracy is 0.800000
time:  27.74880027770996
----------epoch 157 is finished---------------
the loss is 0.512945  the accuracy is 0.800000
time:  27.713599920272827
----------epoch 158 is finished---------------
the loss is 0.422867  the accuracy is 0.880000
time:  27.759000301361084
----------epoch 159 is finished---------------
the loss is 0.451860  the accuracy is 0.880000
time:  27.888200283050537
----------epoch 160 is finished---------------
the loss is 0.561305  the accuracy is 0.800000
time:  27.659800052642822
----------epoch 161 is finished---------------
the loss is 0.420359  the accuracy is 0.840000
time:  27.467600107192993
----------epoch 162 is finished---------------
the loss is 0.523465  the accuracy is 0.880000
time:  27.79419994354248
----------epoch 163 is finished---------------
the loss is 0.568682  the accuracy is 0.880000
time:  27.65660047531128
----------epoch 164 is finished---------------
the loss is 0.482351  the accuracy is 0.920000
time:  27.829400062561035
----------epoch 165 is finished---------------
the loss is 0.548296  the accuracy is 0.880000
time:  27.62720012664795
----------epoch 166 is finished---------------
the loss is 0.456741  the accuracy is 0.880000
time:  27.60700011253357
----------epoch 167 is finished---------------
the loss is 0.457089  the accuracy is 0.800000
time:  27.6742000579834
----------epoch 168 is finished---------------
the loss is 0.454088  the accuracy is 0.880000
time:  27.770400285720825
----------epoch 169 is finished---------------
the loss is 0.636062  the accuracy is 0.880000
time:  28.01960015296936
----------epoch 170 is finished---------------
the loss is 0.427030  the accuracy is 0.960000
time:  27.59720015525818
----------epoch 171 is finished---------------
the loss is 0.533497  the accuracy is 0.760000
time:  27.63319993019104
----------epoch 172 is finished---------------
the loss is 0.683608  the accuracy is 0.840000
time:  27.600000143051147
----------epoch 173 is finished---------------
the loss is 0.414515  the accuracy is 0.920000
time:  27.706400156021118
----------epoch 174 is finished---------------
the loss is 0.478144  the accuracy is 0.840000
time:  27.615600109100342
----------epoch 175 is finished---------------
the loss is 0.460551  the accuracy is 0.960000
time:  27.55440044403076
----------epoch 176 is finished---------------
the loss is 0.417252  the accuracy is 0.920000
time:  27.61140012741089
----------epoch 177 is finished---------------
the loss is 0.563965  the accuracy is 0.880000
time:  27.632399797439575
----------epoch 178 is finished---------------
the loss is 0.364149  the accuracy is 0.960000
time:  27.843200206756592
----------epoch 179 is finished---------------
the loss is 0.473918  the accuracy is 0.880000
time:  27.80520009994507
----------epoch 180 is finished---------------
the loss is 0.520914  the accuracy is 0.800000
time:  27.72420024871826
----------epoch 181 is finished---------------
the loss is 0.408743  the accuracy is 0.800000
time:  27.618600130081177
----------epoch 182 is finished---------------
the loss is 0.518027  the accuracy is 0.840000
time:  27.498400449752808
----------epoch 183 is finished---------------
the loss is 0.349911  the accuracy is 0.880000
time:  27.69539976119995
----------epoch 184 is finished---------------
the loss is 0.481384  the accuracy is 0.840000
time:  27.858200311660767
----------epoch 185 is finished---------------
the loss is 0.464019  the accuracy is 0.920000
time:  27.4760000705719
----------epoch 186 is finished---------------
the loss is 0.520933  the accuracy is 0.840000
time:  27.736000299453735
----------epoch 187 is finished---------------
the loss is 0.458529  the accuracy is 0.840000
time:  27.768400192260742
----------epoch 188 is finished---------------
the loss is 0.493793  the accuracy is 0.920000
time:  27.51039981842041
----------epoch 189 is finished---------------
the loss is 0.537836  the accuracy is 0.800000
time:  27.89340043067932
----------epoch 190 is finished---------------
the loss is 0.416713  the accuracy is 0.840000
time:  27.73680019378662
----------epoch 191 is finished---------------
the loss is 0.442437  the accuracy is 0.840000
time:  27.68840003013611
----------epoch 192 is finished---------------
the loss is 0.361428  the accuracy is 0.920000
time:  27.536800146102905
----------epoch 193 is finished---------------
the loss is 0.466083  the accuracy is 0.880000
time:  27.438400268554688
----------epoch 194 is finished---------------
the loss is 0.394836  the accuracy is 0.840000
time:  27.5518000125885
----------epoch 195 is finished---------------
the loss is 0.459927  the accuracy is 0.960000
time:  27.627800226211548
----------epoch 196 is finished---------------
the loss is 0.481451  the accuracy is 0.920000
time:  27.813600063323975
----------epoch 197 is finished---------------
the loss is 0.451922  the accuracy is 0.920000
time:  27.564800024032593
----------epoch 198 is finished---------------
the loss is 0.508634  the accuracy is 0.920000
time:  27.714200258255005
----------epoch 199 is finished---------------
Optimization Finished!

Process finished with exit code 0
完整的项目源代码见:链接:https://pan.baidu.com/s/1XMm9bNMMhDp8hmfzfVh9sg 密码:ojbx

你可能感兴趣的:(python,机器学习)