發表文章

tensorflow-Windows下使用tensorboard

圖片
最近在學習Tensorflow中的tensoboard的視覺化,但是怎麼都無法實現,按照教程,在Windows下會無法顯示網頁,教程中是在Linux中實現的,檔路徑與Windows不一樣,下面我以官方給出教程為例,指出在Window下要修改的地方: from __future__ import absolute_import from __future__ import division from __future__ import print_function import argparse import sys import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data FLAGS = None def train():   # Import data   mnist = input_data.read_data_sets(FLAGS.data_dir,                                     one_hot=True,                                     fake_data=FLAGS.fake_data)   sess = tf.InteractiveSession()   # Create a multilayer model.   # Input placeholders   with tf.name_scope('input'):     x = tf.placeholder(tf.float32, [None, 784], name='x-input')     y_ = tf...

tensorflow-TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'問題解決

延續上一篇"Python 3.x中使用print函數出現語法錯誤(SyntaxError: invalid syntax)的原因" 當 print 增加 () 後仍然出現錯誤 After %s iteration(s): x%s is %f. Traceback (most recent call last):   File "test9.py", line 14, in <module>     print ('After %s iteration(s): x%s is %f.') % (i+1, i+1, x_value) TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple' 解決方式 在印出的外層再加上() print ( ("After %s iteration(s): x%s is %f.") % (i+1, i+1, x_value) )

tensorflow-Python 3.x中使用print函數出現語法錯誤(SyntaxError: invalid syntax)的原因

  File "test9.py", line 14     print 'After %s iteration(s): x%s is %f.' % (i+1, i+1, x_value)                                                                  ^ SyntaxError: invalid syntax Python 2.x: print 「所要列印的內容」 , 不帶括號 Python 3.x: print函數(」所要列印的內容」),必須帶括號

tensorflow-解決AttributeError: module 'tensorflow' has no attribute 'mul'問題

原因:TensorFlow 發布的新版本的API 修改了 tf.mul, tf.sub and tf.neg are deprecated in favor of tf.multiply, tf.subtract and tf.negative. 解決方法:使用時將  tf.mul改成  tf.multiply即可 其餘的  tf.sub和tf.neg也要相應修改為  tf.subtract和tf.negative。

tensorflow-解决SyntaxError: invalid syntax

  File "test9.py", line 10     print sess.run(y, feed_dict={a: 3, b: 3})              ^ SyntaxError: invalid syntax 這個報錯是因為python3中print變成了一個方法,需要帶括號當參數傳入值。 print(sess.run(y, feed_dict={a: 3, b: 3})) 即可解決!

tensorfloow-placeholder用法

簡單運用 這一次我們會講到Tensorflow中的placeholder, placeholder是Tensorflow中的佔位符,暫時儲存變數. Tensorflow如果想要從外部傳入data,那就需要用到tf.placeholder(),然後以這種形式傳輸資料sess.run(***, feed_dict={input: **}). 示例: import tensorflow as tf #在 Tensorflow 中需要定義 placeholder 的 type ,一般為 float32 形式 input1 = tf.placeholder(tf.float32) input2 = tf.placeholder(tf.float32) # mul = multiply 是將input1和input2 做乘法運算,並輸出為 output ouput = tf.multiply(input1, input2) 接下來,傳值的工作交給了sess.run(),需要傳入的值放在了feed_dict={}並一一對應每一個input. placeholder與feed_dict={}是綁定在一起出現的。 with tf.Session() as sess:     print(sess.run(ouput, feed_dict={input1: [7.], input2: [2.]})) # [ 14.]

tensorflow-基礎語法

TensorFlow 用張量這種資料結構來表示所有的資料。用一階張量來表示向量,如: v = [1.2, 2.3, 3.5] ,如二階張量表示矩陣,如: m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ,可以看成是方括號嵌套的層數。 1.   編輯器 2.   編寫 tensorflow 代碼,實際上就是編寫 py 檔,最好找一個好用的編輯器,如果你用 vim 或 gedit 比較順手,那也可以的啦。我們既然已經安裝了 anaconda ,那麼它裡面自帶一個還算不錯的編輯器,名叫 spyder ,用起來和 matlab 差不多,還可以在右上角查看變數的值。因此我一直使用這個編輯器。它的啟動方式也很簡單,直接在終端輸入 spyder 就行了。 Note: 用 Anaconda 自帶的 IDE spyder 編輯 python 時,發現無法導入 tensorflow 模塊,我猜測應該時 IDE 的搜索路徑沒有包含 tensorflow 的路徑吧(未仔細研究),然後我在 Anadconda 的安裝路徑中找到了 / envs/tensorflow/lib/python2.7 ,並將該路徑中的 site-packages 檔夾中的所有檔拷貝到, Anaconda 安裝路徑下的 lib/python2.7/site-packages 檔夾中,之後再次打開 IDE ,發現已經可以 import 了!!!! cd   anaconda cp -rf  envs/tensorflow/lib/python2.7/site-packages/* lib/python2.7/site-packages/ 2.   常數 3.   我們一般引入 tensorflow 都用語句 4.   import tensorflow as tf 5.   因此,以後文章中我就直接用 tf 來表示 tensorflow 了。 6.   在 tf 中,常數的定義用語句: a=tf.constant(10) 這就定義了一個值為 10 的常數 a 3.   變數 ...