使用TensorFlow对电影评论进行文本分类

文章目录

    • 数据来源
    • 数据处理
    • 数据下载
    • 模型的构建
    • 模型的编译与训练
    • 模型的评估
    • 完整代码
    • 最终结果

数据来源

本次使用的数据来源于网络电影数据库的IMDB数据集,其中包含50,000条影评文本。

数据处理

从该数据集切割出的25,000条评论用作训练,另外25,000条用作测试。训练集与测试集是平衡的,意味着它们包含相等数量的积极和消极评论。

数据下载

使用TensorFlow对电影评论进行文本分类_第1张图片

模型的构建

使用TensorFlow对电影评论进行文本分类_第2张图片

模型的编译与训练

使用TensorFlow对电影评论进行文本分类_第3张图片

模型的评估

使用TensorFlow对电影评论进行文本分类_第4张图片

完整代码

# !/usr/bin/env python
# —*— coding: utf-8 —*—
# @Time:    2020/1/2 7:42
# @Author:  Martin
# @File:    Film_Reviews_Classification.py
# @Software:PyCharm

from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_datasets as tfds
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = '3'
# 下载IMDB数据集
train_validation_split = tfds.Split.TRAIN.subsplit([6, 4])
(train_data, validation_data), test_data = tfds.load(
    name="imdb_reviews",
    split=(train_validation_split, tfds.Split.TEST),
    as_supervised=True
)
# 构建模型
embedding = "https://hub.tensorflow.google.cn/google/tf2-preview/gnews-swivel-20dim/1"
hub_layer = hub.KerasLayer(embedding, input_shape=[], dtype=tf.string, trainable=True)
model = tf.keras.Sequential()
model.add(hub_layer)
model.add(tf.keras.layers.Dense(16, activation='relu'))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
# 编译模型
model.compile(optimizer='adam',
              loss='binary_crossentropy',
              metrics=['accuracy'])
# 训练模型
history = model.fit(train_data.shuffle(10000).batch(512),
                    epochs=20,
                    validation_data=validation_data.batch(512),
                    verbose=1)
# 评估模型
results = model.evaluate(test_data.batch(512), verbose=2)
for name, value in zip(model.metrics_names, results):
    print("%s: %.3f" % (name, value))



最终结果

Epoch 1/20

      1/Unknown - 1s 1s/step - loss: 0.8219 - accuracy: 0.4609
      2/Unknown - 2s 782ms/step - loss: 0.8012 - accuracy: 0.4756
      3/Unknown - 2s 563ms/step - loss: 0.7966 - accuracy: 0.4818
      4/Unknown - 2s 450ms/step - loss: 0.7910 - accuracy: 0.4800
      5/Unknown - 2s 381ms/step - loss: 0.7840 - accuracy: 0.4828
      6/Unknown - 2s 334ms/step - loss: 0.7851 - accuracy: 0.4801
      7/Unknown - 2s 299ms/step - loss: 0.7776 - accuracy: 0.4886
      8/Unknown - 2s 274ms/step - loss: 0.7712 - accuracy: 0.4944
      9/Unknown - 2s 255ms/step - loss: 0.7656 - accuracy: 0.4998
     10/Unknown - 2s 240ms/step - loss: 0.7622 - accuracy: 0.5033
     11/Unknown - 2s 227ms/step - loss: 0.7624 - accuracy: 0.5025
     12/Unknown - 3s 215ms/step - loss: 0.7596 - accuracy: 0.5065
     13/Unknown - 3s 206ms/step - loss: 0.7586 - accuracy: 0.5066
     14/Unknown - 3s 197ms/step - loss: 0.7569 - accuracy: 0.5070
     15/Unknown - 3s 190ms/step - loss: 0.7537 - accuracy: 0.5096
     16/Unknown - 3s 184ms/step - loss: 0.7504 - accuracy: 0.5125
     17/Unknown - 3s 178ms/step - loss: 0.7484 - accuracy: 0.5149
     18/Unknown - 3s 174ms/step - loss: 0.7449 - accuracy: 0.5193
     19/Unknown - 3s 170ms/step - loss: 0.7421 - accuracy: 0.5225
     20/Unknown - 3s 166ms/step - loss: 0.7401 - accuracy: 0.5238
     21/Unknown - 3s 162ms/step - loss: 0.7382 - accuracy: 0.5252
     22/Unknown - 3s 159ms/step - loss: 0.7366 - accuracy: 0.5264
     23/Unknown - 4s 156ms/step - loss: 0.7347 - accuracy: 0.5284
     24/Unknown - 4s 153ms/step - loss: 0.7327 - accuracy: 0.5303
     25/Unknown - 4s 151ms/step - loss: 0.7312 - accuracy: 0.5304
     26/Unknown - 4s 149ms/step - loss: 0.7290 - accuracy: 0.5322
     27/Unknown - 4s 147ms/step - loss: 0.7269 - accuracy: 0.5348
     28/Unknown - 4s 144ms/step - loss: 0.7255 - accuracy: 0.5363
     29/Unknown - 4s 142ms/step - loss: 0.7242 - accuracy: 0.5369
     30/Unknown - 4s 139ms/step - loss: 0.7231 - accuracy: 0.5374
30/30 [==============================] - 6s 207ms/step - loss: 0.7231 - accuracy: 0.5374 - val_loss: 0.0000e+00 - val_accuracy: 0.0000e+00
Epoch 2/20

 1/20 [>.............................] - ETA: 12s - loss: 0.6648 - accuracy: 0.6133
 2/20 [==>...........................] - ETA: 6s - loss: 0.6550 - accuracy: 0.6230 
 3/20 [===>..........................] - ETA: 4s - loss: 0.6492 - accuracy: 0.6243
 4/20 [=====>........................] - ETA: 4s - loss: 0.6570 - accuracy: 0.6211
 5/20 [======>.......................] - ETA: 3s - loss: 0.6621 - accuracy: 0.6133
 6/20 [========>.....................] - ETA: 2s - loss: 0.6596 - accuracy: 0.6159
 7/20 [=========>....................] - ETA: 2s - loss: 0.6600 - accuracy: 0.6158
 8/20 [===========>..................] - ETA: 2s - loss: 0.6589 - accuracy: 0.6187
 9/20 [============>.................] - ETA: 1s - loss: 0.6568 - accuracy: 0.6237
10/20 [==============>...............] - ETA: 1s - loss: 0.6567 - accuracy: 0.6244
11/20 [===============>..............] - ETA: 1s - loss: 0.6574 - accuracy: 0.6223
12/20 [=================>............] - ETA: 1s - loss: 0.6539 - accuracy: 0.6265
13/20 [==================>...........] - ETA: 1s - loss: 0.6535 - accuracy: 0.6259
14/20 [====================>.........] - ETA: 0s - loss: 0.6540 - accuracy: 0.6253
15/20 [=====================>........] - ETA: 0s - loss: 0.6531 - accuracy: 0.6254
16/20 [=======================>......] - ETA: 0s - loss: 0.6520 - accuracy: 0.6263
17/20 [========================>.....] - ETA: 0s - loss: 0.6516 - accuracy: 0.6252
18/20 [==========================>...] - ETA: 0s - loss: 0.6519 - accuracy: 0.6253
19/20 [===========================>..] - ETA: 0s - loss: 0.6504 - accuracy: 0.6278
30/30 [==============================] - 5s 173ms/step - loss: 0.6466 - accuracy: 0.6398 - val_loss: 0.6144 - val_accuracy: 0.6696
Epoch 3/20

 1/20 [>.............................] - ETA: 12s - loss: 0.6175 - accuracy: 0.6602
 2/20 [==>...........................] - ETA: 6s - loss: 0.6040 - accuracy: 0.6826 
 3/20 [===>..........................] - ETA: 5s - loss: 0.6080 - accuracy: 0.6823
 4/20 [=====>........................] - ETA: 3s - loss: 0.5987 - accuracy: 0.6914
 5/20 [======>.......................] - ETA: 3s - loss: 0.5974 - accuracy: 0.6922
 6/20 [========>.....................] - ETA: 2s - loss: 0.5993 - accuracy: 0.6872
 7/20 [=========>....................] - ETA: 2s - loss: 0.5989 - accuracy: 0.6881
 8/20 [===========>..................] - ETA: 2s - loss: 0.6000 - accuracy: 0.6890
 9/20 [============>.................] - ETA: 1s - loss: 0.5987 - accuracy: 0.6866
10/20 [==============>...............] - ETA: 1s - loss: 0.5985 - accuracy: 0.6867
11/20 [===============>..............] - ETA: 1s - loss: 0.5995 - accuracy: 0.6848
12/20 [=================>............] - ETA: 1s - loss: 0.5986 - accuracy: 0.6857
13/20 [==================>...........] - ETA: 0s - loss: 0.5981 - accuracy: 0.6870
14/20 [====================>.........] - ETA: 0s - loss: 0.5998 - accuracy: 0.6871
15/20 [=====================>........] - ETA: 0s - loss: 0.5991 - accuracy: 0.6880
16/20 [=======================>......] - ETA: 0s - loss: 0.5985 - accuracy: 0.6890
17/20 [========================>.....] - ETA: 0s - loss: 0.5982 - accuracy: 0.6898
18/20 [==========================>...] - ETA: 0s - loss: 0.5972 - accuracy: 0.6900
19/20 [===========================>..] - ETA: 0s - loss: 0.5948 - accuracy: 0.6926
30/30 [==============================] - 5s 171ms/step - loss: 0.5923 - accuracy: 0.6983 - val_loss: 0.5705 - val_accuracy: 0.7160
Epoch 4/20

 1/20 [>.............................] - ETA: 13s - loss: 0.5646 - accuracy: 0.7031
 2/20 [==>...........................] - ETA: 7s - loss: 0.5533 - accuracy: 0.7158 
 3/20 [===>..........................] - ETA: 5s - loss: 0.5497 - accuracy: 0.7240
 4/20 [=====>........................] - ETA: 4s - loss: 0.5535 - accuracy: 0.7168
 5/20 [======>.......................] - ETA: 3s - loss: 0.5614 - accuracy: 0.7094
 6/20 [========>.....................] - ETA: 3s - loss: 0.5617 - accuracy: 0.7113
 7/20 [=========>....................] - ETA: 2s - loss: 0.5603 - accuracy: 0.7132
 8/20 [===========>..................] - ETA: 2s - loss: 0.5576 - accuracy: 0.7161
 9/20 [============>.................] - ETA: 2s - loss: 0.5545 - accuracy: 0.7216
10/20 [==============>...............] - ETA: 1s - loss: 0.5570 - accuracy: 0.7209
11/20 [===============>..............] - ETA: 1s - loss: 0.5560 - accuracy: 0.7227
12/20 [=================>............] - ETA: 1s - loss: 0.5540 - accuracy: 0.7251
13/20 [==================>...........] - ETA: 1s - loss: 0.5549 - accuracy: 0.7258
14/20 [====================>.........] - ETA: 0s - loss: 0.5525 - accuracy: 0.7288
15/20 [=====================>........] - ETA: 0s - loss: 0.5504 - accuracy: 0.7314
16/20 [=======================>......] - ETA: 0s - loss: 0.5510 - accuracy: 0.7311
17/20 [========================>.....] - ETA: 0s - loss: 0.5492 - accuracy: 0.7333
18/20 [==========================>...] - ETA: 0s - loss: 0.5483 - accuracy: 0.7340
19/20 [===========================>..] - ETA: 0s - loss: 0.5470 - accuracy: 0.7366
30/30 [==============================] - 6s 200ms/step - loss: 0.5450 - accuracy: 0.7421 - val_loss: 0.5294 - val_accuracy: 0.7485
Epoch 5/20

 1/20 [>.............................] - ETA: 15s - loss: 0.5316 - accuracy: 0.7480
 2/20 [==>...........................] - ETA: 8s - loss: 0.5228 - accuracy: 0.7588 
 3/20 [===>..........................] - ETA: 6s - loss: 0.5195 - accuracy: 0.7572
 4/20 [=====>........................] - ETA: 4s - loss: 0.5217 - accuracy: 0.7515
 5/20 [======>.......................] - ETA: 4s - loss: 0.5153 - accuracy: 0.7598
 6/20 [========>.....................] - ETA: 3s - loss: 0.5170 - accuracy: 0.7552
 7/20 [=========>....................] - ETA: 2s - loss: 0.5178 - accuracy: 0.7567
 8/20 [===========>..................] - ETA: 2s - loss: 0.5125 - accuracy: 0.7603
 9/20 [============>.................] - ETA: 2s - loss: 0.5108 - accuracy: 0.7628
10/20 [==============>...............] - ETA: 1s - loss: 0.5105 - accuracy: 0.7627
11/20 [===============>..............] - ETA: 1s - loss: 0.5089 - accuracy: 0.7630
12/20 [=================>............] - ETA: 1s - loss: 0.5065 - accuracy: 0.7660
13/20 [==================>...........] - ETA: 1s - loss: 0.5063 - accuracy: 0.7670
14/20 [====================>.........] - ETA: 1s - loss: 0.5075 - accuracy: 0.7662
15/20 [=====================>........] - ETA: 0s - loss: 0.5076 - accuracy: 0.7669
16/20 [=======================>......] - ETA: 0s - loss: 0.5064 - accuracy: 0.7683
17/20 [========================>.....] - ETA: 0s - loss: 0.5059 - accuracy: 0.7687
18/20 [==========================>...] - ETA: 0s - loss: 0.5062 - accuracy: 0.7688
19/20 [===========================>..] - ETA: 0s - loss: 0.5057 - accuracy: 0.7701
30/30 [==============================] - 6s 203ms/step - loss: 0.5024 - accuracy: 0.7791 - val_loss: 0.4901 - val_accuracy: 0.7749
Epoch 6/20

 1/20 [>.............................] - ETA: 15s - loss: 0.4646 - accuracy: 0.8047
 2/20 [==>...........................] - ETA: 8s - loss: 0.4698 - accuracy: 0.8037 
 3/20 [===>..........................] - ETA: 5s - loss: 0.4678 - accuracy: 0.8073
 4/20 [=====>........................] - ETA: 4s - loss: 0.4634 - accuracy: 0.8105
 5/20 [======>.......................] - ETA: 4s - loss: 0.4670 - accuracy: 0.8051
 6/20 [========>.....................] - ETA: 3s - loss: 0.4673 - accuracy: 0.8031
 7/20 [=========>....................] - ETA: 2s - loss: 0.4622 - accuracy: 0.8041
 8/20 [===========>..................] - ETA: 2s - loss: 0.4659 - accuracy: 0.7981
 9/20 [============>.................] - ETA: 2s - loss: 0.4643 - accuracy: 0.7993
10/20 [==============>...............] - ETA: 1s - loss: 0.4649 - accuracy: 0.8010
11/20 [===============>..............] - ETA: 1s - loss: 0.4656 - accuracy: 0.8008
12/20 [=================>............] - ETA: 1s - loss: 0.4649 - accuracy: 0.8016
13/20 [==================>...........] - ETA: 1s - loss: 0.4630 - accuracy: 0.8026
14/20 [====================>.........] - ETA: 1s - loss: 0.4635 - accuracy: 0.8022
15/20 [=====================>........] - ETA: 0s - loss: 0.4632 - accuracy: 0.8016
16/20 [=======================>......] - ETA: 0s - loss: 0.4617 - accuracy: 0.8038
17/20 [========================>.....] - ETA: 0s - loss: 0.4607 - accuracy: 0.8037
18/20 [==========================>...] - ETA: 0s - loss: 0.4590 - accuracy: 0.8051
19/20 [===========================>..] - ETA: 0s - loss: 0.4603 - accuracy: 0.8041
30/30 [==============================] - 6s 199ms/step - loss: 0.4571 - accuracy: 0.8093 - val_loss: 0.4511 - val_accuracy: 0.7988
Epoch 7/20

 1/20 [>.............................] - ETA: 14s - loss: 0.4428 - accuracy: 0.8164
 2/20 [==>...........................] - ETA: 8s - loss: 0.4384 - accuracy: 0.8281 
 3/20 [===>..........................] - ETA: 6s - loss: 0.4481 - accuracy: 0.8125
 4/20 [=====>........................] - ETA: 4s - loss: 0.4415 - accuracy: 0.8169
 5/20 [======>.......................] - ETA: 4s - loss: 0.4384 - accuracy: 0.8164
 6/20 [========>.....................] - ETA: 3s - loss: 0.4372 - accuracy: 0.8164
 7/20 [=========>....................] - ETA: 2s - loss: 0.4333 - accuracy: 0.8172
 8/20 [===========>..................] - ETA: 2s - loss: 0.4311 - accuracy: 0.8193
 9/20 [============>.................] - ETA: 2s - loss: 0.4309 - accuracy: 0.8181
10/20 [==============>...............] - ETA: 1s - loss: 0.4285 - accuracy: 0.8215
11/20 [===============>..............] - ETA: 1s - loss: 0.4265 - accuracy: 0.8233
12/20 [=================>............] - ETA: 1s - loss: 0.4278 - accuracy: 0.8223
13/20 [==================>...........] - ETA: 1s - loss: 0.4277 - accuracy: 0.8209
14/20 [====================>.........] - ETA: 1s - loss: 0.4268 - accuracy: 0.8220
15/20 [=====================>........] - ETA: 0s - loss: 0.4249 - accuracy: 0.8225
16/20 [=======================>......] - ETA: 0s - loss: 0.4257 - accuracy: 0.8213
17/20 [========================>.....] - ETA: 0s - loss: 0.4243 - accuracy: 0.8218
18/20 [==========================>...] - ETA: 0s - loss: 0.4229 - accuracy: 0.8230
19/20 [===========================>..] - ETA: 0s - loss: 0.4215 - accuracy: 0.8240
30/30 [==============================] - 6s 202ms/step - loss: 0.4168 - accuracy: 0.8331 - val_loss: 0.4177 - val_accuracy: 0.8153
Epoch 8/20

 1/20 [>.............................] - ETA: 15s - loss: 0.3927 - accuracy: 0.8301
 2/20 [==>...........................] - ETA: 8s - loss: 0.3845 - accuracy: 0.8408 
 3/20 [===>..........................] - ETA: 6s - loss: 0.3938 - accuracy: 0.8353
 4/20 [=====>........................] - ETA: 4s - loss: 0.3910 - accuracy: 0.8403
 5/20 [======>.......................] - ETA: 4s - loss: 0.3894 - accuracy: 0.8422
 6/20 [========>.....................] - ETA: 3s - loss: 0.3856 - accuracy: 0.8424
 7/20 [=========>....................] - ETA: 2s - loss: 0.3878 - accuracy: 0.8418
 8/20 [===========>..................] - ETA: 2s - loss: 0.3879 - accuracy: 0.8403
 9/20 [============>.................] - ETA: 2s - loss: 0.3848 - accuracy: 0.8418
10/20 [==============>...............] - ETA: 1s - loss: 0.3860 - accuracy: 0.8418
11/20 [===============>..............] - ETA: 1s - loss: 0.3863 - accuracy: 0.8436
12/20 [=================>............] - ETA: 1s - loss: 0.3855 - accuracy: 0.8438
13/20 [==================>...........] - ETA: 1s - loss: 0.3837 - accuracy: 0.8444
14/20 [====================>.........] - ETA: 1s - loss: 0.3828 - accuracy: 0.8453
15/20 [=====================>........] - ETA: 0s - loss: 0.3827 - accuracy: 0.8454
16/20 [=======================>......] - ETA: 0s - loss: 0.3807 - accuracy: 0.8466
17/20 [========================>.....] - ETA: 0s - loss: 0.3814 - accuracy: 0.8471
18/20 [==========================>...] - ETA: 0s - loss: 0.3782 - accuracy: 0.8492
19/20 [===========================>..] - ETA: 0s - loss: 0.3763 - accuracy: 0.8503
30/30 [==============================] - 6s 202ms/step - loss: 0.3743 - accuracy: 0.8511 - val_loss: 0.3922 - val_accuracy: 0.8263
Epoch 9/20

 1/20 [>.............................] - ETA: 14s - loss: 0.3511 - accuracy: 0.8691
 2/20 [==>...........................] - ETA: 8s - loss: 0.3323 - accuracy: 0.8877 
 3/20 [===>..........................] - ETA: 5s - loss: 0.3369 - accuracy: 0.8724
 4/20 [=====>........................] - ETA: 4s - loss: 0.3332 - accuracy: 0.8760
 5/20 [======>.......................] - ETA: 3s - loss: 0.3403 - accuracy: 0.8676
 6/20 [========>.....................] - ETA: 3s - loss: 0.3397 - accuracy: 0.8688
 7/20 [=========>....................] - ETA: 2s - loss: 0.3422 - accuracy: 0.8669
 8/20 [===========>..................] - ETA: 2s - loss: 0.3463 - accuracy: 0.8650
 9/20 [============>.................] - ETA: 2s - loss: 0.3444 - accuracy: 0.8661
10/20 [==============>...............] - ETA: 1s - loss: 0.3417 - accuracy: 0.8682
11/20 [===============>..............] - ETA: 1s - loss: 0.3413 - accuracy: 0.8677
12/20 [=================>............] - ETA: 1s - loss: 0.3424 - accuracy: 0.8670
13/20 [==================>...........] - ETA: 1s - loss: 0.3441 - accuracy: 0.8657
14/20 [====================>.........] - ETA: 0s - loss: 0.3412 - accuracy: 0.8668
15/20 [=====================>........] - ETA: 0s - loss: 0.3381 - accuracy: 0.8686
16/20 [=======================>......] - ETA: 0s - loss: 0.3397 - accuracy: 0.8676
17/20 [========================>.....] - ETA: 0s - loss: 0.3402 - accuracy: 0.8665
18/20 [==========================>...] - ETA: 0s - loss: 0.3390 - accuracy: 0.8666
19/20 [===========================>..] - ETA: 0s - loss: 0.3398 - accuracy: 0.8653
30/30 [==============================] - 6s 202ms/step - loss: 0.3388 - accuracy: 0.8661 - val_loss: 0.3671 - val_accuracy: 0.8379
Epoch 10/20

 1/20 [>.............................] - ETA: 15s - loss: 0.3103 - accuracy: 0.8809
 2/20 [==>...........................] - ETA: 8s - loss: 0.3342 - accuracy: 0.8711 
 3/20 [===>..........................] - ETA: 5s - loss: 0.3351 - accuracy: 0.8698
 4/20 [=====>........................] - ETA: 4s - loss: 0.3290 - accuracy: 0.8716
 5/20 [======>.......................] - ETA: 3s - loss: 0.3307 - accuracy: 0.8691
 6/20 [========>.....................] - ETA: 3s - loss: 0.3304 - accuracy: 0.8672
 7/20 [=========>....................] - ETA: 2s - loss: 0.3229 - accuracy: 0.8722
 8/20 [===========>..................] - ETA: 2s - loss: 0.3199 - accuracy: 0.8728
 9/20 [============>.................] - ETA: 2s - loss: 0.3155 - accuracy: 0.8737
10/20 [==============>...............] - ETA: 1s - loss: 0.3154 - accuracy: 0.8740
11/20 [===============>..............] - ETA: 1s - loss: 0.3135 - accuracy: 0.8750
12/20 [=================>............] - ETA: 1s - loss: 0.3120 - accuracy: 0.8750
13/20 [==================>...........] - ETA: 1s - loss: 0.3104 - accuracy: 0.8776
14/20 [====================>.........] - ETA: 0s - loss: 0.3106 - accuracy: 0.8779
15/20 [=====================>........] - ETA: 0s - loss: 0.3132 - accuracy: 0.8760
16/20 [=======================>......] - ETA: 0s - loss: 0.3136 - accuracy: 0.8766
17/20 [========================>.....] - ETA: 0s - loss: 0.3132 - accuracy: 0.8767
18/20 [==========================>...] - ETA: 0s - loss: 0.3136 - accuracy: 0.8772
19/20 [===========================>..] - ETA: 0s - loss: 0.3123 - accuracy: 0.8777
30/30 [==============================] - 6s 200ms/step - loss: 0.3105 - accuracy: 0.8806 - val_loss: 0.3484 - val_accuracy: 0.8493
Epoch 11/20

 1/20 [>.............................] - ETA: 14s - loss: 0.3195 - accuracy: 0.8672
 2/20 [==>...........................] - ETA: 8s - loss: 0.3088 - accuracy: 0.8789 
 3/20 [===>..........................] - ETA: 5s - loss: 0.2946 - accuracy: 0.8867
 4/20 [=====>........................] - ETA: 4s - loss: 0.3012 - accuracy: 0.8828
 5/20 [======>.......................] - ETA: 3s - loss: 0.3031 - accuracy: 0.8805
 6/20 [========>.....................] - ETA: 3s - loss: 0.3042 - accuracy: 0.8773
 7/20 [=========>....................] - ETA: 2s - loss: 0.3009 - accuracy: 0.8811
 8/20 [===========>..................] - ETA: 2s - loss: 0.2974 - accuracy: 0.8831
 9/20 [============>.................] - ETA: 2s - loss: 0.2970 - accuracy: 0.8822
10/20 [==============>...............] - ETA: 1s - loss: 0.2963 - accuracy: 0.8824
11/20 [===============>..............] - ETA: 1s - loss: 0.2950 - accuracy: 0.8817
12/20 [=================>............] - ETA: 1s - loss: 0.2919 - accuracy: 0.8844
13/20 [==================>...........] - ETA: 1s - loss: 0.2911 - accuracy: 0.8860
14/20 [====================>.........] - ETA: 1s - loss: 0.2910 - accuracy: 0.8859
15/20 [=====================>........] - ETA: 0s - loss: 0.2908 - accuracy: 0.8859
16/20 [=======================>......] - ETA: 0s - loss: 0.2906 - accuracy: 0.8861
17/20 [========================>.....] - ETA: 0s - loss: 0.2907 - accuracy: 0.8860
18/20 [==========================>...] - ETA: 0s - loss: 0.2902 - accuracy: 0.8870
19/20 [===========================>..] - ETA: 0s - loss: 0.2910 - accuracy: 0.8862
30/30 [==============================] - 6s 202ms/step - loss: 0.2881 - accuracy: 0.8898 - val_loss: 0.3353 - val_accuracy: 0.8557
Epoch 12/20

 1/20 [>.............................] - ETA: 14s - loss: 0.2690 - accuracy: 0.9004
 2/20 [==>...........................] - ETA: 8s - loss: 0.2556 - accuracy: 0.9072 
 3/20 [===>..........................] - ETA: 5s - loss: 0.2513 - accuracy: 0.9036
 4/20 [=====>........................] - ETA: 4s - loss: 0.2599 - accuracy: 0.9014
 5/20 [======>.......................] - ETA: 3s - loss: 0.2614 - accuracy: 0.9000
 6/20 [========>.....................] - ETA: 3s - loss: 0.2639 - accuracy: 0.8968
 7/20 [=========>....................] - ETA: 2s - loss: 0.2648 - accuracy: 0.8962
 8/20 [===========>..................] - ETA: 2s - loss: 0.2618 - accuracy: 0.8984
 9/20 [============>.................] - ETA: 2s - loss: 0.2656 - accuracy: 0.8950
10/20 [==============>...............] - ETA: 1s - loss: 0.2654 - accuracy: 0.8959
11/20 [===============>..............] - ETA: 1s - loss: 0.2670 - accuracy: 0.8951
12/20 [=================>............] - ETA: 1s - loss: 0.2659 - accuracy: 0.8955
13/20 [==================>...........] - ETA: 1s - loss: 0.2657 - accuracy: 0.8959
14/20 [====================>.........] - ETA: 0s - loss: 0.2658 - accuracy: 0.8959
15/20 [=====================>........] - ETA: 0s - loss: 0.2656 - accuracy: 0.8956
16/20 [=======================>......] - ETA: 0s - loss: 0.2653 - accuracy: 0.8969
17/20 [========================>.....] - ETA: 0s - loss: 0.2655 - accuracy: 0.8975
18/20 [==========================>...] - ETA: 0s - loss: 0.2638 - accuracy: 0.8981
19/20 [===========================>..] - ETA: 0s - loss: 0.2628 - accuracy: 0.8985
30/30 [==============================] - 6s 201ms/step - loss: 0.2625 - accuracy: 0.9001 - val_loss: 0.3233 - val_accuracy: 0.8612
Epoch 13/20

 1/20 [>.............................] - ETA: 14s - loss: 0.2426 - accuracy: 0.9160
 2/20 [==>...........................] - ETA: 8s - loss: 0.2490 - accuracy: 0.9053 
 3/20 [===>..........................] - ETA: 5s - loss: 0.2469 - accuracy: 0.9121
 4/20 [=====>........................] - ETA: 4s - loss: 0.2489 - accuracy: 0.9087
 5/20 [======>.......................] - ETA: 3s - loss: 0.2440 - accuracy: 0.9102
 6/20 [========>.....................] - ETA: 3s - loss: 0.2423 - accuracy: 0.9121
 7/20 [=========>....................] - ETA: 2s - loss: 0.2419 - accuracy: 0.9116
 8/20 [===========>..................] - ETA: 2s - loss: 0.2384 - accuracy: 0.9131
 9/20 [============>.................] - ETA: 2s - loss: 0.2403 - accuracy: 0.9130
10/20 [==============>...............] - ETA: 1s - loss: 0.2404 - accuracy: 0.9125
11/20 [===============>..............] - ETA: 1s - loss: 0.2406 - accuracy: 0.9121
12/20 [=================>............] - ETA: 1s - loss: 0.2422 - accuracy: 0.9115
13/20 [==================>...........] - ETA: 1s - loss: 0.2414 - accuracy: 0.9117
14/20 [====================>.........] - ETA: 0s - loss: 0.2401 - accuracy: 0.9117
15/20 [=====================>........] - ETA: 0s - loss: 0.2406 - accuracy: 0.9118
16/20 [=======================>......] - ETA: 0s - loss: 0.2412 - accuracy: 0.9119
17/20 [========================>.....] - ETA: 0s - loss: 0.2426 - accuracy: 0.9110
18/20 [==========================>...] - ETA: 0s - loss: 0.2414 - accuracy: 0.9117
19/20 [===========================>..] - ETA: 0s - loss: 0.2402 - accuracy: 0.9120
30/30 [==============================] - 6s 202ms/step - loss: 0.2409 - accuracy: 0.9108 - val_loss: 0.3147 - val_accuracy: 0.8647
Epoch 14/20

 1/20 [>.............................] - ETA: 15s - loss: 0.2293 - accuracy: 0.9102
 2/20 [==>...........................] - ETA: 8s - loss: 0.2436 - accuracy: 0.9102 
 3/20 [===>..........................] - ETA: 6s - loss: 0.2299 - accuracy: 0.9180
 4/20 [=====>........................] - ETA: 4s - loss: 0.2242 - accuracy: 0.9224
 5/20 [======>.......................] - ETA: 3s - loss: 0.2265 - accuracy: 0.9211
 6/20 [========>.....................] - ETA: 3s - loss: 0.2301 - accuracy: 0.9196
 7/20 [=========>....................] - ETA: 2s - loss: 0.2285 - accuracy: 0.9196
 8/20 [===========>..................] - ETA: 2s - loss: 0.2312 - accuracy: 0.9172
 9/20 [============>.................] - ETA: 2s - loss: 0.2309 - accuracy: 0.9173
10/20 [==============>...............] - ETA: 1s - loss: 0.2306 - accuracy: 0.9166
11/20 [===============>..............] - ETA: 1s - loss: 0.2305 - accuracy: 0.9165
12/20 [=================>............] - ETA: 1s - loss: 0.2298 - accuracy: 0.9163
13/20 [==================>...........] - ETA: 1s - loss: 0.2299 - accuracy: 0.9163
14/20 [====================>.........] - ETA: 0s - loss: 0.2271 - accuracy: 0.9185
15/20 [=====================>........] - ETA: 0s - loss: 0.2269 - accuracy: 0.9191
16/20 [=======================>......] - ETA: 0s - loss: 0.2270 - accuracy: 0.9185
17/20 [========================>.....] - ETA: 0s - loss: 0.2247 - accuracy: 0.9200
18/20 [==========================>...] - ETA: 0s - loss: 0.2255 - accuracy: 0.9191
19/20 [===========================>..] - ETA: 0s - loss: 0.2251 - accuracy: 0.9201
30/30 [==============================] - 6s 200ms/step - loss: 0.2249 - accuracy: 0.9185 - val_loss: 0.3083 - val_accuracy: 0.8677
Epoch 15/20

 1/20 [>.............................] - ETA: 15s - loss: 0.2235 - accuracy: 0.9297
 2/20 [==>...........................] - ETA: 8s - loss: 0.2194 - accuracy: 0.9287 
 3/20 [===>..........................] - ETA: 6s - loss: 0.2232 - accuracy: 0.9238
 4/20 [=====>........................] - ETA: 4s - loss: 0.2185 - accuracy: 0.9248
 5/20 [======>.......................] - ETA: 3s - loss: 0.2181 - accuracy: 0.9258
 6/20 [========>.....................] - ETA: 3s - loss: 0.2187 - accuracy: 0.9261
 7/20 [=========>....................] - ETA: 2s - loss: 0.2233 - accuracy: 0.9244
 8/20 [===========>..................] - ETA: 2s - loss: 0.2206 - accuracy: 0.9253
 9/20 [============>.................] - ETA: 2s - loss: 0.2188 - accuracy: 0.9243
10/20 [==============>...............] - ETA: 1s - loss: 0.2199 - accuracy: 0.9242
11/20 [===============>..............] - ETA: 1s - loss: 0.2179 - accuracy: 0.9251
12/20 [=================>............] - ETA: 1s - loss: 0.2175 - accuracy: 0.9253
13/20 [==================>...........] - ETA: 1s - loss: 0.2174 - accuracy: 0.9246
14/20 [====================>.........] - ETA: 1s - loss: 0.2142 - accuracy: 0.9259
15/20 [=====================>........] - ETA: 0s - loss: 0.2116 - accuracy: 0.9271
16/20 [=======================>......] - ETA: 0s - loss: 0.2119 - accuracy: 0.9270
17/20 [========================>.....] - ETA: 0s - loss: 0.2118 - accuracy: 0.9267
18/20 [==========================>...] - ETA: 0s - loss: 0.2109 - accuracy: 0.9269
19/20 [===========================>..] - ETA: 0s - loss: 0.2118 - accuracy: 0.9261
30/30 [==============================] - 6s 203ms/step - loss: 0.2112 - accuracy: 0.9255 - val_loss: 0.3049 - val_accuracy: 0.8692
Epoch 16/20

 1/20 [>.............................] - ETA: 15s - loss: 0.1807 - accuracy: 0.9336
 2/20 [==>...........................] - ETA: 8s - loss: 0.1794 - accuracy: 0.9404 
 3/20 [===>..........................] - ETA: 6s - loss: 0.1848 - accuracy: 0.9395
 4/20 [=====>........................] - ETA: 4s - loss: 0.1844 - accuracy: 0.9370
 5/20 [======>.......................] - ETA: 3s - loss: 0.1842 - accuracy: 0.9363
 6/20 [========>.....................] - ETA: 3s - loss: 0.1811 - accuracy: 0.9368
 7/20 [=========>....................] - ETA: 2s - loss: 0.1813 - accuracy: 0.9369
 8/20 [===========>..................] - ETA: 2s - loss: 0.1823 - accuracy: 0.9358
 9/20 [============>.................] - ETA: 2s - loss: 0.1834 - accuracy: 0.9351
10/20 [==============>...............] - ETA: 1s - loss: 0.1873 - accuracy: 0.9338
11/20 [===============>..............] - ETA: 1s - loss: 0.1869 - accuracy: 0.9343
12/20 [=================>............] - ETA: 1s - loss: 0.1876 - accuracy: 0.9347
13/20 [==================>...........] - ETA: 1s - loss: 0.1884 - accuracy: 0.9339
14/20 [====================>.........] - ETA: 1s - loss: 0.1891 - accuracy: 0.9337
15/20 [=====================>........] - ETA: 0s - loss: 0.1890 - accuracy: 0.9340
16/20 [=======================>......] - ETA: 0s - loss: 0.1876 - accuracy: 0.9344
17/20 [========================>.....] - ETA: 0s - loss: 0.1867 - accuracy: 0.9352
18/20 [==========================>...] - ETA: 0s - loss: 0.1874 - accuracy: 0.9350
19/20 [===========================>..] - ETA: 0s - loss: 0.1885 - accuracy: 0.9348
30/30 [==============================] - 6s 202ms/step - loss: 0.1911 - accuracy: 0.9321 - val_loss: 0.2996 - val_accuracy: 0.8722
Epoch 17/20

 1/20 [>.............................] - ETA: 15s - loss: 0.2013 - accuracy: 0.9219
 2/20 [==>...........................] - ETA: 8s - loss: 0.1983 - accuracy: 0.9297 
 3/20 [===>..........................] - ETA: 6s - loss: 0.1909 - accuracy: 0.9362
 4/20 [=====>........................] - ETA: 4s - loss: 0.1927 - accuracy: 0.9346
 5/20 [======>.......................] - ETA: 4s - loss: 0.1915 - accuracy: 0.9359
 6/20 [========>.....................] - ETA: 3s - loss: 0.1901 - accuracy: 0.9355
 7/20 [=========>....................] - ETA: 2s - loss: 0.1887 - accuracy: 0.9344
 8/20 [===========>..................] - ETA: 2s - loss: 0.1912 - accuracy: 0.9333
 9/20 [============>.................] - ETA: 2s - loss: 0.1907 - accuracy: 0.9349
10/20 [==============>...............] - ETA: 1s - loss: 0.1918 - accuracy: 0.9348
11/20 [===============>..............] - ETA: 1s - loss: 0.1887 - accuracy: 0.9357
12/20 [=================>............] - ETA: 1s - loss: 0.1896 - accuracy: 0.9354
13/20 [==================>...........] - ETA: 1s - loss: 0.1893 - accuracy: 0.9363
14/20 [====================>.........] - ETA: 1s - loss: 0.1895 - accuracy: 0.9354
15/20 [=====================>........] - ETA: 0s - loss: 0.1881 - accuracy: 0.9354
16/20 [=======================>......] - ETA: 0s - loss: 0.1877 - accuracy: 0.9358
17/20 [========================>.....] - ETA: 0s - loss: 0.1870 - accuracy: 0.9361
18/20 [==========================>...] - ETA: 0s - loss: 0.1876 - accuracy: 0.9354
19/20 [===========================>..] - ETA: 0s - loss: 0.1875 - accuracy: 0.9353
30/30 [==============================] - 6s 205ms/step - loss: 0.1859 - accuracy: 0.9370 - val_loss: 0.3001 - val_accuracy: 0.8726
Epoch 18/20

 1/20 [>.............................] - ETA: 18s - loss: 0.1795 - accuracy: 0.9297
 2/20 [==>...........................] - ETA: 10s - loss: 0.1775 - accuracy: 0.9355
 3/20 [===>..........................] - ETA: 7s - loss: 0.1709 - accuracy: 0.9382 
 4/20 [=====>........................] - ETA: 5s - loss: 0.1768 - accuracy: 0.9326
 5/20 [======>.......................] - ETA: 4s - loss: 0.1730 - accuracy: 0.9352
 6/20 [========>.....................] - ETA: 3s - loss: 0.1740 - accuracy: 0.9378
 7/20 [=========>....................] - ETA: 3s - loss: 0.1740 - accuracy: 0.9381
 8/20 [===========>..................] - ETA: 2s - loss: 0.1721 - accuracy: 0.9395
 9/20 [============>.................] - ETA: 2s - loss: 0.1741 - accuracy: 0.9379
10/20 [==============>...............] - ETA: 2s - loss: 0.1772 - accuracy: 0.9363
11/20 [===============>..............] - ETA: 1s - loss: 0.1762 - accuracy: 0.9379
12/20 [=================>............] - ETA: 1s - loss: 0.1747 - accuracy: 0.9375
13/20 [==================>...........] - ETA: 1s - loss: 0.1744 - accuracy: 0.9389
14/20 [====================>.........] - ETA: 1s - loss: 0.1745 - accuracy: 0.9385
15/20 [=====================>........] - ETA: 0s - loss: 0.1731 - accuracy: 0.9384
16/20 [=======================>......] - ETA: 0s - loss: 0.1728 - accuracy: 0.9386
17/20 [========================>.....] - ETA: 0s - loss: 0.1724 - accuracy: 0.9388
18/20 [==========================>...] - ETA: 0s - loss: 0.1718 - accuracy: 0.9393
19/20 [===========================>..] - ETA: 0s - loss: 0.1720 - accuracy: 0.9395
30/30 [==============================] - 7s 219ms/step - loss: 0.1719 - accuracy: 0.9403 - val_loss: 0.2969 - val_accuracy: 0.8743
Epoch 19/20

 1/20 [>.............................] - ETA: 15s - loss: 0.1690 - accuracy: 0.9336
 2/20 [==>...........................] - ETA: 8s - loss: 0.1825 - accuracy: 0.9375 
 3/20 [===>..........................] - ETA: 6s - loss: 0.1645 - accuracy: 0.9453
 4/20 [=====>........................] - ETA: 4s - loss: 0.1615 - accuracy: 0.9453
 5/20 [======>.......................] - ETA: 4s - loss: 0.1647 - accuracy: 0.9426
 6/20 [========>.....................] - ETA: 3s - loss: 0.1627 - accuracy: 0.9440
 7/20 [=========>....................] - ETA: 3s - loss: 0.1635 - accuracy: 0.9436
 8/20 [===========>..................] - ETA: 2s - loss: 0.1634 - accuracy: 0.9446
 9/20 [============>.................] - ETA: 2s - loss: 0.1634 - accuracy: 0.9451
10/20 [==============>...............] - ETA: 1s - loss: 0.1618 - accuracy: 0.9455
11/20 [===============>..............] - ETA: 1s - loss: 0.1606 - accuracy: 0.9466
12/20 [=================>............] - ETA: 1s - loss: 0.1594 - accuracy: 0.9478
13/20 [==================>...........] - ETA: 1s - loss: 0.1603 - accuracy: 0.9465
14/20 [====================>.........] - ETA: 1s - loss: 0.1597 - accuracy: 0.9471
15/20 [=====================>........] - ETA: 0s - loss: 0.1591 - accuracy: 0.9473
16/20 [=======================>......] - ETA: 0s - loss: 0.1582 - accuracy: 0.9482
17/20 [========================>.....] - ETA: 0s - loss: 0.1570 - accuracy: 0.9489
18/20 [==========================>...] - ETA: 0s - loss: 0.1583 - accuracy: 0.9485
19/20 [===========================>..] - ETA: 0s - loss: 0.1588 - accuracy: 0.9475
30/30 [==============================] - 6s 210ms/step - loss: 0.1597 - accuracy: 0.9454 - val_loss: 0.2963 - val_accuracy: 0.8748
Epoch 20/20

 1/20 [>.............................] - ETA: 15s - loss: 0.1607 - accuracy: 0.9473
 2/20 [==>...........................] - ETA: 8s - loss: 0.1588 - accuracy: 0.9463 
 3/20 [===>..........................] - ETA: 6s - loss: 0.1581 - accuracy: 0.9486
 4/20 [=====>........................] - ETA: 5s - loss: 0.1546 - accuracy: 0.9512
 5/20 [======>.......................] - ETA: 4s - loss: 0.1526 - accuracy: 0.9516
 6/20 [========>.....................] - ETA: 3s - loss: 0.1543 - accuracy: 0.9512
 7/20 [=========>....................] - ETA: 2s - loss: 0.1532 - accuracy: 0.9528
 8/20 [===========>..................] - ETA: 2s - loss: 0.1541 - accuracy: 0.9534
 9/20 [============>.................] - ETA: 2s - loss: 0.1542 - accuracy: 0.9531
10/20 [==============>...............] - ETA: 1s - loss: 0.1539 - accuracy: 0.9523
11/20 [===============>..............] - ETA: 1s - loss: 0.1536 - accuracy: 0.9515
12/20 [=================>............] - ETA: 1s - loss: 0.1515 - accuracy: 0.9518
13/20 [==================>...........] - ETA: 1s - loss: 0.1529 - accuracy: 0.9509
14/20 [====================>.........] - ETA: 1s - loss: 0.1542 - accuracy: 0.9508
15/20 [=====================>........] - ETA: 0s - loss: 0.1539 - accuracy: 0.9509
16/20 [=======================>......] - ETA: 0s - loss: 0.1515 - accuracy: 0.9519
17/20 [========================>.....] - ETA: 0s - loss: 0.1503 - accuracy: 0.9520
18/20 [==========================>...] - ETA: 0s - loss: 0.1510 - accuracy: 0.9521
19/20 [===========================>..] - ETA: 0s - loss: 0.1517 - accuracy: 0.9515
30/30 [==============================] - 6s 213ms/step - loss: 0.1513 - accuracy: 0.9509 - val_loss: 0.2954 - val_accuracy: 0.8758
49/49 - 5s - loss: 0.3182 - accuracy: 0.8657
loss: 0.318
accuracy: 0.866

你可能感兴趣的:(TensorFlow)