问题
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