美文网首页编程
Python基础学习15

Python基础学习15

作者: ericblue | 来源:发表于2019-02-14 13:01 被阅读0次

    tensorflow库安装

    ⮀ ~/Python ⮀ pip3 install tensorflow
    Collecting tensorflow
      Downloading https://files.pythonhosted.org/packages/81/07/be624c7e0a63b080a76b7f6faf417eecdc5f6480f6a740a8bcf8991bce0b/tensorflow-1.12.0-cp36-cp36m-macosx_10_11_x86_64.whl (62.0MB)
        100% |████████████████████████████████| 62.0MB 46kB/s
    Collecting grpcio>=1.8.6 (from tensorflow)
      Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)",)': /simple/grpcio/
      Downloading https://files.pythonhosted.org/packages/50/11/e1a1e4912131c783f01734597150a58d75003d89aeff3ebf3d2ee5b4d36a/grpcio-1.18.0-cp36-cp36m-macosx_10_9_x86_64.whl (1.8MB)
        100% |████████████████████████████████| 1.8MB 45kB/s
    Collecting tensorboard<1.13.0,>=1.12.0 (from tensorflow)
      Downloading https://files.pythonhosted.org/packages/07/53/8d32ce9471c18f8d99028b7cef2e5b39ea8765bd7ef250ca05b490880971/tensorboard-1.12.2-py3-none-any.whl (3.0MB)
        100% |████████████████████████████████| 3.1MB 96kB/s
    Collecting termcolor>=1.1.0 (from tensorflow)
      Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
    Collecting keras-preprocessing>=1.0.5 (from tensorflow)
      Downloading https://files.pythonhosted.org/packages/fc/94/74e0fa783d3fc07e41715973435dd051ca89c550881b3454233c39c73e69/Keras_Preprocessing-1.0.5-py2.py3-none-any.whl
    Collecting gast>=0.2.0 (from tensorflow)
      Downloading https://files.pythonhosted.org/packages/4e/35/11749bf99b2d4e3cceb4d55ca22590b0d7c2c62b9de38ac4a4a7f4687421/gast-0.2.2.tar.gz
    Collecting absl-py>=0.1.6 (from tensorflow)
      Downloading https://files.pythonhosted.org/packages/31/bc/ab68120d1d89ae23b694a55fe2aece2f91194313b71f9b05a80b32d3c24b/absl-py-0.7.0.tar.gz (96kB)
        100% |████████████████████████████████| 102kB 73kB/s
    Requirement already satisfied: wheel>=0.26 in /Users/.virtualenvs/py3env/lib/python3.6/site-packages (from tensorflow) (0.31.1)
    Requirement already satisfied: numpy>=1.13.3 in /Users/.virtualenvs/py3env/lib/python3.6/site-packages (from tensorflow) (1.15.4)
    Collecting astor>=0.6.0 (from tensorflow)
      Downloading https://files.pythonhosted.org/packages/35/6b/11530768cac581a12952a2aad00e1526b89d242d0b9f59534ef6e6a1752f/astor-0.7.1-py2.py3-none-any.whl
    Requirement already satisfied: six>=1.10.0 in /Users/.virtualenvs/py3env/lib/python3.6/site-packages (from tensorflow) (1.11.0)
    Collecting keras-applications>=1.0.6 (from tensorflow)
      Downloading https://files.pythonhosted.org/packages/3f/c4/2ff40221029f7098d58f8d7fb99b97e8100f3293f9856f0fb5834bef100b/Keras_Applications-1.0.6-py2.py3-none-any.whl (44kB)
        100% |████████████████████████████████| 51kB 86kB/s
    Collecting protobuf>=3.6.1 (from tensorflow)
      Downloading https://files.pythonhosted.org/packages/c7/27/133f225035b9539f2dcfebcdf9a69ff0152f56e0120160ec5c972ea7deb9/protobuf-3.6.1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (1.2MB)
        100% |████████████████████████████████| 1.2MB 86kB/s
    Collecting markdown>=2.6.8 (from tensorboard<1.13.0,>=1.12.0->tensorflow)
      Downloading https://files.pythonhosted.org/packages/7a/6b/5600647404ba15545ec37d2f7f58844d690baf2f81f3a60b862e48f29287/Markdown-3.0.1-py2.py3-none-any.whl (89kB)
        100% |████████████████████████████████| 92kB 35kB/s
    Collecting werkzeug>=0.11.10 (from tensorboard<1.13.0,>=1.12.0->tensorflow)
      Downloading https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
        100% |████████████████████████████████| 327kB 28kB/s
    Collecting h5py (from keras-applications>=1.0.6->tensorflow)
      Downloading https://files.pythonhosted.org/packages/03/21/1cdf7fa7868528b35c1a08a770eb9334279574a8b5f1d7a2966dcec14e42/h5py-2.9.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (6.3MB)
        100% |████████████████████████████████| 6.3MB 33kB/s
    Requirement already satisfied: setuptools in /Users/.virtualenvs/py3env/lib/python3.6/site-packages (from protobuf>=3.6.1->tensorflow) (40.4.1)
    Building wheels for collected packages: termcolor, gast, absl-py
      Running setup.py bdist_wheel for termcolor ... done
      Stored in directory: /Users/Library/Caches/pip/wheels/7c/06/54/bc84598ba1daf8f970247f550b175aaaee85f68b4b0c5ab2c6
      Running setup.py bdist_wheel for gast ... done
      Stored in directory: /Users/Library/Caches/pip/wheels/5c/2e/7e/a1d4d4fcebe6c381f378ce7743a3ced3699feb89bcfbdadadd
      Running setup.py bdist_wheel for absl-py ... done
      Stored in directory: /Users/Library/Caches/pip/wheels/90/db/f8/2c3101f72ef1ad434e4662853174126ce30201a3e163dcbeca
    Successfully built termcolor gast absl-py
    Installing collected packages: grpcio, markdown, protobuf, werkzeug, tensorboard, termcolor, keras-preprocessing, gast, absl-py, astor, h5py, keras-applications, tensorflow
    Successfully installed absl-py-0.7.0 astor-0.7.1 gast-0.2.2 grpcio-1.18.0 h5py-2.9.0 keras-applications-1.0.6 keras-preprocessing-1.0.5 markdown-3.0.1 protobuf-3.6.1 tensorboard-1.12.2 tensorflow-1.12.0 termcolor-1.1.0 werkzeug-0.14.1
    

    鸢尾花样例下载

    Snip20190204_2.png
    在如下路径找到premade_estimator.py启动运行
    /PycharmProjects⮀ cd models-master/samples/core/get_started
    (py3env)   ⮀  ll
    -rwxr-xr-x@ 1 insight2026  staff   2.5K  2  2 16:38 _index.ipynb
    -rwxr-xr-x@ 1 insight2026  staff   4.7K  2  2 16:38 custom_estimator.py
    -rwxr-xr-x@ 1 insight2026  staff   2.6K  2  2 16:38 eager.ipynb
    -rwxr-xr-x@ 1 insight2026  staff   1.8K  2  2 16:38 estimator_test.py
    -rwxr-xr-x@ 1 insight2026  staff   2.8K  2  2 16:38 iris_data.py
    -rwxr-xr-x@ 1 insight2026  staff   3.1K  2  2 16:38 premade_estimator.py
    
     ~/PycharmProjects/models-master/samples/core/get_started ⮀ python3 premade_estimator.py
    Downloading data from http://download.tensorflow.org/data/iris_training.csv
    8192/2194 [================================================================================================================] - 0s 0us/step
    Downloading data from http://download.tensorflow.org/data/iris_test.csv
    8192/573 [============================================================================================================================================================================================================================================================================================================================================================================================================================================] - 0s 0us/step
    INFO:tensorflow:Using default config.
    WARNING:tensorflow:Using temporary folder as model directory: /var/folders/d9/4msh_3yj16g_tq9q0kb5t0yw0000gn/T/tmpumzl2rp9
    INFO:tensorflow:Using config: {'_model_dir': '/var/folders/d9/4msh_3yj16g_tq9q0kb5t0yw0000gn/T/tmpumzl2rp9', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': allow_soft_placement: true
    graph_options {
      rewrite_options {
        meta_optimizer_iterations: ONE
      }
    }
    , '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x123d8b4e0>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}
    INFO:tensorflow:Calling model_fn.
    INFO:tensorflow:Done calling model_fn.
    INFO:tensorflow:Create CheckpointSaverHook.
    INFO:tensorflow:Graph was finalized.
    2019-02-04 13:16:46.177230: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
    INFO:tensorflow:Running local_init_op.
    INFO:tensorflow:Done running local_init_op.
    INFO:tensorflow:Saving checkpoints for 0 into /var/folders/d9/4msh_3yj16g_tq9q0kb5t0yw0000gn/T/tmpumzl2rp9/model.ckpt.
    INFO:tensorflow:loss = 112.282875, step = 1
    INFO:tensorflow:global_step/sec: 452.427
    INFO:tensorflow:loss = 10.784231, step = 101 (0.220 sec)
    INFO:tensorflow:global_step/sec: 654.523
    INFO:tensorflow:loss = 7.279642, step = 201 (0.153 sec)
    INFO:tensorflow:global_step/sec: 661.9
    INFO:tensorflow:loss = 5.410771, step = 301 (0.151 sec)
    INFO:tensorflow:global_step/sec: 661.63
    INFO:tensorflow:loss = 8.72373, step = 401 (0.151 sec)
    INFO:tensorflow:global_step/sec: 660.917
    INFO:tensorflow:loss = 7.6892686, step = 501 (0.151 sec)
    INFO:tensorflow:global_step/sec: 658.336
    INFO:tensorflow:loss = 6.3910046, step = 601 (0.152 sec)
    INFO:tensorflow:global_step/sec: 652.481
    INFO:tensorflow:loss = 6.1809897, step = 701 (0.153 sec)
    INFO:tensorflow:global_step/sec: 655.184
    INFO:tensorflow:loss = 3.2532542, step = 801 (0.153 sec)
    INFO:tensorflow:global_step/sec: 657.479
    INFO:tensorflow:loss = 3.6389048, step = 901 (0.152 sec)
    INFO:tensorflow:Saving checkpoints for 1000 into /var/folders/d9/4msh_3yj16g_tq9q0kb5t0yw0000gn/T/tmpumzl2rp9/model.ckpt.
    INFO:tensorflow:Loss for final step: 4.421207.
    INFO:tensorflow:Calling model_fn.
    INFO:tensorflow:Done calling model_fn.
    INFO:tensorflow:Starting evaluation at 2019-02-04-05:16:48
    INFO:tensorflow:Graph was finalized.
    INFO:tensorflow:Restoring parameters from /var/folders/d9/4msh_3yj16g_tq9q0kb5t0yw0000gn/T/tmpumzl2rp9/model.ckpt-1000
    INFO:tensorflow:Running local_init_op.
    INFO:tensorflow:Done running local_init_op.
    INFO:tensorflow:Finished evaluation at 2019-02-04-05:16:49
    INFO:tensorflow:Saving dict for global step 1000: accuracy = 0.93333334, average_loss = 0.05496562, global_step = 1000, loss = 1.6489686
    INFO:tensorflow:Saving 'checkpoint_path' summary for global step 1000: /var/folders/d9/4msh_3yj16g_tq9q0kb5t0yw0000gn/T/tmpumzl2rp9/model.ckpt-1000
    
    Test set accuracy: 0.933
    
    INFO:tensorflow:Calling model_fn.
    INFO:tensorflow:Done calling model_fn.
    INFO:tensorflow:Graph was finalized.
    INFO:tensorflow:Restoring parameters from /var/folders/d9/4msh_3yj16g_tq9q0kb5t0yw0000gn/T/tmpumzl2rp9/model.ckpt-1000
    INFO:tensorflow:Running local_init_op.
    INFO:tensorflow:Done running local_init_op.
    
    Prediction is "Setosa" (99.7%), expected "Setosa"
    
    Prediction is "Versicolor" (99.6%), expected "Versicolor"
    
    Prediction is "Virginica" (98.2%), expected "Virginica"
    
    

    相关文章

      网友评论

        本文标题:Python基础学习15

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