tensorflow学习笔记

人工智能的浪潮重新洗脑华厦大地,热度只增不减,开始
https://www.tensorflow.org/

一 安装
1.虚拟环境安装

virtualenv --system-site-packages -p python3 tensorflow
cd tensorflow/
source bin/activate
pip3 install --upgrade https://download.tensorflow.google.cn/mac/cpu/tensorflow-1.8.0-py3-none-any.whl

python3.7环境下启动 tensorboard 会出现python保留字async问题,打开出问题的文件把async替换下就 Ok了

tensorboard --logdir=/data/python/tensorflow/logs
Traceback (most recent call last):
  File "/data/python/tensorflow/bin/tensorboard", line 7, in 
    from tensorboard.main import run_main
  File "/data/python/tensorflow/lib/python3.7/site-packages/tensorboard/main.py", line 28, in 
    import tensorflow as tf
  File "/data/python/tensorflow/lib/python3.7/site-packages/tensorflow/__init__.py", line 24, in 
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/data/python/tensorflow/lib/python3.7/site-packages/tensorflow/python/__init__.py", line 49, in 
    from tensorflow.python import pywrap_tensorflow
  File "/data/python/tensorflow/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in 
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/data/python/tensorflow/lib/python3.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 114
    def TFE_ContextOptionsSetAsync(arg1, async):
                                             ^
SyntaxError: invalid syntax

2. 运行hello world会出现如下问题:

(tf) hulupiao:tf hanjiafeng$ python
Python 2.7.10 (default, Feb  6 2017, 23:53:20)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42

虽然是warning级别的,这两年没了手动编译症,但强迫症发作,查了下可以强制不警告此问题

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
#....其它代码段

有点类似php的运行级别设置,说明如下:
TF_CPP_MIN_LOG_LEVEL is a TensorFlow environment variable responsible for the logs, to silence INFO logs set it to 1, to filter out WARNING 2 and to additionally silence ERROR logs (not recommended) set it to 3

发帖时间: AI 归档位置:

发表评论

电子邮件地址不会被公开。 必填项已用*标注