Tensorflowã«ã¤ãã¦ã¯ããããããªæ¸ç±ãåºã¦ãã¾ããããããä¸ã§ãæçãªæ å ±ãããããããã¾ãããã ããã¯ãæ¬å®¶æ¬å ã®Tendorflowã®ãµã¤ãã®æ å ±ã¯å å®ãã¦ãã¾ããä»åã¯ãããããããã¤ãPythonã®ã³ã¼ã解説ããµã³ãã«ãåãããªããåå¼·ãã¦ã¿ãã®ã§ãç°¡åã«ã¡ã¢ãã¦ããã¾ãã
- ï¼ï¼Tensorflowã®ãµã¤ã
- ï¼ï¼GET STARTED
- ï¼ï¼Google翻訳ãä½µç¨ãã¦ããã
- ï¼ï¼ã¨ã©ã¼ãåºãå ´å
- ï¼ï¼tf.train APIãç¨ããLiner Regressionã®ãµã³ãã«
- ï¼ï¼tf.train API
Â
ï¼ï¼Tensorflowã®ãµã¤ã
ãµã¤ãã®URLã¯ã·ã³ãã«ã§ã(https://www.tensorflow.org/)ãéãã¨æ¬¡ã®ãããªç»é¢ãåºã¦ãã¾ãã
ãã®ããããã¼ã¸ã¯ãææ°Versionã®ãç¥ããã大è¦æ¨¡ã¤ãã³ãã®ã¢ãã¦ã³ã¹ãGITHUBã¸ã®ãªã³ã¯ãå³ä¸ã«ãã£ã¦ããªããªãå å®ãã¦ãã¾ããTensorflowãã¯ããã人åãã«ã¯ãGET STARTEDããããã¾ãããããã¯ãªãã¯ãã¦ã¿ã¾ãããã
Â
ï¼ï¼GET STARTED
Tensorflowã®APIã¯ãTensorflow Coreç¨ã®APIã¨ããä¸ä½ã®APIãããã¾ãããããã§ã¯Tensorflow Coreç¨ã®APIã®ãã¥ã¼ããªã¢ã«ã«ãªã£ã¦ãã¾ããè¨èªã¯Pythonã§ããã¤ã³ã¹ãã¼ã«æ¹æ³ã¸ã®URLã®Linkãä¹ã£ã¦ãã¾ãã
ç¶ãã¦ãTensorflowã®ãã¼ã¿ã®ä¸å¿åä½ãtensorã¨å¼ã°ãããã¨ã¨ãã®ã³ã¼ãä¾ãPythonã§ã®Importä¾ãæ¸ãã¦ããã¾ãã
Â
ããã«ããã®ããã«åºæ¬çãªTensoflowã®ä½¿ãæ¹ãã³ã¼ãä¾ã¨ãã¦åºã¦ãã¾ããèªã¿ãªããé©æã³ãããã¦ã¤ãªãã§IPythonãJupier NoteBookã§åããã¦ãããã¨ã§ç¢ºèªã§ãã¾ãããã®åå¿è åãã®æåã®ãã¼ã¸ã ãã§ãããªããªãæ å ±éããããå³ã交ãã¦æ¸ããã¦ãã£ã¦ãã¨ã¦ãããã§ãã
Â
ï¼ï¼Google翻訳ãä½µç¨ãã¦ããã
Â
è±èªã®æç« ãé·ã ã¨èªã¿ãããªãã¨ãã人ãè±èªã¯è¦æã¨ãã人ã¯ãé©æGoogle翻訳ã使ã£ã¦ãããã¨æãã¾ããGoogle翻訳ã¯ä½¿ããã±ã¼ã¹ã¨ãã¾ãå½¹ã«ç«ããªãã±ã¼ã¹ãããã®ã§ããããã®ãµã¤ãã®æ£å¼ææ¸ã¯ãã¡ãã¨æ¸ããã¦ããæç« ãå¤ãã®ã§ãæ¯è¼çãã·ãªæ¥æ¬èªãè¿ã£ã¦ãããã®ãå¤ãã§ããä¾ãã°ã以ä¸ã®ãããªæãã§ãèªç¶ãªè¨³ãã©ããã¯ã¨ãããç解ã®å½¹ã«ã¯ç«ã¡ã¾ãã
Â
ï¼ãªãªã¸ãã«ã®è±æï¼
A computational graph is a series of TensorFlow operations arranged into a graph of nodes. Let's build a simple computational graph. Each node takes zero or more tensors as inputs and produces a tensor as an output. One type of node is a constant. Like all TensorFlow constants, it takes no inputs, and it outputs a value it stores internally. We can create two floating point Tensors node1 and node2 as follows:
ï¼ä¸è¨ãGoogle翻訳ãããã®ï¼
è¨ç®ã°ã©ãã¯ãä¸é£ã®TensorFlowæ¼ç®ããã¼ãã®ã°ã©ãã«é ç½®ãããã®ã§ããç°¡åãªè¨ç®ã°ã©ããä½æãã¾ããããåãã¼ãã¯ãå ¥åã¨ãã¦0以ä¸ã®ãã³ã½ã«ãã¨ããåºåã¨ãã¦ãã³ã½ã«ãçæããã1ã¤ã®ã¿ã¤ãã®ãã¼ãã¯å®æ°ã§ãããã¹ã¦ã®TensorFlowå®æ°ã¨åæ§ã«ãå ¥åããªãå é¨çã«æ ¼ç´ãããå¤ãåºåãã¾ããnode1ã¨node2ã®2ã¤ã®æµ®åå°æ°ç¹ãã³ã½ã«ã次ã®ããã«ä½æã§ãã¾ãã
Â
ï¼ãªãªã¸ãã«ã®è±æï¼
As it stands, this graph is not especially interesting because it always produces a constant result. A graph can be parameterized to accept external inputs, known as placeholders. A placeholder is a promise to provide a value later.
ï¼ä¸è¨ãGoogle翻訳ãããã®ï¼
ãã®ã°ã©ãã¯ã常ã«ä¸å®ã®çµæãçããããç¹ã«èå³æ·±ãããã§ã¯ããã¾ãããã°ã©ãã¯ããã¬ã¼ã¹ãã«ãã¨å¼ã°ããå¤é¨å ¥åãåãä»ããããã«ãã©ã¡ã¼ã¿åã§ãã¾ãããã¬ã¼ã¹ãã«ãã¯å¾ã§å¤ãæä¾ããã¨ããç´æã§ãã
Â
ï¼ï¼ã¨ã©ã¼ãåºãå ´å
ã¨ã©ã¼ãåºãå ´åãããã¾ãããããããã®ãã¼ã¸ã¯ã¨ã¦ãæåã§ããããã®äººãå©ç¨ãã¦ããã®ã§ãã©ããªã¨ã©ã¼ãåºãã®ãããã®è¡ã¨ã¨ã©ã¼ãã³ãããã¦æ¤ç´¢ããã°çµæ§ããããã¦ãã©ãããã°ããã対å¦æ¹æ³ããããã¾ãã
Â
ç§ã®å ´åããã®ãã¼ã¸ã«ããã³ã¼ããå®è¡ãããä¸é¨ã§ã¨ã©ã¼ãåºãã®ã§ããã®è¡ã¨ã¨ã©ã¼ãæ¤ç´¢ãããããã¯ãåãã¨ã©ã¼ã«ç´é¢ãã人ã質åãã¦ããslackããã£ã¦(https://www.quora.com/How-should-I-start-learning-tensor-flow)ã以ä¸ã®ãããªæãã§åºã¦ããã®ã§ãããã§å¯¾å¦ãã¾ãããããã£ã¦ãã¾ãã°ããªã¼ãã ãã§ãããã¡ãªã¿ã«ãã¤ãã§ã«ãã£ã¨æµãã¦èªãã ã ãã§ããããã®slackã¯ããããªè³ªåã¨çãããã£ã¦ãæçããã§ãã
ï¼ï¼tf.train APIãç¨ããLiner Regressionã®ãµã³ãã«
ã·ã³ãã«ãªLiner Regressionï¼ç·å½¢å帰ï¼ã®ãµã³ãã«ãåããã¼ã¸ã«ä¹ã£ã¦ãã¾ãã以ä¸ã®éãã§ããGPUãä¹ã£ã¦ããªããã·ã³ã ã¨å®è¡æã«è¦åãåºã¾ããããã¡ãã¨ãããã¾ãã
- ã¢ãã«ãè¨å®
- æ失é¢æ°ãè¨å®
- å¾é éä¸æ³ã§æé©å
- ãã¬ã¼ãã³ã°
- 精度ãã¿ã
ã¨ããæ©æ¢°å¦ç¿ã®åºæ¬çãªå½¢ãç°¡æ½ãªã³ã¼ãã§æ¸ãããã¨ããããã¾ãã
Â
import tensorflow as tf
Â
# Model parameters
W = tf.Variable([.3], dtype=tf.float32)
b = tf.Variable([-.3], dtype=tf.float32)
# Model input and output
x = tf.placeholder(tf.float32)
linear_model = W * x + b
y = tf.placeholder(tf.float32)
Â
# loss
loss = tf.reduce_sum(tf.square(linear_model - y)) # sum of the squares
# optimizer
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)
Â
# training data
x_train = [1, 2, 3, 4]
y_train = [0, -1, -2, -3]
# training loop
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init) # reset values to wrong
for i in range(1000):
 sess.run(train, {x: x_train, y: y_train})
Â
# evaluate training accuracy
curr_W, curr_b, curr_loss = sess.run([W, b, loss], {x: x_train, y: y_train})
print("W: %s b: %s loss: %s"%(curr_W, curr_b, curr_loss))
Â
ï¼ï¼tf.train API
å ã»ã©ã®ç·å½¢å帰ã®ããã°ã©ã ããé«ã¬ãã«ã®Tensorflowã®ã©ã¤ãã©ãªã§ããtf.train APIã§æ¸ãç´ããä¾ãè¼ã£ã¦ãã¾ããã³ã¼ãã¯ãµã¤ããè¦ã¦ãã ããããããGPUç¡ãã ã¨è¦åã¯åºã¾ãããåãã¾ãã
Â