概要
クラウドサーバでTensorFlowやってみた。
csv + shuffule_batchの動作確認してみた。
写真
元
結果
環境
クラウド idcf
linux debian-8.11
tensorflow 1.2
gpu 無し
サンプルコード
random生成
import numpy as np
import matplotlib.pyplot as plt
x = np.random.randint(0, 255, 10000)
y = np.random.randint(0, 255, 10000)
v = np.empty((0, 2))
for i in range(10000):
z = np.hstack((x[i], y[i]))
v = np.vstack((v, z))
np.savetxt("batchtest0.csv", v, fmt = "%.0f", delimiter = ",")
x0, y0 = np.loadtxt("batchtest0.csv", unpack = True, usecols = (0, 1), delimiter = ',')
plt.scatter(x0, y0, marker = '.', alpha = 0.8, linewidths = 0.01)
plt.show()
csv + shuffle_batch
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
filename_queue = tf.train.string_input_producer(["batchtest0.csv"])
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
x, y = tf.decode_csv(value, record_defaults = [[1], [1]], field_delim = ",")
xs, ys = tf.train.shuffle_batch([x, y], 100, capacity = 500, min_after_dequeue = 400)
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess = sess, coord = coord)
try:
for i in range(100):
dx, dy = sess.run([xs, ys])
plt.scatter(dx, dy, marker = '.', alpha = 0.8, linewidths = 0.01)
plt.show()
finally:
coord.request_stop()
coord.join(threads)