【发布时间】:2021-10-05 08:35:37
【问题描述】:
我正在尝试迭代两个批量大小均为 32 的数组,但其中包含嵌套的 tf.vectorize_maps,因此每个数组都有一个,但它们的形状不同,因此:(32,12-1,4) 和 (32, 1024,4) 但我在嵌套 tf.function 内的 training_step 内的 model.fit/model.train_on_batch 内执行此操作。我得到了这个错误。
我得到这个错误:
tf.vectorized Input to reshape is a tensor with 98304 values, but the requested shape has 288.
尝试修复或原创。
IoUs = tf.vectorized_map(lambda batch: tf.vectorized_map(lambda ypredValues:
tfytrue(ytrue[batch],ypredValues),ypred[batch]),tf.range(32))
IoUs = tf.vectorized_map(lambda batch: tf.vectorized_map(lambda ypredValues: tfytrue(batch[0],ypredValues),batch[1]),(ytrue,ypred))
批量索引相同时有效:
IoUs = tf.vectorized_map(lambda batch: tf.vectorized_map(lambda ypredValues: tfytrue(batch[1],ypredValues),batch[1]),(ytrue,ypred`))
但这很愚蠢,因为我无法对批处理大小进行parrel映射并使用相同的数组:也许它在其他vectorized_maps中,但如果有人可以提供帮助,那就太好了。我使用 tf.vectorized 的原因是速度比 map_fn 提高了大约 3000 倍,并且我能够使用 numpy 作为 tf.py_func 和 tf.numpy_array 返回无效的占位符值。
但它确实适用于 elems=(ytrue,ypred) 但不适用于 model.fit 或 model.train_on_batch。
RegLoss = tfIoU(batch[1],self.RPN(batch[0])[0])
效果很好,但在我的自定义 train_step tfIoU(ytrue,ypred) 中的 train_on_batch/model.fit 内:
Input to reshape is a tensor with 393216 values, but the requested shape has 4608
没有发生重塑,它可以追溯到批量矢量化地图
我的问题是,因为它第一次工作就像它为 tf.vectorized 地图设置形状一样,所以第二次就不能工作了?
所以 (32,12,4) 工作,然后 (32,8,4) 失败,然后颠倒顺序,他们做同样的事情有人可以帮忙吗?
【问题讨论】:
标签: python-3.x tensorflow tensorflow2.0