1. 程式人生 > >學習筆記-TypeError: Fetch argument array has invalid type type 'numpy.ndarray',(Can not convert a ...)

學習筆記-TypeError: Fetch argument array has invalid type type 'numpy.ndarray',(Can not convert a ...)

報錯:

TypeError: Fetch argument array([ 12., 244., 234., ..., 255., 189., 0.], dtype=float32) has invalid type <type 'numpy.ndarray'>,  (Can not convert a ndarray into a Tensor or Operation.)

程式碼出錯位置:

for i in range(1):
  image, label = sess.run([image, label])
  print label

原因分析:

程式碼迭代了20次, 第1次迭代後可以打印出label的值, 第2次迭代就開始報錯誤, 可見第二行程式碼, 在同一個session裡我們用新的image, label取代了原始的image, label, 第1次迭代時, 兩個變數都是原始資料, 資料型別均為Tensor, 但run之後, 老的變數就被新的變數取代了, 此時的兩個變數的資料型別是np.array(), 那麼第2次迭代就會因為資料型別不是Tensor而報錯.

解決方案:

for i in range(1):
  images, labels = sess.run([image, label])
  print labels

用新的變數名去接收新的變數, 不要取代了老的變數即可.

reference: