如何在Tensorflow中将值分配给指定位置? [英] How to assign values to specified location in Tensorflow?
问题描述
我想实现SSIM损失功能,因为边界被卷积中止,所以我想保留边界并为边界像素计算L1损耗.从这里学习代码. 用于TensorFlow的SSIM/MS-SSIM
例如,我们具有img1和img2大小[batch,32,32,32,1],以及Guassian 11的window_size,结果sim贴图将为[batch,22,22,22,1],L1映射[batch,32,32,32,1]如何将sim分配给L1的中心?
我收到这样的错误; TypeError:张量"对象不支持项目分配对于按价值分配,请在此处查看答案:SSIM / MS-SSIM for TensorFlow
For example, we hava img1 and img2 size [batch,32,32,32,1], and the window_size of Guassian 11, the result ssim map will be [batch,22,22,22,1], L1 map [batch,32,32,32,1] how can I assign ssim to the center of the L1?
I receive error like this; TypeError: 'Tensor' object does not support item assignment
For value-wise assignement, give a look at the answer here: Adjust Single Value within Tensor -- TensorFlow
A way that probably goes more along to what you are looking for might be:
- create the ssim_map tensor
- create the frame of the ssim_map, i.e. the part (as tensors) that you need in order to complete ssim_map to L1_map
- use
tf.concat
operations to put the pieces together and have your final tensor
For example, I haven't checked if it works, but somethink like this should do the job:
upper_band1 = L1_map[:, :5, 5:-5, 5:-5, :]
lower_band1 = L1_map[:, -5:, 5:-5, 5:-5, :]
upper_band2 = L1_map[:, :, :5, 5:-5, :]
lower_band2 = L1_map[:, :, -5:, 5:-5, :]
upper_band3 = L1_map[:, :, :, :5, :]
lower_band3 = L1_map[:, :, :, -5:, :]
intermediate_1 = tf.concat([upper_band1, ssmi_map, lower_band1], axis=1)
intermediate_2 = tf.concat([upper_band2, intermediate1, lower_band2], axis=2)
final = tf.concat([upper_band3, intermediate3, lower_band3], axis=3)
这篇关于如何在Tensorflow中将值分配给指定位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!