简体   繁体   English

张量流-tf.where TypeError

[英]tensorflow - tf.where TypeError

I wrote the following test code (a part of a much bigger code) 我编写了以下测试代码(更大的代码的一部分)

import tensorflow as tf

update_boolean = [True, False, True, False, True, True]


with tf.Session() as sess:
    op = tf.where(update_boolean, lambda: tf.train.AdamOptimizer(0.1), lambda: tf.no_op())

I get the following error 我收到以下错误

TypeError: Expected binary or unicode string, got <function <lambda> at 0x000000000118E400>

how can I fix this? 我怎样才能解决这个问题?

what I want to do is create a list\\tensor of operators (which are optimizer\\do nothing) given a certain condition (not using tf.cond because i want to apply this to a batch so I have a list\\tensor of booleans) * working in tensorflow 1.0 我想做的是给定条件创建一个操作符的列表\\张量(它们是优化器\\什么都不做)(不使用tf.cond因为我想将此应用于批处理,所以我有一个布尔值的列表\\张量) *在tensorflow 1.0中工作

tf.train.AdamOptimizer(0.1) returns an Optimizer object, it is not clear how this relates to a no_op. tf.train.AdamOptimizer(0.1)返回一个Optimizer对象,尚不清楚它与no_op的关系。 I suggest starting by creating the optimizer and then conditioning on gradient updates instead, for instance by zeroing gradient contributions from the part of the batch wanted. 我建议从创建优化器开始,然后以渐变更新为条件,例如,将所需批次中的渐变贡献归零。 tf.where does not work with operations, it provides indices for accessing tensors. tf.where不适用于操作,它提供用于访问张量的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM