I am trying to understand the implementation of a Siamese Network in PyTorch. In particular, I am confused as to why we are able to run two images through the same model twice. In examples such as these:
it seems like the default way to do this in PyTorch is something like (for example):
my question is, why can we run two input images through the same layers twice? I understand that in a Siamese network both legs should share the same parameters, but in torch aren’t the local gradients at each layer computed during the forward pass? Wouldn’t running the second image through the network remove the local gradients from the first image and ruin the backpropogation step?
Clearly, this isn’t the case but I’d love to understand why.