I am coding a denoising autoencoder function with tensorflow (which is a little long so i won't post the entire code) and every thing is working well except when i am adding masking noise to a batch
Masking noise is just taking a random proportion of the features to 0. So the problem is just taking some value in a matrix to 0.(trivial if i had a np.array for exepmle)
So i see ,if it's a tf.variable, how to modify one element of a matrix thanks to tf.scatter_update() But then when I try with a placeholder it raises the error : "TypeError: 'ScatterUpdate' Op requires that input 'ref' be a mutable tensor" this is kind of problematic
I could solve this by adding noise to the batch before doing the encoding routine(I would handle then np.array instead of tf.placeholder) but i found this problem kind of frustrating ...
def bruit_MN(x,p=0.5):
l,c = x.shape
nbr = int(ceil(p*int(c))) #proportion of features to block
for i in range(l):
temp = np.zeros(c)
for j in range(nbr):
u = randint(0,c-1)
if temp[u]==0:
aux=tf.Variable(initial_value=x[i])
indices=tf.constant([u])
new_value=tf.constant([0.0])
aux=tf.scatter_update(aux,indices,new_value)
x=tf.scatter_update(x,i,aux)
temp[u] = 1
else:
j = j-1
return x
ps :maybe the code is not optimal i don't control random function very well
thanks for your attention!!