I Have an auto encoder like neural network that i coded and 9000 training examples. I also have a numpy ndarray with 9000 arrays. My goal is to tie the activations (not weights) of the middle layer (which is reshaped to the size of one of the arrays in the 9000 group). I would like a situation where i randomly innitialise the numpy array. Then , using a batch size of 9000..average the values between the particular training examples activation in the middle layer , and its associated array out of the 9000 in the numpy array.
The numpy ndarray is to be used elsewhere in the program after training.
So this is what should happen should we have 1 training example, then we may have the numpy array be a (1,240,5) and the representation (activations) in the middle layer of the neural network after forward propagating become reshaped to (1,240,5). so there is a neuron for each entry in the numpy ndarray. Given that after the first forward pass , the activations will be reshaped to an ndarray the same shape as the numpy array, i would like to average the values of those found already within the numpy array , and those that appeared after the first foward pass.
as training countinues on that one training example, the activations will change, and i would like to keep averaging the values at each iteration, untill training is complete.
this is more complex in the example with 9000 training examples where each example after the first pass has a seperate activation ndarray and must be averaged with its own external numpy array.
Again, the external numpy array is not a part of the neural network although its final values will depend on the training procedure.
i am using keras.
so the code could be something like this perhaps, using model.metrics_tensors and a minibatch of 1.
a=np.random.rand(9000, 240, 5)
Mirror=(Dense(240*5))
model = Sequential()
model.add(Conv2D(64, (3, 3), activation='relu', padding='same'))
model.add(MaxPooling2D(pool_size=(2, 2))) #7 x 7 x 64
model.add(Conv2D(64, (3, 3), activation='relu', padding='same'))
model.add(Flatten())
model.add(Mirror)
#decoder
model.add(Conv2D(128, (3, 3), activation='relu', padding='same'))
model.add(UpSampling2D((2,2))) # 14 x 14 x 128
model.add(Conv2D(64, (3, 3), activation='relu', padding='same'))
model.add(UpSampling2D((2,2))) # 28 x 28 x 64
model.add(Conv2D(64, (3, 3), activation='relu', padding='same'))
model.compile(optimizer="adadelta", loss='mse',metrics=["accuracy"])
output_layers= ['Mirror']
model.metrics_names += 'Mirror'
model.metrics_tensors = [Mirror]
x=[layer.output for layer in model.layers if layer.name in output_layers]
del x[0]
x=np.asarray(x)
x=np.flatten(x)
x=np.ndarray.reshape(x,(1,240,5))
tf.keras.layers.average(x,a[0:1,:,:])