安装Tensorflow和Keras

命令行执行:pip install tensorflow

C:\Users\99>pip install tensorflow
Collecting tensorflow
  Downloading tensorflow-2.4.1-cp38-cp38-win_amd64.whl (370.7 MB)
     |████████████████████████████████| 370.7 MB 89 kB/s
Collecting h5py~=2.10.0
  Downloading h5py-2.10.0-cp38-cp38-win_amd64.whl (2.5 MB)
     |████████████████████████████████| 2.5 MB 2.2 MB/s
Collecting gast==0.3.3
  Downloading gast-0.3.3-py2.py3-none-any.whl (9.7 kB)
Collecting opt-einsum~=3.3.0
  Downloading opt_einsum-3.3.0-py3-none-any.whl (65 kB)
     |████████████████████████████████| 65 kB 4.5 MB/s
Collecting tensorflow-estimator<2.5.0,>=2.4.0
  Downloading tensorflow_estimator-2.4.0-py2.py3-none-any.whl (462 kB)
     |████████████████████████████████| 462 kB 3.2 MB/s
Collecting wheel~=0.35
  Downloading wheel-0.36.2-py2.py3-none-any.whl (35 kB)
Collecting protobuf>=3.9.2
  Downloading protobuf-3.15.4-py2.py3-none-any.whl (173 kB)
     |████████████████████████████████| 173 kB 3.2 MB/s
Requirement already satisfied: wrapt~=1.12.1 in c:\users\99\appdata\roaming\python\python38\site-packages (from tensorflow) (1.12.1)
Collecting flatbuffers~=1.12.0
  Downloading flatbuffers-1.12-py2.py3-none-any.whl (15 kB)
Collecting keras-preprocessing~=1.1.2
  Downloading Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB)
     |████████████████████████████████| 42 kB 3.2 MB/s
Collecting tensorboard~=2.4
  Downloading tensorboard-2.4.1-py3-none-any.whl (10.6 MB)
     |████████████████████████████████| 10.6 MB 652 kB/s
Collecting grpcio~=1.32.0
  Downloading grpcio-1.32.0-cp38-cp38-win_amd64.whl (2.6 MB)
     |████████████████████████████████| 2.6 MB 6.8 MB/s
Collecting absl-py~=0.10
  Downloading absl_py-0.11.0-py3-none-any.whl (127 kB)
     |████████████████████████████████| 127 kB 3.3 MB/s
Collecting typing-extensions~=3.7.4
  Downloading typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
Collecting numpy~=1.19.2
  Downloading numpy-1.19.5-cp38-cp38-win_amd64.whl (13.3 MB)
     |████████████████████████████████| 13.3 MB 504 kB/s
Collecting google-pasta~=0.2
  Downloading google_pasta-0.2.0-py3-none-any.whl (57 kB)
     |████████████████████████████████| 57 kB 1.1 MB/s
Requirement already satisfied: six~=1.15.0 in e:\python\lib\site-packages (from tensorflow) (1.15.0)
Collecting astunparse~=1.6.3
  Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
Collecting termcolor~=1.1.0
  Downloading termcolor-1.1.0.tar.gz (3.9 kB)
Collecting tensorboard-plugin-wit>=1.6.0
  Downloading tensorboard_plugin_wit-1.8.0-py3-none-any.whl (781 kB)
     |████████████████████████████████| 781 kB 726 kB/s
Requirement already satisfied: setuptools>=41.0.0 in e:\python\lib\site-packages (from tensorboard~=2.4->tensorflow) (47.1.0)
Collecting werkzeug>=0.11.15
  Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
     |████████████████████████████████| 298 kB 819 kB/s
Collecting markdown>=2.6.8
  Downloading Markdown-3.3.4-py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 1.1 MB/s
Collecting google-auth<2,>=1.6.3
  Downloading google_auth-1.27.0-py2.py3-none-any.whl (135 kB)
     |████████████████████████████████| 135 kB 819 kB/s
Collecting google-auth-oauthlib<0.5,>=0.4.1
  Downloading google_auth_oauthlib-0.4.2-py2.py3-none-any.whl (18 kB)
Collecting requests<3,>=2.21.0
  Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
     |████████████████████████████████| 61 kB 969 kB/s
Collecting cachetools<5.0,>=2.0.0
  Downloading cachetools-4.2.1-py3-none-any.whl (12 kB)
Collecting rsa<5,>=3.1.4
  Downloading rsa-4.7.2-py3-none-any.whl (34 kB)
Collecting pyasn1-modules>=0.2.1
  Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
     |████████████████████████████████| 155 kB 819 kB/s
Collecting requests-oauthlib>=0.7.0
  Downloading requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB)
Collecting pyasn1<0.5.0,>=0.4.6
  Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
     |████████████████████████████████| 77 kB 589 kB/s
Collecting chardet<5,>=3.0.2
  Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
     |████████████████████████████████| 178 kB 726 kB/s
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.3-py2.py3-none-any.whl (137 kB)
     |████████████████████████████████| 137 kB 819 kB/s
Collecting idna<3,>=2.5
  Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
     |████████████████████████████████| 58 kB 1.3 MB/s
Requirement already satisfied: certifi>=2017.4.17 in e:\python\lib\site-packages (from requests<3,>=2.21.0->tensorboard~=2.4->tensorflow) (2020.6.20)
Collecting oauthlib>=3.0.0
  Downloading oauthlib-3.1.0-py2.py3-none-any.whl (147 kB)
     |████████████████████████████████| 147 kB 273 kB/s
Using legacy 'setup.py install' for termcolor, since package 'wheel' is not installed.
Installing collected packages: urllib3, pyasn1, idna, chardet, rsa, requests, pyasn1-modules, oauthlib, cachetools, requests-oauthlib, google-auth, wheel, werkzeug, tensorboard-plugin-wit, protobuf, numpy, markdown, grpcio, google-auth-oauthlib, absl-py, typing-extensions, termcolor, tensorflow-estimator, tensorboard, opt-einsum, keras-preprocessing, h5py, google-pasta, gast, flatbuffers, astunparse, tensorflow
  Attempting uninstall: numpy
    Found existing installation: numpy 1.19.1
    Uninstalling numpy-1.19.1:
      Successfully uninstalled numpy-1.19.1
    Running setup.py install for termcolor ... done
Successfully installed absl-py-0.11.0 astunparse-1.6.3 cachetools-4.2.1 chardet-4.0.0 flatbuffers-1.12 gast-0.3.3 google-auth-1.27.0 google-auth-oauthlib-0.4.2 google-pasta-0.2.0 grpcio-1.32.0 h5py-2.10.0 idna-2.10 keras-preprocessing-1.1.2 markdown-3.3.4 numpy-1.19.5 oauthlib-3.1.0 opt-einsum-3.3.0 protobuf-3.15.4 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.25.1 requests-oauthlib-1.3.0 rsa-4.7.2 tensorboard-2.4.1 tensorboard-plugin-wit-1.8.0 tensorflow-2.4.1 tensorflow-estimator-2.4.0 termcolor-1.1.0 typing-extensions-3.7.4.3 urllib3-1.26.3 werkzeug-1.0.1 wheel-0.36.2

安装Keras:pip install Keras

C:\Users\99>pip install Keras
Collecting Keras
  Downloading Keras-2.4.3-py2.py3-none-any.whl (36 kB)
Requirement already satisfied: numpy>=1.9.1 in e:\python\lib\site-packages (from Keras) (1.19.5)
Requirement already satisfied: scipy>=0.14 in e:\python\lib\site-packages (from Keras) (1.5.2)
Collecting pyyaml
  Downloading PyYAML-5.4.1-cp38-cp38-win_amd64.whl (213 kB)
     |████████████████████████████████| 213 kB 652 kB/s
Requirement already satisfied: h5py in e:\python\lib\site-packages (from Keras) (2.10.0)
Requirement already satisfied: six in e:\python\lib\site-packages (from h5py->Keras) (1.15.0)
Installing collected packages: pyyaml, Keras
Successfully installed Keras-2.4.3 pyyaml-5.4.1

VSCode运行:

PS F:\Code_vscode> & E:/python/python.exe c:/Users/99/Desktop/AutoEncoders-master/test.py
Traceback (most recent call last):
  File "c:/Users/99/Desktop/AutoEncoders-master/test.py", line 8, in <module>
ModuleNotFoundError: No module named 'keras'
PS F:\Code_vscode> & E:/python/python.exe c:/Users/99/Desktop/AutoEncoders-master/test.py
Traceback (most recent call last):
  File "c:/Users/99/Desktop/AutoEncoders-master/test.py", line 8, in <module>
    import keras
ModuleNotFoundError: No module named 'keras'
PS F:\Code_vscode> & E:/python/python.exe c:/Users/99/Desktop/AutoEncoders-master/test.py
2021-03-04 21:31:01.054012: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-03-04 21:31:01.055886: 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.
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
11493376/11490434 [==============================] - 5s 0us/step
x_train shape: (60000, 28, 28, 1)
60000 train samples
10000 test samples
2021-03-04 21:31:12.210576: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-03-04 21:31:12.211434: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2021-03-04 21:31:12.211808: W tensorflow/stream_executor/cuda/cuda_driver.cc:326] failed call to cuInit: UNKNOWN ERROR (303)
2021-03-04 21:31:12.214765: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: LAPTOP-MBTUAQ1L
2021-03-04 21:31:12.215226: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: LAPTOP-MBTUAQ1L
2021-03-04 21:31:12.216224: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with 
oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-03-04 21:31:12.217548: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
conv2d (Conv2D)              (None, 26, 26, 32)        320
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 24, 24, 64)        18496
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 12, 12, 64)        0
_________________________________________________________________
dropout (Dropout)            (None, 12, 12, 64)        0
_________________________________________________________________
flatten (Flatten)            (None, 9216)              0
_________________________________________________________________
dense (Dense)                (None, 128)               1179776
_________________________________________________________________
dropout_1 (Dropout)          (None, 128)               0
_________________________________________________________________
dense_1 (Dense)              (None, 10)                1290
=================================================================
Total params: 1,199,882
Trainable params: 1,199,882
Non-trainable params: 0
_________________________________________________________________
2021-03-04 21:31:12.393049: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization 
passes are enabled (registered 2)
Epoch 1/12
469/469 [==============================] - 58s 122ms/step - loss: 2.2987 - accuracy: 0.1135 - val_loss: 2.2665 - val_accuracy: 0.3167
Epoch 2/12
469/469 [==============================] - 61s 131ms/step - loss: 2.2633 - accuracy: 0.2174 - val_loss: 2.2234 - val_accuracy: 0.5150
Epoch 3/12
469/469 [==============================] - 59s 126ms/step - loss: 2.2218 - accuracy: 0.3134 - val_loss: 2.1666 - val_accuracy: 0.6315
Epoch 4/12
469/469 [==============================] - 62s 131ms/step - loss: 2.1656 - accuracy: 0.4040 - val_loss: 2.0863 - val_accuracy: 0.7009
Epoch 5/12
469/469 [==============================] - 61s 130ms/step - loss: 2.0836 - accuracy: 0.4774 - val_loss: 1.9724 - val_accuracy: 0.7372
Epoch 6/12
469/469 [==============================] - 60s 127ms/step - loss: 1.9721 - accuracy: 0.5282 - val_loss: 1.8154 - val_accuracy: 0.7586
Epoch 7/12
469/469 [==============================] - 58s 124ms/step - loss: 1.8211 - accuracy: 0.5725 - val_loss: 1.6144 - val_accuracy: 0.7825
Epoch 8/12
469/469 [==============================] - 58s 124ms/step - loss: 1.6397 - accuracy: 0.6064 - val_loss: 1.3915 - val_accuracy: 0.8021
Epoch 9/12
469/469 [==============================] - 58s 124ms/step - loss: 1.4530 - accuracy: 0.6392 - val_loss: 1.1810 - val_accuracy: 0.8156
Epoch 10/12
469/469 [==============================] - 59s 125ms/step - loss: 1.2853 - accuracy: 0.6649 - val_loss: 1.0073 - val_accuracy: 0.8309
Epoch 11/12
469/469 [==============================] - 59s 126ms/step - loss: 1.1447 - accuracy: 0.6891 - val_loss: 0.8735 - val_accuracy: 0.8387
Epoch 12/12
469/469 [==============================] - 58s 125ms/step - loss: 1.0401 - accuracy: 0.7050 - val_loss: 0.7746 - val_accuracy: 0.8477
Test loss: 0.7746074795722961
Test accuracy: 0.8476999998092651
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值