入坑tensorflow
Posted tszs_song
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了入坑tensorflow相关的知识,希望对你有一定的参考价值。
win10 CPU版,anaconda prompt命令行一句话,pip install --upgrade tensorflow搞定。比caffe好装一万倍。
gpu版没装成,首先这个笔记本没装cuda,另外一个台式装好了cuda8.0和cunn5.1也是报一样的错误,缺少一个setuptool.egg
命令行如下:
1 (D:\Users\song\Anaconda3) C:\SPB_Data>python --version 2 Python 3.6.0 :: Anaconda 4.3.1 (64-bit) 3 4 (D:\Users\song\Anaconda3) C:\SPB_Data>pip -V 5 pip 9.0.1 from D:\Users\song\Anaconda3\lib\site-packages (python 3.6) 6 7 (D:\Users\song\Anaconda3) C:\SPB_Data>pip3 install --upgrade tensorflow-gpu 8 ‘pip3‘ 不是内部或外部命令,也不是可运行的程序 9 或批处理文件。 10 11 (D:\Users\song\Anaconda3) C:\SPB_Data>pip install --upgrade tensorflow-gpu 12 Collecting tensorflow-gpu 13 Downloading tensorflow_gpu-1.3.0-cp36-cp36m-win_amd64.whl (60.0MB) 14 100% |████████████████████████████████| 60.0MB 16kB/s 15 Collecting numpy>=1.11.0 (from tensorflow-gpu) 16 Downloading numpy-1.13.3-cp36-none-win_amd64.whl (13.1MB) 17 100% |████████████████████████████████| 13.1MB 73kB/s 18 Collecting protobuf>=3.3.0 (from tensorflow-gpu) 19 Downloading protobuf-3.4.0-py2.py3-none-any.whl (375kB) 20 100% |████████████████████████████████| 378kB 667kB/s 21 Collecting wheel>=0.26 (from tensorflow-gpu) 22 Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB) 23 100% |████████████████████████████████| 51kB 371kB/s 24 Collecting tensorflow-tensorboard<0.2.0,>=0.1.0 (from tensorflow-gpu) 25 Downloading tensorflow_tensorboard-0.1.8-py3-none-any.whl (1.6MB) 26 100% |████████████████████████████████| 1.6MB 413kB/s 27 Collecting six>=1.10.0 (from tensorflow-gpu) 28 Downloading six-1.11.0-py2.py3-none-any.whl 29 Collecting setuptools (from protobuf>=3.3.0->tensorflow-gpu) 30 Downloading setuptools-36.6.0-py2.py3-none-any.whl (481kB) 31 100% |████████████████████████████████| 481kB 734kB/s 32 Collecting bleach==1.5.0 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu) 33 Downloading bleach-1.5.0-py2.py3-none-any.whl 34 Collecting werkzeug>=0.11.10 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu) 35 Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB) 36 100% |████████████████████████████████| 317kB 1.7MB/s 37 Collecting html5lib==0.9999999 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu) 38 Downloading html5lib-0.9999999.tar.gz (889kB) 39 100% |████████████████████████████████| 890kB 502kB/s 40 Collecting markdown>=2.6.8 (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow-gpu) 41 Downloading Markdown-2.6.9.tar.gz (271kB) 42 100% |████████████████████████████████| 276kB 687kB/s 43 Building wheels for collected packages: html5lib, markdown 44 Running setup.py bdist_wheel for html5lib ... done 45 Stored in directory: C:\Users\song\AppData\Local\pip\Cache\wheels\6f\85\6c\56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962 46 Running setup.py bdist_wheel for markdown ... done 47 Stored in directory: C:\Users\song\AppData\Local\pip\Cache\wheels\bf\46\10\c93e17ae86ae3b3a919c7b39dad3b5ccf09aeb066419e5c1e5 48 Successfully built html5lib markdown 49 Installing collected packages: numpy, setuptools, six, protobuf, wheel, html5lib, bleach, werkzeug, markdown, tensorflow-tensorboard, tensorflow-gpu 50 Found existing installation: numpy 1.11.3 51 Uninstalling numpy-1.11.3: 52 Successfully uninstalled numpy-1.11.3 53 Found existing installation: setuptools 27.2.0 54 Uninstalling setuptools-27.2.0: 55 Successfully uninstalled setuptools-27.2.0 56 Found existing installation: six 1.10.0 57 DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project. 58 Uninstalling six-1.10.0: 59 Successfully uninstalled six-1.10.0 60 Found existing installation: wheel 0.29.0 61 Uninstalling wheel-0.29.0: 62 Successfully uninstalled wheel-0.29.0 63 Found existing installation: Werkzeug 0.11.15 64 Uninstalling Werkzeug-0.11.15: 65 Successfully uninstalled Werkzeug-0.11.15 66 Successfully installed bleach-1.5.0 html5lib-0.9999999 markdown-2.6.9 numpy-1.13.3 protobuf-3.4.0 setuptools-36.6.0 six-1.11.0 tensorflow-gpu-1.3.0 tensorflow-tensorboard-0.1.8 werkzeug-0.12.2 wheel-0.30.0 67 Traceback (most recent call last): 68 File "D:\Users\song\Anaconda3\Scripts\pip-script.py", line 5, in <module> 69 sys.exit(pip.main()) 70 File "D:\Users\song\Anaconda3\lib\site-packages\pip\__init__.py", line 249, in main 71 return command.main(cmd_args) 72 File "D:\Users\song\Anaconda3\lib\site-packages\pip\basecommand.py", line 252, in main 73 pip_version_check(session) 74 File "D:\Users\song\Anaconda3\lib\site-packages\pip\utils\outdated.py", line 102, in pip_version_check 75 installed_version = get_installed_version("pip") 76 File "D:\Users\song\Anaconda3\lib\site-packages\pip\utils\__init__.py", line 838, in get_installed_version 77 working_set = pkg_resources.WorkingSet() 78 File "D:\Users\song\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 644, in __init__ 79 self.add_entry(entry) 80 File "D:\Users\song\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 700, in add_entry 81 for dist in find_distributions(entry, True): 82 File "D:\Users\song\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 1949, in find_eggs_in_zip 83 if metadata.has_metadata(‘PKG-INFO‘): 84 File "D:\Users\song\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 1463, in has_metadata 85 return self.egg_info and self._has(self._fn(self.egg_info, name)) 86 File "D:\Users\song\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 1823, in _has 87 return zip_path in self.zipinfo or zip_path in self._index() 88 File "D:\Users\song\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 1703, in zipinfo 89 return self._zip_manifests.load(self.loader.archive) 90 File "D:\Users\song\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 1643, in load 91 mtime = os.stat(path).st_mtime 92 FileNotFoundError: [WinError 2] 系统找不到指定的文件。: ‘D:\\Users\\song\\Anaconda3\\lib\\site-packages\\setuptools-27.2.0-py3.6.egg‘ 93 94 (D:\Users\song\Anaconda3) C:\SPB_Data>cd .. 95 96 (D:\Users\song\Anaconda3) C:\>cd .. 97 98 (D:\Users\song\Anaconda3) C:\>ls 99 ‘ls‘ 不是内部或外部命令,也不是可运行的程序 100 或批处理文件。 101 102 (D:\Users\song\Anaconda3) C:\>python --version 103 Python 3.6.0 :: Anaconda 4.3.1 (64-bit) 104 105 (D:\Users\song\Anaconda3) C:\>nvcc -V 106 ‘nvcc‘ 不是内部或外部命令,也不是可运行的程序 107 或批处理文件。 108 109 (D:\Users\song\Anaconda3) C:\>pip install --upgrade tensorflow 110 Collecting tensorflow 111 Downloading tensorflow-1.3.0-cp36-cp36m-win_amd64.whl (25.5MB) 112 100% |████████████████████████████████| 25.5MB 29kB/s 113 Requirement already up-to-date: protobuf>=3.3.0 in d:\users\song\anaconda3\lib\site-packages (from tensorflow) 114 Requirement already up-to-date: wheel>=0.26 in d:\users\song\anaconda3\lib\site-packages (from tensorflow) 115 Requirement already up-to-date: tensorflow-tensorboard<0.2.0,>=0.1.0 in d:\users\song\anaconda3\lib\site-packages (from tensorflow) 116 Requirement already up-to-date: six>=1.10.0 in d:\users\song\anaconda3\lib\site-packages (from tensorflow) 117 Requirement already up-to-date: numpy>=1.11.0 in d:\users\song\anaconda3\lib\site-packages (from tensorflow) 118 Requirement already up-to-date: setuptools in d:\users\song\anaconda3\lib\site-packages (from protobuf>=3.3.0->tensorflow) 119 Requirement already up-to-date: markdown>=2.6.8 in d:\users\song\anaconda3\lib\site-packages (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow) 120 Requirement already up-to-date: bleach==1.5.0 in d:\users\song\anaconda3\lib\site-packages (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow) 121 Requirement already up-to-date: html5lib==0.9999999 in d:\users\song\anaconda3\lib\site-packages (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow) 122 Requirement already up-to-date: werkzeug>=0.11.10 in d:\users\song\anaconda3\lib\site-packages (from tensorflow-tensorboard<0.2.0,>=0.1.0->tensorflow) 123 Installing collected packages: tensorflow 124 Successfully installed tensorflow-1.3.0 125 126 (D:\Users\song\Anaconda3) C:\>import tensorflow as tf 127 ‘import‘ 不是内部或外部命令,也不是可运行的程序 128 或批处理文件。 129 130 (D:\Users\song\Anaconda3) C:\>python 131 Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32 132 Type "help", "copyright", "credits" or "license" for more information. 133 >>> import tensorflow as tf 134 >>> a = tf.random_normal((100,100)) 135 >>> b = tf.random_normal((100,500)) 136 >>> c=tf.matmul(a,b) 137 >>> sess=tf.InteractiveSession() 138 2017-10-29 20:46:03.615036: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\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. 139 2017-10-29 20:46:03.620666: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\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. 140 >>> sess.run(c) 141 array([[ -2.01546478e+01, -1.21840429e+01, 8.52634966e-01, ..., 142 -1.93460350e+01, -1.17136412e+01, -2.81856956e+01], 143 [ -2.86180496e+00, 1.86777287e+01, 2.39728212e-01, ..., 144 1.65606441e+01, -8.35585117e+00, 1.21092701e+01], 145 [ -6.70668936e+00, -1.92020512e+00, -8.63678837e+00, ..., 146 1.19851971e+01, -1.95774388e+00, -3.46706104e+00], 147 ..., 148 [ -6.20419502e+00, -1.58898029e+01, 1.47155542e+01, ..., 149 -6.35781908e+00, -7.09256840e+00, 1.04180880e+01], 150 [ -1.14867371e-03, -2.47349381e+00, 1.40450490e+00, ..., 151 1.87805653e+00, 7.70393276e+00, -1.11452806e+00], 152 [ -1.81114292e+01, 2.83652916e+01, 2.23067703e+01, ..., 153 4.72095060e+00, 2.01743245e+00, 9.46466255e+00]], dtype=float32) 154 >>> c 155 <tf.Tensor ‘MatMul:0‘ shape=(100, 500) dtype=float32> 156 >>> print(c) 157 Tensor("MatMul:0", shape=(100, 500), dtype=float32) 158 >>> print(c.val) 159 Traceback (most recent call last): 160 File "<stdin>", line 1, in <module> 161 AttributeError: ‘Tensor‘ object has no attribute ‘val‘ 162 >>> print(c.eval()) 163 [[ 7.44645548e+00 7.01777339e-01 -3.29522681e+00 ..., -4.11035490e+00 164 6.88585615e+00 -1.03243275e+01] 165 [ 1.74935007e+00 -8.06512642e+00 -8.94767094e+00 ..., -8.51691341e+00 166 -6.86603403e+00 9.46757889e+00] 167 [ -6.61030436e+00 5.86357307e+00 1.51259956e+01 ..., -9.53737926e+00 168 1.95381641e-02 1.16717541e+00] 169 ..., 170 [ -5.34449625e+00 1.13798809e+00 1.34737101e+01 ..., 6.86746025e+00 171 3.37234330e+00 -9.16017354e-01] 172 [ -3.89829564e+00 1.19947767e+00 9.16424465e+00 ..., 7.61591375e-01 173 -1.70225441e-01 1.02892227e+01] 174 [ 1.97680518e-01 -1.99925423e+01 -9.40755844e+00 ..., 5.44214249e+00 175 1.52138865e+00 2.48984170e+00]] 176 >>> print(a) 177 Tensor("random_normal:0", shape=(100, 100), dtype=float32) 178 >>> sess=tf.InteractiveSession() 179 >>> print(sess.run(a)) 180 [[-1.394485 -1.95048952 0.76553309 ..., -0.43924141 -1.21975422 181 0.60572529] 182 [ 0.34292024 0.86016667 -2.25437665 ..., 1.67957187 1.57846153 183 -1.53106809] 184 [ 0.08453497 0.59995687 -1.37805259 ..., -0.92989731 -0.07856822 185 -1.36062932] 186 ..., 187 [-0.41187105 0.60689414 -0.44695681 ..., 0.51408201 -1.49676847 188 0.95741159] 189 [-1.01903558 -1.24220276 0.12283699 ..., 0.53144586 -0.2782338 190 0.34964591] 191 [ 0.27783027 0.5017578 -1.0619179 ..., 0.4974283 -0.04771407 192 0.48028085]] 193 >>> ls 194 Traceback (most recent call last): 195 File "<stdin>", line 1, in <module> 196 NameError: name ‘ls‘ is not defined 197 >>> exit() 198 199 (D:\Users\song\Anaconda3) C:\>e:200 ‘e:\‘ 不是内部或外部命令,也不是可运行的程序 201 或批处理文件。 202 203 (D:\Users\song\Anaconda3) C:\>cd e:204 205 (D:\Users\song\Anaconda3) C:\>python minst.py 206 File "minst.py", line 16 207 SyntaxError: Non-UTF-8 code starting with ‘\xb0‘ in file minst.py on line 16, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 208 209 (D:\Users\song\Anaconda3) C:\>python minst.py 210 File "minst.py", line 16 211 SyntaxError: Non-UTF-8 code starting with ‘\xb0‘ in file minst.py on line 16, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 212 213 (D:\Users\song\Anaconda3) C:\>python minst.py 214 File "minst.py", line 16 215 SyntaxError: Non-UTF-8 code starting with ‘\xb0‘ in file minst.py on line 16, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 216 217 (D:\Users\song\Anaconda3) C:\>python 218 Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32 219 Type "help", "copyright", "credits" or "license" for more information. 220 >>> import tensorflow as tf 221 >>> flags = tf.app.flags 222 >>> FLAGS = flags.FLAGS 223 >>> flags.DEFINE_string(‘data_dir‘, ‘/tmp/data/‘, ‘Directory for storing data‘) 224 >>> 225 >>> mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True) 226 Traceback (most recent call last): 227 File "<stdin>", line 1, in <module> 228 NameError: name ‘input_data‘ is not defined 229 >>> from __future__ import absolute_import 230 >>> from __future__ import division 231 >>> from __future__ import print_function 232 >>> from tensorflow.examples.tutorials.mnist import input_data 233 >>> 234 >>> mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True) 235 Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes. 236 Extracting /tmp/data/train-images-idx3-ubyte.gz 237 Traceback (most recent call last): 238 File "D:\Users\song\Anaconda3\lib\urllib\request.py", line 1318, in do_open 239 encode_chunked=req.has_header(‘Transfer-encoding‘)) 240 File "D:\Users\song\Anaconda3\lib\http\client.py", line 1239, in request 241 self._send_request(method, url, body, headers, encode_chunked) 242 File "D:\Users\song\Anaconda3\lib\http\client.py", line 1285, in _send_request 243 self.endheaders(body, encode_chunked=encode_chunked) 244 File "D:\Users\song\Anaconda3\lib\http\client.py", line 1234, in endheaders 245 self._send_output(message_body, encode_chunked=encode_chunked) 246 File "D:\Users\song\Anaconda3\lib\http\client.py", line 1026, in _send_output 247 self.send(msg) 248 File "D:\Users\song\Anaconda3\lib\http\client.py", line 964, in send 249 self.connect() 250 File "D:\Users\song\Anaconda3\lib\http\client.py", line 1400, in connect 251 server_hostname=server_hostname) 252 File "D:\Users\song\Anaconda3\lib\ssl.py", line 401, in wrap_socket 253 _context=self, _session=session) 254 File "D:\Users\song\Anaconda3\lib\ssl.py", line 808, in __init__ 255 self.do_handshake() 256 File "D:\Users\song\Anaconda3\lib\ssl.py", line 1061, in do_handshake 257 self._sslobj.do_handshake() 258 File "D:\Users\song\Anaconda3\lib\ssl.py", line 683, in do_handshake 259 self._sslobj.do_handshake() 260 ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:749) 261 262 During handling of the above exception, another exception occurred: 263 264 Traceback (most recent call last): 265 File "<stdin>", line 1, in <module> 266 File "D:\Users\song\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\mnist.py", line 240, in read_data_sets 267 SOURCE_URL + TRAIN_LABELS) 268 File "D:\Users\song\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\base.py", line 208, in maybe_download 269 temp_file_name, _ = urlretrieve_with_retry(source_url) 270 File "D:\Users\song\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\base.py", line 165, in wrapped_fn 271 return fn(*args, **kwargs) 272 File "D:\Users\song\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\base.py", line 190, in urlretrieve_with_retry 273 return urllib.request.urlretrieve(url, filename) 274 File "D:\Users\song\Anaconda3\lib\urllib\request.py", line 248, in urlretrieve 275 with contextlib.closing(urlopen(url, data)) as fp: 276 File "D:\Users\song\Anaconda3\lib\urllib\request.py", line 223, in urlopen 277 return opener.open(url, data, timeout) 278 File "D:\Users\song\Anaconda3\lib\urllib\request.py", line 526, in open 279 response = self._open(req, data) 280 File "D:\Users\song\Anaconda3\lib\urllib\request.py", line 544, in _open 281 ‘_open‘, req) 282 File "D:\Users\song\Anaconda3\lib\urllib\request.py", line 504, in _call_chain 283 result = func(*args) 284 File "D:\Users\song\Anaconda3\lib\urllib\request.py", line 1361, in https_open 285 context=self._context, check_hostname=self._check_hostname) 286 File "D:\Users\song\Anaconda3\lib\urllib\request.py", line 1320, in do_open 287 raise URLError(err) 288 urllib.error.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:749)> 289 >>> import requests 290 >>> >>> from requests.adapters import HTTPAdapter 291 File "<stdin>", line 1 292 >>> from requests.adapters import HTTPAdapter 293 ^ 294 SyntaxError: invalid syntax 295 >>> >>> from requests.packages.urllib3.poolmanager import PoolManager 296 File "<stdin>", line 1 297 >>> from requests.packages.urllib3.poolmanager import PoolManager 298 ^ 299 SyntaxError: invalid syntax 300 >>> >>> import ssl 301 File "<stdin>", line 1 302 >>> import ssl 303 ^ 304 SyntaxError: invalid syntax 305 >>> >>> 306 File "<stdin>", line 1 307 >>> 308 ^ 309 SyntaxError: invalid syntax 310 >>> >>> class MyAdapter(HTTPAdapter): 311 File "<stdin>", line 1 312 >>> class MyAdapter(HTTPAdapter): 313 ^ 314 SyntaxError: invalid syntax 315 >>> ... def init_poolmanager(self, connections, maxsize, block=False): 316 File "<stdin>", line 1 317 ... def init_poolmanager(self, connections, maxsize, block=False): 318 ^ 319 SyntaxError: invalid syntax 320 >>> ... self.poolmanager = PoolManager(num_pools=connections, 321 File "<stdin>", line 1 322 ... self.poolmanager = PoolManager(num_pools=connections, 323 ^ 324 SyntaxError: invalid syntax 325 >>> ... maxsize=maxsize, 326 File "<stdin>", line 1 327 ... maxsize=maxsize, 328 ^ 329 SyntaxError: invalid syntax 330 >>> ... block=block, 331 File "<stdin>", line 1 332 ... block=block, 333 ^ 334 SyntaxError: invalid syntax 335 >>> ... ssl_version=ssl.PROTOCOL_TLSv1) 336 File "<stdin>", line 1 337 ... ssl_version=ssl.PROTOCOL_TLSv1) 338 ^ 339 SyntaxError: invalid syntax 340 >>> ... 341 Ellipsis 342 >>> >>> s = requests.Session() 343 File "<stdin>", line 1 344 >>> s = requests.Session() 345 ^ 346 SyntaxError: invalid syntax 347 >>> >>> s.mount(‘https://‘, MyAdapter()) 348 File "<stdin>", line 1 349 >>> s.mount(‘https://‘, MyAdapter()) 350 ^ 351 SyntaxError: invalid syntax 352 >>> >>> s.get(‘https://www.supercash.cz‘) 353 File "<stdin>", line 1 354 >>> s.get(‘https://www.supercash.cz‘) 355 ^ 356 SyntaxError: invalid syntax 357 >>> <Response [200]> 358 File "<stdin>", line 1 359 <Response [200]> 360 ^ 361 SyntaxError: invalid syntax 362 >>> mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True) 363 Extracting /tmp/data/train-images-idx3-ubyte.gz 364 Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes. 365 Extracting /tmp/data/train-labels-idx1-ubyte.gz 366 Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes. 367 Extracting /tmp/data/t10k-images-idx3-ubyte.gz 368 Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes. 369 Extracting /tmp/data/t10k-labels-idx1-ubyte.gz 370 >>> x = tf.placeholder(tf.float32, [None, 784]) # 占位符 371 >>> y = tf.placeholder(tf.float32, [None, 10]) 372 >>> W = tf.Variable(tf.zeros([784, 10])) 373 >>> b = tf.Variable(tf.zeros([10])) 374 >>> a = tf.nn.softmax(tf.matmul(x, W) + b) 375 >>> cross_entropy = tf.reduce_mean(-tf.reduce_sum(y * tf.log(a), reduction_indices=[1])) # 损失函数为交叉熵 376 >>> optimizer = tf.train.GradientDescentOptimizer(0.5) # 梯度下降法,学习速率为0.5 377 >>> train = optimizer.minimize(cross_entropy) # 训练目标:最小化损失函数 378 >>> 379 >>> # Test trained model 380 ... correct_prediction = tf.equal(tf.argmax(a, 1), tf.argmax(y, 1)) 381 >>> accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 382 >>> correct_prediction = tf.equal(tf.argmax(a, 1), tf.argmax(y, 1)) 383 >>> accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 384 >>> sess = tf.InteractiveSession() # 建立交互式会话 385 2017-10-29 21:28:03.960497: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\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. 386 2017-10-29 21:28:03.968465: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\36\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. 387 >>> tf.initialize_all_variables().run() 388 WARNING:tensorflow:From D:\Users\song\Anaconda3\lib\site-packages\tensorflow\python\util\tf_should_use.py:175: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02. 389 Instructions for updating: 390 Use `tf.global_variables_initializer` instead. 391 >>> for i in range(1000): 392 ... batch_xs, batch_ys = mnist.train.next_batch(100) 393 ... train.run({x: batch_xs, y: batch_ys}) 394 ... print(sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels})) 395 File "<stdin>", line 4 396 print(sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels})) 397 ^ 398 SyntaxError: invalid syntax 399 >>> tf.initialize_all_variables().run() 400 WARNING:tensorflow:From D:\Users\song\Anaconda3\lib\site-packages\tensorflow\python\util\tf_should_use.py:175: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02. 401 Instructions for updating: 402 Use `tf.global_variables_initializer` instead. 403 >>> tf.global_variables_initializer().run() 404 >>> for i in range(1000): 405 ... batch_xs, batch_ys = mnist.train.next_batch(100) 406 ... train.run({x: batch_xs, y: batch_ys}) 407 ... 408 >>> print(sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels})) 409 0.9154 410 >>>
以上是关于入坑tensorflow的主要内容,如果未能解决你的问题,请参考以下文章