Update weights of keras model only based on samples that meet a condition while training
I recently dealt with such a situation and the way I handled was by keeping the batch dimension flexible. For example: if you are using TensorFlow define the placeholder as [None, w, h, 3] (in case of image) and develop your model. The weights have nothing to do with the batch dimensions. So,  when you decrease the size of the computations on axis = 0, the rest of the change will happen accordingly. Basically don't define any concrete batch size, keep it flexible.
I have an autoencoder model using keras, input and output shape is (BATCH_SIZE, 20). In the middle there is a Lambda layer that filters the data. In other words, if the batch size is 1000, there might be only 700 that comes out from the Lambda layer. Then I want to update the weights based on just these 700 samples. Is there any way to tackle this in Keras?