The investments are usually large enough that the only viable approach is to use them to initialize tf.Variableyour schedule. This will allow you to use servers with parameters in distributed, etc.
For this (and anything else), I would recommend using the new "core" rating tf.estimator.Estimator, as this will make things a lot easier.
, , , :
(2) dict
(3)
(3), :
model_fn Tensor, tf.contrib.framework.load_variable. :
:
def model_fn(mode, features, labels, hparams):
embeddings = tf.Variable(tf.contrib.framework.load_variable(
'gs://my-bucket/word2vec_checkpoints/',
'a/fully/qualified/scope/embeddings'
))
....
return tf.estimator.EstimatorSpec(...)
, TF, (2).
(2) tf.train.Scaffold, , tf.Session ( ).
Scaffold tf.train.EstimatorSpec, model_fn.
model_fn
, init_feed_dict Scaffold. .
def model_fn(mode, features, labels, hparams):
embed_ph = tf.placeholder(
shape=[hparams.vocab_size, hparams.embedding_size],
dtype=tf.float32)
embeddings = tf.Variable(embed_ph)
return tf.estimator.EstimatorSpec(
..., # normal EstimatorSpec args
scaffold=tf.train.Scaffold(init_feed_dict={embed_ph: my_embedding_numpy_array})
)
, init_feed_dict embed_ph , embeddings.initialization_op ( ).