tensorflow 如何使用 tf.map_fn 批量处理 (?, 40,30,128) 和 (?,40,30) 的两个输入张量形状,?是我的批量大小 [英] tensorflow how to use tf.map_fn to process two input tensor shape of (?, 40,30,128) and (?,40,30) in batch wise, ? is my batch size

查看:21
本文介绍了tensorflow 如何使用 tf.map_fn 批量处理 (?, 40,30,128) 和 (?,40,30) 的两个输入张量形状,?是我的批量大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 TF1.12.

I am using TF1.12.

我得到一个函数输入大小是 fn([40, 30, 128],[40, 30]) 并返回 tf.float32

I got a function input size is fn([40, 30, 128],[40, 30]) and return tf.float32

但是对于批量大小,我不知道该怎么做.然后我发现了这个 function tf.map_fn.我有两个输入,所以我应该把我的输入放在哪里.input1 [?, 40, 30, 128]input2 [?, 40, 30]

But with batch size, I don't know what to do. Then I found this function tf.map_fn. I got two input so where shall I put my input. input1 [?, 40, 30, 128]and input2 [?, 40, 30]

批量大小为None,但它们是相等的.

The batch size is None, but they are equal.

任何相关的将不胜感激.我是 tensorflow 的新手,所以任何事情都有帮助.

Anything related will be thankful. I am new to tensorflow, so anything is helpful.

非常感谢!

推荐答案

您可以:

tf.map_fn(lambda inp: fn(inp[0], inp[1]), (input1, input2))

注意tf.map_fn 通常比使用矢量化解决方案慢.考虑是否可以让 fn 处理成批数据而不是单个批处理元素.

Note that tf.map_fn is generally slower than using a vectorized solution. Consider whether you can make fn work with batches of data instead of with individual batch elements.

这篇关于tensorflow 如何使用 tf.map_fn 批量处理 (?, 40,30,128) 和 (?,40,30) 的两个输入张量形状,?是我的批量大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆