TensorFlow > sine curveの学習 > v0.3 > feed_dictを使おうとしている / TypeError: The value of a feed cannot be a tf.Tensor object. > .eval()の使用 > よくないかもしれない

```txt:動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 14.04 LTS desktop amd64
TensorFlow v0.11
cuDNN v5.1 for Linux
CUDA v8.0
Python 2.7.6
IPython 5.1.0 -- An enhanced Interactive Python.
```

v0.1 http://qiita.com/7of9/items/b364d897b95476a30754

http://qiita.com/7of9/items/c8c521fa808b133a801a
の続き

feed_dictを使おうとしてtf.placeholder()形式に変更中。

```linreg2_feeddict.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tensorflow as tf
import tensorflow.contrib.slim as slim

# ファイル名の Queue を作成
filename_queue = tf.train.string_input_producer(["input.csv"])

# CSV を parse
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
input1, output = tf.decode_csv(value, record_defaults=[[0.], [0.]])
inputs = tf.pack([input1])
output = tf.pack([output])

#batch_size=4 # [4]
#inputs_batch, output_batch = tf.train.shuffle_batch([inputs, output], batch_size, capacity=40, min_after_dequeue=batch_size)

input_ph = tf.placeholder("float", [None,1])
output_ph = tf.placeholder("float",[None,1])

inputs_rs = tf.reshape(inputs, [-1, 1])
output_rs = tf.reshape(output, [-1, 1])

## NN のグラフ生成
hiddens = slim.stack(input_ph, slim.fully_connected, [1,7,7,7], 
  activation_fn=tf.nn.sigmoid, scope="hidden")
prediction = slim.fully_connected(hiddens, 1, activation_fn=tf.nn.sigmoid, scope="output")
loss = tf.contrib.losses.mean_squared_error(prediction, output_ph)

def feed_dict(train, inputs, output):
#    if train:
#
    return {input_ph: inputs.eval(), output_ph: output.eval()}

#train_op = slim.learning.create_train_op(loss, tf.train.AdamOptimizer(0.01))
train_op = slim.learning.create_train_op(loss, tf.train.AdamOptimizer(0.001))

init_op = tf.initialize_all_variables()

with tf.Session() as sess:
  coord = tf.train.Coordinator()
  threads = tf.train.start_queue_runners(sess=sess, coord=coord)

  try:
    sess.run(init_op)
    for i in range(10000): #[10000]
      _, t_loss = sess.run([train_op, loss], feed_dict=feed_dict(True, inputs_rs, output_rs))
      if (i+1) % 100 == 0:
        print("%d,%f" % (i+1, t_loss))
#        print("%d,%f,#step, loss" % (i+1, t_loss))
  finally:
    coord.request_stop()

  coord.join(threads)
```

```txt:結果
100,0.607436
200,0.546756
300,0.505339
400,0.475503
500,0.453048
600,0.435565
700,0.421596
800,0.410206
900,0.400765
1000,0.392831
1100,0.386082
1200,0.380280
1300,0.375244
1400,0.370837
1500,0.366952
1600,0.363503
1700,0.360425
1800,0.357664
1900,0.355175
2000,0.352922
2100,0.350875
2200,0.349009
2300,0.347303
2400,0.345737
2500,0.344297
2600,0.342969
2700,0.341741
2800,0.340603
2900,0.339545
3000,0.338561
3100,0.337643
3200,0.336786
3300,0.335983
3400,0.335230
3500,0.334524
3600,0.333859
3700,0.333233
3800,0.332642
3900,0.332084
4000,0.331557
4100,0.331058
4200,0.330585
4300,0.330137
4400,0.329711
4500,0.329307
4600,0.328922
4700,0.328556
4800,0.328208
4900,0.327875
5000,0.327559
5100,0.327256
5200,0.326968
5300,0.326692
5400,0.326428
5500,0.326176
5600,0.325934
5700,0.325704
5800,0.325482
5900,0.325271
6000,0.325068
6100,0.324873
6200,0.324686
6300,0.324507
6400,0.324335
6500,0.324171
6600,0.324012
6700,0.323860
6800,0.323714
6900,0.323574
7000,0.323440
7100,0.323310
7200,0.323186
7300,0.323066
7400,0.322951
7500,0.322841
7600,0.322734
7700,0.322632
7800,0.322534
7900,0.322439
8000,0.322348
8100,0.322261
8200,0.322176
8300,0.322095
8400,0.322017
8500,0.321942
8600,0.321870
8700,0.321800
8800,0.321733
8900,0.321668
9000,0.321606
9100,0.321546
9200,0.321489
9300,0.321433
9400,0.321380
9500,0.321329
9600,0.321279
9700,0.321231
9800,0.321185
9900,0.321141
10000,0.321099
```

feed_dictへの与え方は学習中なのでよく分かっていないためか、lossの値が悪いまま。

### .eval()


```
def feed_dict(train, inputs, output):
#    if train:
#
    return {input_ph: inputs, output_ph: output}
```

上記ではエラーが出た。

> TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, or numpy ndarrays.

http://stackoverflow.com/questions/37203858/tensorflow-typed-miss-when-run-my-train-py
を参考に.eval()をつけると動くようになった。

```
def feed_dict(train, inputs, output):
#    if train:
#
    return {input_ph: inputs.eval(), output_ph: output.eval()}
```

まだまだ色々分かってはいない。

(追記 2016/11/20)
**<font color=red>.eval()をつけるとその時点で評価がされる。以下の記事で書いたように、複数のevalを実行すると、それぞれのインデックスが異なるので失敗する</font>**
http://qiita.com/7of9/items/40a7cfc741f4b11f50d2