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.
修理からようやく帰ってきたTensorFlow(+GTX 1070)実行環境。
電源基板の故障とのことだった。
sine curveの学習結果のweight, biasを出力しようとしている。
Variables
...
In addition to the functionality provided by tf.Variable, slim.variables keeps track of the variables created by slim.ops to define a model, which allows one to distinguish variables that belong to the model versus other variables.
# Get all the variables defined by the model.
model_variables = slim.variables.get_variables()
上記のget_variables()の行を追加して、実行すると以下のエラーとなった。
Traceback (most recent call last):
File "linreg2_reprod.py", line 40, in <module>
model_variables = slim.variables.get_variables()
AttributeError: 'module' object has no attribute 'get_variables'
get_variablesというアトリビュートがないとのこと。
代わりに以下とすると一応model_variablesを取得できた。
資料が古いのか、資料の参照先をこちらが間違えているのかは不明。
model_variables = slim.get_variables()
print model_variables
[<tensorflow.python.ops.variables.Variable object at 0x7fe57c5ffdd0>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c5ffb50>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c5905d0>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c5ff650>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c5ff810>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c590890>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c5ff710>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c590050>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c5d3cd0>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c526d10>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c462550>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c5d3c50>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c453d10>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c316790>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c316650>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c316490>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c325a50>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c2d0f50>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c334550>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c334c90>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c316f10>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c325e50>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c325650>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c2dfbd0>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c2fb690>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c28ae10>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c244590>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c2edd10>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c298450>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c2a8a50>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c2fb390>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c334750>, <tensorflow.python.ops.variables.Variable object at 0x7fe57c26f0d0>]
variablesの格納場所(アドレス?)が得られたが、欲しい情報はその先にある個々の係数。
code
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
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])
## 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)
# 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))
# def feed_dict(inputs, output):
# return {input_ph: inputs.eval(), output_ph: output.eval()}
init_op = tf.initialize_all_variables()
# if 1 // show variables
# model_variables = slim.variables.get_variables()
model_variables = slim.get_variables()
print model_variables
# print "VARIABLES", tf.get_collection(tf.GraphKeys.VARIABLES,scope='output')
# print "TRAINABLE_VARIABLES", tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES,scope='output')
# print "TABLE_INITIALIZERS", tf.get_collection(tf.GraphKeys.TABLE_INITIALIZERS)
# print "SUMMARIES", tf.get_collection(tf.GraphKeys.SUMMARIES)
# print "QUEUE_RUNNERS", tf.get_collection(tf.GraphKeys.QUEUE_RUNNERS)
print ""
sys.exit()
# endif
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(30000): #[10000]
inpbt, outbt = sess.run([inputs_batch, output_batch])
_, t_loss = sess.run([train_op, loss], feed_dict={input_ph:inpbt, output_ph: outbt})
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)
link
こちらの方が本来参照すべき方なのかもしれない。
# Model Variables
weights = slim.model_variable('weights',
shape=[10, 10, 3 , 3],
initializer=tf.truncated_normal_initializer(stddev=0.1),
regularizer=slim.l2_regularizer(0.05),
device='/CPU:0')
model_variables = slim.get_model_variables()
# Regular variables
my_var = slim.variable('my_var',
shape=[20, 1],
initializer=tf.zeros_initializer)
regular_variables_and_model_variables = slim.get_variables()
.../inception/slimの方は最終更新日が8月30日。
.../contrib/slimの方は最終更新日が12月2日。