我认为最简单的方法就是
for i in range(1000): batch_xs, batch_ys = mnist.train.next_batch(100) if i % 2 == 0: sess.run(train_step1, feed_dict={x: batch_xs, y_: batch_ys}) else: sess.run(train_step2, feed_dict={x: batch_xs, y_: batch_ys})
但是如果需要通过tensorflow条件流进行切换,请按照以下方式进行 *** 作:
optimizer = tf.train.GradientDescentOptimizer(0.5)train_step = tf.cond(tf.equal(tf.mod(global_step, 2), 0), true_fn=lambda: optimizer.apply_gradients(zip(tf.gradients(cross_entropy, tvars1), tvars1), global_step), false_fn=lambda: optimizer.apply_gradients(zip(tf.gradients(cross_entropy, tvars2), tvars2), global_step))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)