美文网首页
Tensorflow机器学习神经网络学习案例

Tensorflow机器学习神经网络学习案例

作者: 火卫控 | 来源:发表于2021-12-04 00:42 被阅读0次

    神经网络框架TensorFlow,谷歌开发
    序列结果下:


    image.png image.png

    控制台结果如下:

    G:\python_projectkotin\venv\Scripts\python.exe F:/vscode-python-kiton/数学/TensorFlow/zijiancpugpu-vs.py
    2021-12-02 03:50:38.798149: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
    2021-12-02 03:50:38.798433: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
    训练数据形状, (60000, 28, 28)
    数据最大值  255
    查看标签数值  [9 0 0 ... 3 0 5]
    2021-12-02 03:50:45.909224: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
    2021-12-02 03:50:45.957119: E tensorflow/stream_executor/cuda/cuda_driver.cc:351] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
    2021-12-02 03:50:45.960296: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: KOTIN
    2021-12-02 03:50:45.960534: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: KOTIN
    2021-12-02 03:50:45.961982: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
    Model: "sequential"
    _________________________________________________________________
    Layer (type)                 Output Shape              Param #   
    =================================================================
    flatten (Flatten)            (None, 784)               0         
    _________________________________________________________________
    dense (Dense)                (None, 128)               100480    
    _________________________________________________________________
    dense_1 (Dense)              (None, 10)                1290      
    =================================================================
    Total params: 101,770
    Trainable params: 101,770
    Non-trainable params: 0
    _________________________________________________________________
    查看自己写的代码的总体参数  None
    Train on 60000 samples
    Epoch 1/10
    
       32/60000 [..............................] - ETA: 5:57 - loss: 2.4495 - accuracy: 0.0312
     2112/60000 [>.............................] - ETA: 6s - loss: 1.0450 - accuracy: 0.6274  
     4288/60000 [=>............................] - ETA: 3s - loss: 0.8700 - accuracy: 0.6887
     6432/60000 [==>...........................] - ETA: 2s - loss: 0.7774 - accuracy: 0.7240
     8544/60000 [===>..........................] - ETA: 2s - loss: 0.7263 - accuracy: 0.7425
    10624/60000 [====>.........................] - ETA: 2s - loss: 0.6925 - accuracy: 0.7569
    12768/60000 [=====>........................] - ETA: 1s - loss: 0.6670 - accuracy: 0.7660
    14912/60000 [======>.......................] - ETA: 1s - loss: 0.6416 - accuracy: 0.7748
    17088/60000 [=======>......................] - ETA: 1s - loss: 0.6248 - accuracy: 0.7792
    19232/60000 [========>.....................] - ETA: 1s - loss: 0.6133 - accuracy: 0.7842
    21344/60000 [=========>....................] - ETA: 1s - loss: 0.6025 - accuracy: 0.7887
    23520/60000 [==========>...................] - ETA: 1s - loss: 0.5909 - accuracy: 0.7927
    25632/60000 [===========>..................] - ETA: 1s - loss: 0.5812 - accuracy: 0.7964
    27712/60000 [============>.................] - ETA: 0s - loss: 0.5717 - accuracy: 0.7993
    29792/60000 [=============>................] - ETA: 0s - loss: 0.5626 - accuracy: 0.8021
    31936/60000 [==============>...............] - ETA: 0s - loss: 0.5544 - accuracy: 0.8049
    34112/60000 [================>.............] - ETA: 0s - loss: 0.5491 - accuracy: 0.8070
    36224/60000 [=================>............] - ETA: 0s - loss: 0.5423 - accuracy: 0.8089
    38368/60000 [==================>...........] - ETA: 0s - loss: 0.5370 - accuracy: 0.8111
    40448/60000 [===================>..........] - ETA: 0s - loss: 0.5328 - accuracy: 0.8125
    42624/60000 [====================>.........] - ETA: 0s - loss: 0.5273 - accuracy: 0.8149
    44736/60000 [=====================>........] - ETA: 0s - loss: 0.5232 - accuracy: 0.8160
    46880/60000 [======================>.......] - ETA: 0s - loss: 0.5191 - accuracy: 0.8170
    48992/60000 [=======================>......] - ETA: 0s - loss: 0.5162 - accuracy: 0.8183
    51072/60000 [========================>.....] - ETA: 0s - loss: 0.5105 - accuracy: 0.8202
    53248/60000 [=========================>....] - ETA: 0s - loss: 0.5062 - accuracy: 0.8219
    54592/60000 [==========================>...] - ETA: 0s - loss: 0.5039 - accuracy: 0.8225
    56640/60000 [===========================>..] - ETA: 0s - loss: 0.5005 - accuracy: 0.8239
    58784/60000 [============================>.] - ETA: 0s - loss: 0.4967 - accuracy: 0.8250
    60000/60000 [==============================] - 2s 28us/sample - loss: 0.4947 - accuracy: 0.8257
    Epoch 2/10
    
       32/60000 [..............................] - ETA: 1s - loss: 0.3743 - accuracy: 0.8750
     2112/60000 [>.............................] - ETA: 1s - loss: 0.3884 - accuracy: 0.8575
     4256/60000 [=>............................] - ETA: 1s - loss: 0.3778 - accuracy: 0.8607
     6272/60000 [==>...........................] - ETA: 1s - loss: 0.3752 - accuracy: 0.8619
     8192/60000 [===>..........................] - ETA: 1s - loss: 0.3764 - accuracy: 0.8622
    10112/60000 [====>.........................] - ETA: 1s - loss: 0.3782 - accuracy: 0.8624
    12032/60000 [=====>........................] - ETA: 1s - loss: 0.3800 - accuracy: 0.8625
    14080/60000 [======>.......................] - ETA: 1s - loss: 0.3772 - accuracy: 0.8630
    16160/60000 [=======>......................] - ETA: 1s - loss: 0.3767 - accuracy: 0.8629
    18176/60000 [========>.....................] - ETA: 1s - loss: 0.3819 - accuracy: 0.8614
    20256/60000 [=========>....................] - ETA: 0s - loss: 0.3805 - accuracy: 0.8625
    22400/60000 [==========>...................] - ETA: 0s - loss: 0.3811 - accuracy: 0.8617
    24512/60000 [===========>..................] - ETA: 0s - loss: 0.3817 - accuracy: 0.8619
    26592/60000 [============>.................] - ETA: 0s - loss: 0.3818 - accuracy: 0.8617
    28704/60000 [=============>................] - ETA: 0s - loss: 0.3817 - accuracy: 0.8610
    30848/60000 [==============>...............] - ETA: 0s - loss: 0.3799 - accuracy: 0.8622
    32928/60000 [===============>..............] - ETA: 0s - loss: 0.3783 - accuracy: 0.8629
    35040/60000 [================>.............] - ETA: 0s - loss: 0.3774 - accuracy: 0.8633
    37120/60000 [=================>............] - ETA: 0s - loss: 0.3784 - accuracy: 0.8627
    39264/60000 [==================>...........] - ETA: 0s - loss: 0.3777 - accuracy: 0.8626
    41408/60000 [===================>..........] - ETA: 0s - loss: 0.3766 - accuracy: 0.8628
    43392/60000 [====================>.........] - ETA: 0s - loss: 0.3765 - accuracy: 0.8629
    45472/60000 [=====================>........] - ETA: 0s - loss: 0.3754 - accuracy: 0.8635
    47616/60000 [======================>.......] - ETA: 0s - loss: 0.3750 - accuracy: 0.8638
    49696/60000 [=======================>......] - ETA: 0s - loss: 0.3735 - accuracy: 0.8648
    51808/60000 [========================>.....] - ETA: 0s - loss: 0.3729 - accuracy: 0.8648
    53920/60000 [=========================>....] - ETA: 0s - loss: 0.3725 - accuracy: 0.8652
    56064/60000 [===========================>..] - ETA: 0s - loss: 0.3725 - accuracy: 0.8653
    58176/60000 [============================>.] - ETA: 0s - loss: 0.3727 - accuracy: 0.8654
    60000/60000 [==============================] - 1s 24us/sample - loss: 0.3722 - accuracy: 0.8658
    Epoch 3/10
    
       32/60000 [..............................] - ETA: 1s - loss: 0.3212 - accuracy: 0.8438
     2080/60000 [>.............................] - ETA: 1s - loss: 0.3320 - accuracy: 0.8659
     4224/60000 [=>............................] - ETA: 1s - loss: 0.3536 - accuracy: 0.8655
     6336/60000 [==>...........................] - ETA: 1s - loss: 0.3397 - accuracy: 0.8741
     8416/60000 [===>..........................] - ETA: 1s - loss: 0.3368 - accuracy: 0.8752
    10496/60000 [====>.........................] - ETA: 1s - loss: 0.3326 - accuracy: 0.8760
    12608/60000 [=====>........................] - ETA: 1s - loss: 0.3325 - accuracy: 0.8761
    14720/60000 [======>.......................] - ETA: 1s - loss: 0.3325 - accuracy: 0.8755
    16768/60000 [=======>......................] - ETA: 1s - loss: 0.3325 - accuracy: 0.8760
    18880/60000 [========>.....................] - ETA: 0s - loss: 0.3317 - accuracy: 0.8765
    20928/60000 [=========>....................] - ETA: 0s - loss: 0.3312 - accuracy: 0.8766
    23040/60000 [==========>...................] - ETA: 0s - loss: 0.3320 - accuracy: 0.8763
    25088/60000 [===========>..................] - ETA: 0s - loss: 0.3313 - accuracy: 0.8763
    27168/60000 [============>.................] - ETA: 0s - loss: 0.3300 - accuracy: 0.8772
    29280/60000 [=============>................] - ETA: 0s - loss: 0.3303 - accuracy: 0.8767
    31392/60000 [==============>...............] - ETA: 0s - loss: 0.3327 - accuracy: 0.8764
    33472/60000 [===============>..............] - ETA: 0s - loss: 0.3322 - accuracy: 0.8768
    35584/60000 [================>.............] - ETA: 0s - loss: 0.3328 - accuracy: 0.8769
    37728/60000 [=================>............] - ETA: 0s - loss: 0.3326 - accuracy: 0.8771
    39872/60000 [==================>...........] - ETA: 0s - loss: 0.3322 - accuracy: 0.8771
    41888/60000 [===================>..........] - ETA: 0s - loss: 0.3323 - accuracy: 0.8771
    43968/60000 [====================>.........] - ETA: 0s - loss: 0.3327 - accuracy: 0.8770
    45888/60000 [=====================>........] - ETA: 0s - loss: 0.3318 - accuracy: 0.8775
    47968/60000 [======================>.......] - ETA: 0s - loss: 0.3327 - accuracy: 0.8772
    50048/60000 [========================>.....] - ETA: 0s - loss: 0.3333 - accuracy: 0.8767
    52160/60000 [=========================>....] - ETA: 0s - loss: 0.3326 - accuracy: 0.8769
    54208/60000 [==========================>...] - ETA: 0s - loss: 0.3330 - accuracy: 0.8768
    56288/60000 [===========================>..] - ETA: 0s - loss: 0.3328 - accuracy: 0.8771
    58400/60000 [============================>.] - ETA: 0s - loss: 0.3325 - accuracy: 0.8776
    60000/60000 [==============================] - 1s 24us/sample - loss: 0.3336 - accuracy: 0.8775
    Epoch 4/10
    
       32/60000 [..............................] - ETA: 1s - loss: 0.3212 - accuracy: 0.9062
     2176/60000 [>.............................] - ETA: 1s - loss: 0.3168 - accuracy: 0.8810
     4256/60000 [=>............................] - ETA: 1s - loss: 0.3032 - accuracy: 0.8884
     6304/60000 [==>...........................] - ETA: 1s - loss: 0.3039 - accuracy: 0.8861
     8416/60000 [===>..........................] - ETA: 1s - loss: 0.3089 - accuracy: 0.8838
    10560/60000 [====>.........................] - ETA: 1s - loss: 0.3106 - accuracy: 0.8844
    12672/60000 [=====>........................] - ETA: 1s - loss: 0.3097 - accuracy: 0.8849
    14784/60000 [======>.......................] - ETA: 1s - loss: 0.3119 - accuracy: 0.8840
    16896/60000 [=======>......................] - ETA: 1s - loss: 0.3134 - accuracy: 0.8828
    19008/60000 [========>.....................] - ETA: 0s - loss: 0.3130 - accuracy: 0.8830
    21120/60000 [=========>....................] - ETA: 0s - loss: 0.3133 - accuracy: 0.8835
    23200/60000 [==========>...................] - ETA: 0s - loss: 0.3126 - accuracy: 0.8848
    25344/60000 [===========>..................] - ETA: 0s - loss: 0.3160 - accuracy: 0.8835
    27456/60000 [============>.................] - ETA: 0s - loss: 0.3152 - accuracy: 0.8833
    29600/60000 [=============>................] - ETA: 0s - loss: 0.3155 - accuracy: 0.8833
    31744/60000 [==============>...............] - ETA: 0s - loss: 0.3145 - accuracy: 0.8838
    33888/60000 [===============>..............] - ETA: 0s - loss: 0.3141 - accuracy: 0.8844
    36032/60000 [=================>............] - ETA: 0s - loss: 0.3143 - accuracy: 0.8845
    38080/60000 [==================>...........] - ETA: 0s - loss: 0.3155 - accuracy: 0.8844
    40192/60000 [===================>..........] - ETA: 0s - loss: 0.3148 - accuracy: 0.8846
    42304/60000 [====================>.........] - ETA: 0s - loss: 0.3151 - accuracy: 0.8849
    44448/60000 [=====================>........] - ETA: 0s - loss: 0.3149 - accuracy: 0.8849
    46592/60000 [======================>.......] - ETA: 0s - loss: 0.3147 - accuracy: 0.8849
    48704/60000 [=======================>......] - ETA: 0s - loss: 0.3136 - accuracy: 0.8852
    50816/60000 [========================>.....] - ETA: 0s - loss: 0.3134 - accuracy: 0.8852
    52960/60000 [=========================>....] - ETA: 0s - loss: 0.3126 - accuracy: 0.8856
    55072/60000 [==========================>...] - ETA: 0s - loss: 0.3131 - accuracy: 0.8854
    57216/60000 [===========================>..] - ETA: 0s - loss: 0.3114 - accuracy: 0.8860
    59296/60000 [============================>.] - ETA: 0s - loss: 0.3111 - accuracy: 0.8861
    60000/60000 [==============================] - 1s 24us/sample - loss: 0.3108 - accuracy: 0.8863
    Epoch 5/10
    
       32/60000 [..............................] - ETA: 1s - loss: 0.3649 - accuracy: 0.8438
     2176/60000 [>.............................] - ETA: 1s - loss: 0.2805 - accuracy: 0.8915
     4288/60000 [=>............................] - ETA: 1s - loss: 0.2906 - accuracy: 0.8937
     6432/60000 [==>...........................] - ETA: 1s - loss: 0.2973 - accuracy: 0.8905
     8544/60000 [===>..........................] - ETA: 1s - loss: 0.2966 - accuracy: 0.8902
    10624/60000 [====>.........................] - ETA: 1s - loss: 0.2918 - accuracy: 0.8917
    12704/60000 [=====>........................] - ETA: 1s - loss: 0.2951 - accuracy: 0.8904
    14784/60000 [======>.......................] - ETA: 1s - loss: 0.2940 - accuracy: 0.8910
    16928/60000 [=======>......................] - ETA: 1s - loss: 0.2983 - accuracy: 0.8898
    19008/60000 [========>.....................] - ETA: 0s - loss: 0.2969 - accuracy: 0.8900
    21120/60000 [=========>....................] - ETA: 0s - loss: 0.2990 - accuracy: 0.8895
    23200/60000 [==========>...................] - ETA: 0s - loss: 0.2991 - accuracy: 0.8897
    25312/60000 [===========>..................] - ETA: 0s - loss: 0.2982 - accuracy: 0.8899
    27456/60000 [============>.................] - ETA: 0s - loss: 0.2976 - accuracy: 0.8899
    29568/60000 [=============>................] - ETA: 0s - loss: 0.2963 - accuracy: 0.8908
    31712/60000 [==============>...............] - ETA: 0s - loss: 0.2956 - accuracy: 0.8911
    33824/60000 [===============>..............] - ETA: 0s - loss: 0.2951 - accuracy: 0.8912
    35968/60000 [================>.............] - ETA: 0s - loss: 0.2960 - accuracy: 0.8913
    38048/60000 [==================>...........] - ETA: 0s - loss: 0.2954 - accuracy: 0.8913
    40160/60000 [===================>..........] - ETA: 0s - loss: 0.2956 - accuracy: 0.8914
    42304/60000 [====================>.........] - ETA: 0s - loss: 0.2945 - accuracy: 0.8920
    44448/60000 [=====================>........] - ETA: 0s - loss: 0.2939 - accuracy: 0.8923
    46560/60000 [======================>.......] - ETA: 0s - loss: 0.2955 - accuracy: 0.8916
    48672/60000 [=======================>......] - ETA: 0s - loss: 0.2946 - accuracy: 0.8919
    50752/60000 [========================>.....] - ETA: 0s - loss: 0.2939 - accuracy: 0.8920
    52928/60000 [=========================>....] - ETA: 0s - loss: 0.2933 - accuracy: 0.8921
    55040/60000 [==========================>...] - ETA: 0s - loss: 0.2931 - accuracy: 0.8923
    57152/60000 [===========================>..] - ETA: 0s - loss: 0.2935 - accuracy: 0.8922
    59296/60000 [============================>.] - ETA: 0s - loss: 0.2941 - accuracy: 0.8918
    60000/60000 [==============================] - 1s 24us/sample - loss: 0.2944 - accuracy: 0.8917
    Epoch 6/10
    
       32/60000 [..............................] - ETA: 1s - loss: 0.2428 - accuracy: 0.8750
     2144/60000 [>.............................] - ETA: 1s - loss: 0.2666 - accuracy: 0.9030
     4128/60000 [=>............................] - ETA: 1s - loss: 0.2768 - accuracy: 0.9000
     6144/60000 [==>...........................] - ETA: 1s - loss: 0.2669 - accuracy: 0.9033
     8224/60000 [===>..........................] - ETA: 1s - loss: 0.2649 - accuracy: 0.9020
    10336/60000 [====>.........................] - ETA: 1s - loss: 0.2724 - accuracy: 0.8988
    12352/60000 [=====>........................] - ETA: 1s - loss: 0.2746 - accuracy: 0.8981
    14432/60000 [======>.......................] - ETA: 1s - loss: 0.2750 - accuracy: 0.8984
    16480/60000 [=======>......................] - ETA: 1s - loss: 0.2717 - accuracy: 0.8990
    18624/60000 [========>.....................] - ETA: 1s - loss: 0.2705 - accuracy: 0.8998
    20768/60000 [=========>....................] - ETA: 0s - loss: 0.2712 - accuracy: 0.8999
    22784/60000 [==========>...................] - ETA: 0s - loss: 0.2711 - accuracy: 0.9001
    24896/60000 [===========>..................] - ETA: 0s - loss: 0.2715 - accuracy: 0.9000
    26976/60000 [============>.................] - ETA: 0s - loss: 0.2720 - accuracy: 0.8994
    29088/60000 [=============>................] - ETA: 0s - loss: 0.2730 - accuracy: 0.8992
    31232/60000 [==============>...............] - ETA: 0s - loss: 0.2737 - accuracy: 0.8985
    33280/60000 [===============>..............] - ETA: 0s - loss: 0.2725 - accuracy: 0.8991
    35424/60000 [================>.............] - ETA: 0s - loss: 0.2737 - accuracy: 0.8987
    37536/60000 [=================>............] - ETA: 0s - loss: 0.2738 - accuracy: 0.8987
    39680/60000 [==================>...........] - ETA: 0s - loss: 0.2737 - accuracy: 0.8986
    41792/60000 [===================>..........] - ETA: 0s - loss: 0.2742 - accuracy: 0.8984
    43840/60000 [====================>.........] - ETA: 0s - loss: 0.2750 - accuracy: 0.8985
    45952/60000 [=====================>........] - ETA: 0s - loss: 0.2769 - accuracy: 0.8980
    48064/60000 [=======================>......] - ETA: 0s - loss: 0.2770 - accuracy: 0.8980
    50176/60000 [========================>.....] - ETA: 0s - loss: 0.2781 - accuracy: 0.8976
    52320/60000 [=========================>....] - ETA: 0s - loss: 0.2774 - accuracy: 0.8979
    54432/60000 [==========================>...] - ETA: 0s - loss: 0.2767 - accuracy: 0.8982
    56512/60000 [===========================>..] - ETA: 0s - loss: 0.2778 - accuracy: 0.8975
    58656/60000 [============================>.] - ETA: 0s - loss: 0.2787 - accuracy: 0.8973
    60000/60000 [==============================] - 1s 24us/sample - loss: 0.2790 - accuracy: 0.8972
    Epoch 7/10
    
       32/60000 [..............................] - ETA: 3s - loss: 0.2386 - accuracy: 0.9062
     2080/60000 [>.............................] - ETA: 1s - loss: 0.2425 - accuracy: 0.9115
     4192/60000 [=>............................] - ETA: 1s - loss: 0.2627 - accuracy: 0.9034
     6272/60000 [==>...........................] - ETA: 1s - loss: 0.2653 - accuracy: 0.9034
     8384/60000 [===>..........................] - ETA: 1s - loss: 0.2667 - accuracy: 0.9024
    10464/60000 [====>.........................] - ETA: 1s - loss: 0.2677 - accuracy: 0.9019
    12608/60000 [=====>........................] - ETA: 1s - loss: 0.2671 - accuracy: 0.9016
    14752/60000 [======>.......................] - ETA: 1s - loss: 0.2678 - accuracy: 0.9015
    16896/60000 [=======>......................] - ETA: 1s - loss: 0.2678 - accuracy: 0.9014
    19040/60000 [========>.....................] - ETA: 0s - loss: 0.2688 - accuracy: 0.9001
    21152/60000 [=========>....................] - ETA: 0s - loss: 0.2733 - accuracy: 0.8984
    23200/60000 [==========>...................] - ETA: 0s - loss: 0.2746 - accuracy: 0.8976
    25344/60000 [===========>..................] - ETA: 0s - loss: 0.2738 - accuracy: 0.8984
    27488/60000 [============>.................] - ETA: 0s - loss: 0.2735 - accuracy: 0.8988
    29568/60000 [=============>................] - ETA: 0s - loss: 0.2735 - accuracy: 0.8988
    31680/60000 [==============>...............] - ETA: 0s - loss: 0.2727 - accuracy: 0.8991
    33824/60000 [===============>..............] - ETA: 0s - loss: 0.2729 - accuracy: 0.8988
    35936/60000 [================>.............] - ETA: 0s - loss: 0.2715 - accuracy: 0.8994
    38112/60000 [==================>...........] - ETA: 0s - loss: 0.2713 - accuracy: 0.8998
    40256/60000 [===================>..........] - ETA: 0s - loss: 0.2711 - accuracy: 0.8994
    42400/60000 [====================>.........] - ETA: 0s - loss: 0.2709 - accuracy: 0.8995
    44544/60000 [=====================>........] - ETA: 0s - loss: 0.2704 - accuracy: 0.8995
    46688/60000 [======================>.......] - ETA: 0s - loss: 0.2709 - accuracy: 0.8992
    48832/60000 [=======================>......] - ETA: 0s - loss: 0.2699 - accuracy: 0.8996
    51008/60000 [========================>.....] - ETA: 0s - loss: 0.2686 - accuracy: 0.8999
    53056/60000 [=========================>....] - ETA: 0s - loss: 0.2679 - accuracy: 0.9000
    55200/60000 [==========================>...] - ETA: 0s - loss: 0.2674 - accuracy: 0.9000
    57376/60000 [===========================>..] - ETA: 0s - loss: 0.2661 - accuracy: 0.9002
    59456/60000 [============================>.] - ETA: 0s - loss: 0.2663 - accuracy: 0.9001
    60000/60000 [==============================] - 1s 24us/sample - loss: 0.2664 - accuracy: 0.9002
    Epoch 8/10
    
       32/60000 [..............................] - ETA: 1s - loss: 0.2911 - accuracy: 0.9375
     2144/60000 [>.............................] - ETA: 1s - loss: 0.2324 - accuracy: 0.9165
     4288/60000 [=>............................] - ETA: 1s - loss: 0.2474 - accuracy: 0.9097
     6368/60000 [==>...........................] - ETA: 1s - loss: 0.2515 - accuracy: 0.9081
     8480/60000 [===>..........................] - ETA: 1s - loss: 0.2529 - accuracy: 0.9079
    10528/60000 [====>.........................] - ETA: 1s - loss: 0.2516 - accuracy: 0.9077
    12640/60000 [=====>........................] - ETA: 1s - loss: 0.2451 - accuracy: 0.9089
    14720/60000 [======>.......................] - ETA: 1s - loss: 0.2465 - accuracy: 0.9077
    16832/60000 [=======>......................] - ETA: 1s - loss: 0.2464 - accuracy: 0.9079
    18976/60000 [========>.....................] - ETA: 0s - loss: 0.2476 - accuracy: 0.9080
    21120/60000 [=========>....................] - ETA: 0s - loss: 0.2521 - accuracy: 0.9059
    23264/60000 [==========>...................] - ETA: 0s - loss: 0.2541 - accuracy: 0.9053
    25408/60000 [===========>..................] - ETA: 0s - loss: 0.2538 - accuracy: 0.9057
    27584/60000 [============>.................] - ETA: 0s - loss: 0.2535 - accuracy: 0.9058
    29632/60000 [=============>................] - ETA: 0s - loss: 0.2547 - accuracy: 0.9055
    31712/60000 [==============>...............] - ETA: 0s - loss: 0.2538 - accuracy: 0.9060
    33824/60000 [===============>..............] - ETA: 0s - loss: 0.2548 - accuracy: 0.9059
    35936/60000 [================>.............] - ETA: 0s - loss: 0.2560 - accuracy: 0.9052
    38048/60000 [==================>...........] - ETA: 0s - loss: 0.2565 - accuracy: 0.9050
    40160/60000 [===================>..........] - ETA: 0s - loss: 0.2568 - accuracy: 0.9052
    42240/60000 [====================>.........] - ETA: 0s - loss: 0.2567 - accuracy: 0.9051
    44416/60000 [=====================>........] - ETA: 0s - loss: 0.2550 - accuracy: 0.9058
    46560/60000 [======================>.......] - ETA: 0s - loss: 0.2552 - accuracy: 0.9057
    48672/60000 [=======================>......] - ETA: 0s - loss: 0.2555 - accuracy: 0.9057
    50784/60000 [========================>.....] - ETA: 0s - loss: 0.2556 - accuracy: 0.9053
    52960/60000 [=========================>....] - ETA: 0s - loss: 0.2557 - accuracy: 0.9055
    55040/60000 [==========================>...] - ETA: 0s - loss: 0.2563 - accuracy: 0.9054
    57216/60000 [===========================>..] - ETA: 0s - loss: 0.2562 - accuracy: 0.9054
    59360/60000 [============================>.] - ETA: 0s - loss: 0.2560 - accuracy: 0.9056
    60000/60000 [==============================] - 1s 24us/sample - loss: 0.2560 - accuracy: 0.9054
    Epoch 9/10
    
       32/60000 [..............................] - ETA: 1s - loss: 0.2425 - accuracy: 0.9062
     2144/60000 [>.............................] - ETA: 1s - loss: 0.2481 - accuracy: 0.9095
     4256/60000 [=>............................] - ETA: 1s - loss: 0.2460 - accuracy: 0.9117
     6368/60000 [==>...........................] - ETA: 1s - loss: 0.2443 - accuracy: 0.9117
     8544/60000 [===>..........................] - ETA: 1s - loss: 0.2488 - accuracy: 0.9099
    10688/60000 [====>.........................] - ETA: 1s - loss: 0.2492 - accuracy: 0.9103
    12800/60000 [=====>........................] - ETA: 1s - loss: 0.2468 - accuracy: 0.9109
    14912/60000 [======>.......................] - ETA: 1s - loss: 0.2456 - accuracy: 0.9108
    17056/60000 [=======>......................] - ETA: 1s - loss: 0.2484 - accuracy: 0.9094
    19168/60000 [========>.....................] - ETA: 0s - loss: 0.2495 - accuracy: 0.9079
    21312/60000 [=========>....................] - ETA: 0s - loss: 0.2497 - accuracy: 0.9077
    23360/60000 [==========>...................] - ETA: 0s - loss: 0.2484 - accuracy: 0.9078
    25504/60000 [===========>..................] - ETA: 0s - loss: 0.2512 - accuracy: 0.9071
    27616/60000 [============>.................] - ETA: 0s - loss: 0.2489 - accuracy: 0.9081
    29792/60000 [=============>................] - ETA: 0s - loss: 0.2473 - accuracy: 0.9086
    31840/60000 [==============>...............] - ETA: 0s - loss: 0.2465 - accuracy: 0.9088
    33984/60000 [===============>..............] - ETA: 0s - loss: 0.2463 - accuracy: 0.9089
    36096/60000 [=================>............] - ETA: 0s - loss: 0.2463 - accuracy: 0.9087
    38240/60000 [==================>...........] - ETA: 0s - loss: 0.2452 - accuracy: 0.9089
    40384/60000 [===================>..........] - ETA: 0s - loss: 0.2463 - accuracy: 0.9084
    42368/60000 [====================>.........] - ETA: 0s - loss: 0.2469 - accuracy: 0.9079
    44352/60000 [=====================>........] - ETA: 0s - loss: 0.2465 - accuracy: 0.9076
    46272/60000 [======================>.......] - ETA: 0s - loss: 0.2460 - accuracy: 0.9079
    48192/60000 [=======================>......] - ETA: 0s - loss: 0.2458 - accuracy: 0.9080
    50112/60000 [========================>.....] - ETA: 0s - loss: 0.2470 - accuracy: 0.9073
    52096/60000 [=========================>....] - ETA: 0s - loss: 0.2466 - accuracy: 0.9075
    54112/60000 [==========================>...] - ETA: 0s - loss: 0.2457 - accuracy: 0.9080
    56192/60000 [===========================>..] - ETA: 0s - loss: 0.2457 - accuracy: 0.9081
    58176/60000 [============================>.] - ETA: 0s - loss: 0.2461 - accuracy: 0.9078
    60000/60000 [==============================] - 1s 24us/sample - loss: 0.2463 - accuracy: 0.9077
    Epoch 10/10
    
       32/60000 [..............................] - ETA: 1s - loss: 0.2127 - accuracy: 0.9375
     1984/60000 [..............................] - ETA: 1s - loss: 0.2267 - accuracy: 0.9133
     4032/60000 [=>............................] - ETA: 1s - loss: 0.2326 - accuracy: 0.9110
     6112/60000 [==>...........................] - ETA: 1s - loss: 0.2386 - accuracy: 0.9098
     8160/60000 [===>..........................] - ETA: 1s - loss: 0.2347 - accuracy: 0.9130
    10208/60000 [====>.........................] - ETA: 1s - loss: 0.2380 - accuracy: 0.9103
    12256/60000 [=====>........................] - ETA: 1s - loss: 0.2388 - accuracy: 0.9092
    14304/60000 [======>.......................] - ETA: 1s - loss: 0.2362 - accuracy: 0.9100
    16384/60000 [=======>......................] - ETA: 1s - loss: 0.2358 - accuracy: 0.9104
    18464/60000 [========>.....................] - ETA: 1s - loss: 0.2386 - accuracy: 0.9097
    20544/60000 [=========>....................] - ETA: 0s - loss: 0.2411 - accuracy: 0.9090
    22656/60000 [==========>...................] - ETA: 0s - loss: 0.2418 - accuracy: 0.9092
    24800/60000 [===========>..................] - ETA: 0s - loss: 0.2407 - accuracy: 0.9092
    26816/60000 [============>.................] - ETA: 0s - loss: 0.2398 - accuracy: 0.9094
    28864/60000 [=============>................] - ETA: 0s - loss: 0.2404 - accuracy: 0.9091
    30848/60000 [==============>...............] - ETA: 0s - loss: 0.2400 - accuracy: 0.9093
    32960/60000 [===============>..............] - ETA: 0s - loss: 0.2402 - accuracy: 0.9093
    35072/60000 [================>.............] - ETA: 0s - loss: 0.2394 - accuracy: 0.9097
    37056/60000 [=================>............] - ETA: 0s - loss: 0.2397 - accuracy: 0.9097
    39008/60000 [==================>...........] - ETA: 0s - loss: 0.2393 - accuracy: 0.9099
    41120/60000 [===================>..........] - ETA: 0s - loss: 0.2399 - accuracy: 0.9095
    43200/60000 [====================>.........] - ETA: 0s - loss: 0.2394 - accuracy: 0.9101
    45344/60000 [=====================>........] - ETA: 0s - loss: 0.2391 - accuracy: 0.9104
    47424/60000 [======================>.......] - ETA: 0s - loss: 0.2403 - accuracy: 0.9097
    49536/60000 [=======================>......] - ETA: 0s - loss: 0.2397 - accuracy: 0.9099
    51648/60000 [========================>.....] - ETA: 0s - loss: 0.2405 - accuracy: 0.9096
    53760/60000 [=========================>....] - ETA: 0s - loss: 0.2402 - accuracy: 0.9097
    55840/60000 [==========================>...] - ETA: 0s - loss: 0.2397 - accuracy: 0.9099
    57792/60000 [===========================>..] - ETA: 0s - loss: 0.2394 - accuracy: 0.9099
    59776/60000 [============================>.] - ETA: 0s - loss: 0.2394 - accuracy: 0.9101
    60000/60000 [==============================] - 1s 25us/sample - loss: 0.2394 - accuracy: 0.9101
    
       32/10000 [..............................] - ETA: 12s - loss: 0.2838 - accuracy: 0.8750
     2944/10000 [=======>......................] - ETA: 0s - loss: 0.3345 - accuracy: 0.8815 
     6144/10000 [=================>............] - ETA: 0s - loss: 0.3683 - accuracy: 0.8734
     9248/10000 [==========================>...] - ETA: 0s - loss: 0.3605 - accuracy: 0.8746
    10000/10000 [==============================] - 0s 20us/sample - loss: 0.3568 - accuracy: 0.8757
    0.8757
    Traceback (most recent call last):
      File "F:/vscode-python-kiton/数学/TensorFlow/zijiancpugpu-vs.py", line 63, in <module>
        from sklearn.metrics import accuracy_score
      File "D:\ruanjian\anaconda202002\lib\site-packages\sklearn\__init__.py", line 82, in <module>
        from .base import clone
      File "D:\ruanjian\anaconda202002\lib\site-packages\sklearn\base.py", line 20, in <module>
        from .utils import _IS_32BIT
      File "D:\ruanjian\anaconda202002\lib\site-packages\sklearn\utils\__init__.py", line 27, in <module>
        from .fixes import np_version
      File "D:\ruanjian\anaconda202002\lib\site-packages\sklearn\utils\fixes.py", line 18, in <module>
        import scipy.stats
      File "D:\ruanjian\anaconda202002\lib\site-packages\scipy\stats\__init__.py", line 384, in <module>
        from .stats import *
      File "D:\ruanjian\anaconda202002\lib\site-packages\scipy\stats\stats.py", line 179, in <module>
        from scipy.spatial.distance import cdist
      File "D:\ruanjian\anaconda202002\lib\site-packages\scipy\spatial\__init__.py", line 99, in <module>
        from .qhull import *
    ImportError: DLL load failed: 找不到指定的模块。
    
    Process finished with exit code 1
    

    代码如下:

    #机器学习神经网络
    # here put the import lib
    
    import os
    os.environ['CUDA_VISIBLE_DEVICES'] = '-1' #不用GPU 使用CPU
    
    import tensorflow as tf 
    from tensorflow import keras
    
    import numpy as np 
    import pandas as pd 
    import matplotlib.pyplot as plt
    mnist = keras.datasets.fashion_mnist
    (X_train, y_train),(X_test,y_test) = mnist.load_data()
    
    print("训练数据形状," , X_train.shape)
    print("数据最大值 " , np.max(X_train))
    print("查看标签数值 " , y_train)
    
    class_names =['top','trouser','pullover','dress','coat','sandal','shirt','sneaker','bag','ankle boot']#定义10个类别的名称
    
    plt.figure()#可视化
    plt.imshow(X_train[1])#【】里面的数据可以自己输入随便一个画出第几个的图
    plt.colorbar()#加一个颜色条
    plt.show()
    
    #将数据集归一化 即降低数据集的值
    X_train = X_train/255.0
    X_test = X_test/255.0
    plt.figure()#可视化
    plt.imshow(X_train[1])#【】里面的数据可以自己输入随便一个画出第几个的图
    plt.colorbar()#加一个颜色条
    plt.show()
    
    #可以看出值被缩放到0到1之间
    from tensorflow.python.keras.models import Sequential #导入训练模型
    from tensorflow.python.keras.layers import Flatten,Dense#导入神经网络的第一层和第二层
    
    
    model = Sequential()
    model.add(Flatten(input_shape = (28,28)))#此行代码是将图的大小数据转换成一维的数据
    model.add(Dense(128,activation = 'relu'))#定义第一层神经网络有128个单元,并且选择的激活函数是ReLu函数,也可以是其他函数性sigmoid函数
    # 这里要是不懂可以查看吴恩达老师深度学习的3.6节课
    model.add(Dense(10,activation = 'softmax'))#定义输出层,有10类所以输出10,激活函数是max函数
    
    print("查看自己写的代码的总体参数 " , model.summary())#查看自己写的代码的总体参数
    
    
    #模型补充
    model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])#定义损失函数
    
    #使用的优化器名叫AdamOptimizer,使用的损失函数是稀疏分类交叉熵
    
    
    
    
    model.fit(X_train,y_train,epochs = 10)#进行训练,epochs是显示运行多少次
    
    test_loss, test_acc = model.evaluate(X_test,y_test)#利用测试集测试训练下的模型的准确度
    print(test_acc)
    
    #预测模型精确度
    from sklearn.metrics import accuracy_score
    y_pred = model.predict_classes(X_test)
    
    print(accuracy_score(y_test, y_pred))
    
    #print(tf.test.is_gpu_available())
    
    
    
    

    相关文章

      网友评论

          本文标题:Tensorflow机器学习神经网络学习案例

          本文链接:https://www.haomeiwen.com/subject/yytyxrtx.html