I try to update the weight only at the end of batches and I know that this is the default behavior but I don't understand why you need to have your X and y the same size? If I have X.shape(12,32,64) in which I use the batch size 12, so just one batch why is not enough to have y.shape(1,N)?
I would like to backpropagate only after the entire batch size is shown to the network. Why to have a label for each batch item?
Example code:
def create_model(batch, timesteps, features):
inputTensor1 = Input(batch_shape=(batch, timesteps, features))
lstm1 = LSTM(32, stateful=True, dropout=0.2)(inputTensor1)
x = Dense(4, activation='linear')(lstm1)
model = Model(inputs=inputTensor1, outputs=x)
model.compile(loss='mse', optimizer='rmsprop', metrics=['mse'])
print(model.summary())
plot_model(model, show_shapes=True, show_layer_names=True)
return model
X = np.load("").reshape(1280,12,640,32)
y = np.load("").reshape(1280,1,4)
prop_train = 0.8
ntrain = int(X.shape[0]*prop_train)
X_train, X_val = X[:ntrain], X[ntrain:]
y_train, y_val = y[:ntrain], y[ntrain:]
model =create_model(12,640,32)
for j in np.arange(1):
for i in np.arange(X_train.shape[0]):
print(i)
model.reset_states()
history=model.train_on_batch(X_train[i], y_train[i])
Here I got the error
ValueError: Input arrays should have the same number of samples as target arrays. Found 12 input samples and 1 target samples