後で簡単に取得できるように自分のオブジェクトを保存するにはtf.add_to_collection()を使用します。ここ は、コードセグメントである:テンソルフローでコレクションを使用して自分自身のオブジェクトを保持する方法
class Model(object):
def __init__(self, scope, is_training=True):
は、オブジェクトをコレクションに追加します。
for i in xrange(num_gpus):
with tf.device("/gpu:%d"%i):
with tf.name_scope("tower_%d"%i) as scope:
m = Model.Model(scope)
tf.add_to_collection("train_model", m)
コレクションからオブジェクトを取得:
models = tf.get_collection("train_model")
コードが正常に動作しますが、私は警告が出ます:
WARNING:tensorflow:Error encountered when serializing train_model.
Type is unsupported, or the types of the items don't match field type in CollectionDef.
'Model' object has no attribute 'name
この警告を避けるにはどうすればよいですか?