【问题标题】:Comparing strings with tensors比较字符串和张量
【发布时间】:2019-07-25 21:39:31
【问题描述】:

我知道有一种方法可以检查张量的值,tf.Session().run()。我试图将张量的值与字符串进行比较,但是时间太长了。有没有其他办法?

sess = tf.Session()
value = sess.run(output[0])  # type of output[0] : tensor

for i in range(len(image_list_LR)):
    if (image_list_LR[i] == value):  # type of image_list_LR[i] : string
        input_image_LR = image_list_LR_npy[i]

【问题讨论】:

  • 我猜内线应该是input_image_LR[i] = image_list_LR_npy[i]?
  • output[0]image_list_LR[i] 相等时,我想将image_list_LR_npy[i] 放入input_image_LR
  • 好的,我改变了答案,所以它应该这样做。

标签: python tensorflow


【解决方案1】:

试试这个:

image_list_LR = np.array(image_list_LR)
indices = np.where(image_list_LR == value) 
if indices:
    input_image_LR = image_list_LR_npy[indices[0]]

【讨论】:

  • 非常感谢您的建议。这是一个愚蠢的问题,但如果没有sess.run(),就无法比较字符串和张量?运行时间太长。
  • @LUCY 除非您运行会话,否则 tensorflow 张量没有值。所以不幸的是,它不可能。根据您在代码中所做的其他事情,您可以在其他时间执行此操作,但如果没有看到就很难说。
  • @LUCY 如果解决了您的问题,请接受答案!
  • 感谢您的建议和详细解释!!祝你有美好的一天!:)
  • @LUCY 没问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-23
  • 2021-03-30
相关资源
最近更新 更多