问题
I have a function that has one two inputs and both of them are tensor. I need to do some processes on these inputs and then used the output in my network. one of these inputs is the output of the convolution layer and I do not know how do I solve this error! I put the function below:
the below code implements this equation, G, C(u) and C(v) are numbers.
enter image description here
def DCT(a, b):
for u in range(8):
for v in range(8):
for x in range(8):
for y in range(8):
b[u,v] = b[u, v] + 0.25 * C(u) * C(v) * a[x, y]* np.cos((2 * x+1) * (u) * np.pi / 16) * np.cos((2 * y+1) * (v) * np.pi / 16)
in the above code, a and b are tensors that are produced in the following code:
def slicAndJpeg(img):
for i in range (int(img.shape[1].value/8)):
for j in range(int(img.shape[2].value/8)):
temp=(img[:,i*8:i*8+8,j*8:j*8+8])
tempb=K.zeros((8,8))
DCT(temp,tempb)
mask=quntize_mask(8,9)
qunz=Kr.layers.multiply(mask,tempb)
tempc=K.zeros((8,8))
IDCT(qunz,tempc)
img[:,i*8:i*8+8,j*8:j*8+8]=tempc
the produced error is:
Traceback (most recent call last):
File "", line 122, in decoded_noise=JPEGLayer()(decoded)#16
File "D:\software\Anaconda3\envs\py36\lib\site-packages\keras\engine\base_layer.py", line 457, in call output = self.call(inputs, **kwargs)
File "", line 94, in call return noise()
File "", line 88, in noise slicAndJpeg(noised_image_pad)
File "", line 66, in slicAndJpeg DCT(temp,tempb)
File "", line 40, in DCT b[u,v] = b[u, v] + 0.25 * C(u) * C(v) * a[x, y]* np.cos((2 * x+1) * (u) * np.pi / 16) * np.cos((2 * y+1) * (v) * np.pi / 16)
TypeError: 'RefVariable' object does not support item assignment
but I need to do these assignments and I can not change them. do you have any suggestion? I also tried to use K.eval for these two inputs, but It produces another error that I think it is due to using K.eval before model.fit
InvalidArgumentError: You must feed a value for placeholder tensor 'input_1' with dtype float and shape [?,28,28,1]
could you please tell me how can I so these assignments without error? I am a beginner in keras and I do not know many things yet, so maybe my questions are easy for you but unfortunately, confused me. Thank you.
来源:https://stackoverflow.com/questions/55871023/how-do-i-assign-a-value-to-a-tensor-in-order-to-prevent-this-error-typeerror