TensorFlow > (input:2ノード, output:2ノード)のデータを作成し、TensorFlowの中で読込む > v0.1

```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.
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
```

### やろうとしていること

input node: 167,926個
output node: 167,926個

の学習を行う。
(無理かも)

その前段階として

input node:2
output node:2
を読んでみる。

### Python > データ生成

```pre_data_170109.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import numpy as np
import random

'''
v0.2 Jan. 09, 2017
    - output to files
v0.1 Nov. 12, 2016
    - print to Standard output
'''

numdata = 100
x_data = np.random.rand(numdata)
y_data = np.sin(2*np.pi*x_data) + 0.3 * np.random.rand()

for xs, ys in zip(x_data, y_data):
    print('%.5f, %.5f, %.5f, %.5f' % (xs, (xs+3), ys, (ys+5)))

with open("input_node.csv", "w") as inpfd:  # inpfd: input layer
    for xs in x_data:
        inpfd.write('%.5f, %.5f\n' % (xs, (xs+3)))

with open("output_node.csv", "w") as outfd:  # outfd: output layer
    for ys in y_data:
        outfd.write('%.5f, %.5f\n' % (ys, (ys+5)))
```

### ファイル生成

```txt:実行
$ python pre_data_170109.py > res.csv
```

上記実行後、以下のファイルが生成される

1. res.csv : デバッグ用
2. input_node.csv
3. output_node.csv


```txt:確認
$ head -n 3 res.csv input_node.csv output_node.csv 
==> res.csv <==
0.11199, 3.11199, 0.71899, 5.71899
0.89814, 3.89814, -0.52524, 4.47476
0.63075, 3.63075, -0.66022, 4.33978

==> input_node.csv <==
0.11199, 3.11199
0.89814, 3.89814
0.63075, 3.63075

==> output_node.csv <==
0.71899, 5.71899
-0.52524, 4.47476
-0.66022, 4.33978
```


### TensorFlow > ファイル読込み

input_node.csvとoutput_node.csvから読み込んでみる。
TensorFlowでの「学習」は実装していない。

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

'''
v0.1 Jan. 09, 2017
    - read (2,2) nodes for (input, output) from [input_node.csv] and [output_node.csv]
'''

import sys
import tensorflow as tf
import tensorflow.contrib.slim as slim
import numpy as np

# read input node
filename_queue = tf.train.string_input_producer(["input_node.csv"])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
input1 = tf.decode_csv(value, record_defaults=[[0.], [0.]])

# read output node
filename_queue = tf.train.string_input_producer(["output_node.csv"])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
output1 = tf.decode_csv(value, record_defaults=[[0.], [0.]])

# initialize
init_op = tf.initialize_all_variables()

# session
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 loop in range(10):
            inp1 = sess.run(input1)
            out1 = sess.run(output1)
            print(inp1, out1)
    finally:
        coord.request_stop()
    coord.join(threads)
```

```txt:実行$ 
python read_target.py 
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_device.cc:951] Found device 0 with properties: 
name: GeForce GTX 1070
major: 6 minor: 1 memoryClockRate (GHz) 1.7715
pciBusID 0000:01:00.0
Total memory: 7.91GiB
Free memory: 7.41GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:972] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)
([0.11199, 3.11199], [0.71899003, 5.7189898])
([0.89814001, 3.89814], [-0.52524, 4.4747601])
([0.63075, 3.6307499], [-0.66022003, 4.3397799])
([0.66579002, 3.6657901], [-0.79128999, 4.2087102])
([0.52727002, 3.5272701], [-0.098540001, 4.9014602])
([0.62568998, 3.62569], [-0.63819999, 4.3618002])
([0.10847, 3.10847], [0.70196003, 5.7019601])
([0.96858001, 3.96858], [-0.12414, 4.8758602])
([0.097790003, 3.09779], [0.64844, 5.6484399])
([0.89565998, 3.8956599], [-0.53763002, 4.4623699])
```

読めているようだ。

(input:2, output:2)
から
(input:100, output:100)
などにするには根本的に違う方法が必要かも。

MNISTのコードを学ぶ方がいいかもしれない。