How to assign values to specified location in Tensorflow?

浪子不回头ぞ 提交于 2019-12-13 02:59:08

问题


I would like to implement a SSIM loss function, since the boarders are aborted by the convolution, I would like to preserve the boarders and compute L1 loss for the pixels of boarder. The code are learned from here. 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


回答1:


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)


来源:https://stackoverflow.com/questions/44648788/how-to-assign-values-to-specified-location-in-tensorflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!