tf.add_to_collection()tf.get_collection()tf.add_n()
tf.add_to_collection:セットに変数、に多くの変数のリスト tf.get_collection:結合、リストからすべての変数を削除することである tf.add_n:物事のリストは順次組み合わせて 例を: インポートtensorflow TF AS; インポートnumpyのAS NP; PLT ASインポートmatplotlib.pyplot; V1 = tf.get_variable([1] NAME = 'V1'、形状=、tf.constant_initializer =(0)の初期化子) tf.add_to_collection( '損失'、 V1) V2 = tf.get_variable([1] NAME = 'V2'、形状=、= tf.constant_initializer初期化(2)) tf.add_to_collection( '損失'、V2) tf.Sessionと()のようなセッション数: セッション数。 RUN(tf.initialize_all_variables()) プリントtf.get_collection( '損失') プリントsess.run(tf.add_n(tf.get_collection( '損失'))) 出力: [<0x7f6b5d700c50でtensorflow.python.ops.variables.Variableオブジェクト>、<0x7f6b5d700c90でtensorflow.python.ops.variables.Variableオブジェクト>] [2]