Your code looks like a classification task and I’m not sure where you are checking, if two images look similar or not.
I would recommend to scale down your use case a bit and try to overfit a small data sample (e.g. single batch) with your model and training routine.
If that doesn’t work, there might be a bug (I haven’s seen yet) or you would have to adapt e.g. the model architecture.
Is the last dropout layer on the model output on purpose or are you missing another linear layer?