Currently you are passing two tensors to your loss function, which don’t require gradients and are decoupled of your models.
last_Y1 is still the zero tensor, while Xt is the image you’ve captured using openCV.
Usually you would pass some model output as the first input and a target as the second input to your loss function. Could you check, what should be calculated in loss_S1?
Also a small side note: you should call the model directly and not the forward method: H1 = E1(Xt, last_Y1, last_H1).