It is not very clear, what class of images you have.
You have to use triple loss to compare the images and get the related images.
Refer Deep Learning Coursera course, Convolutional neural networks Week 4 classes, to understand the background.
- Build a model to predict the right class. Ex: Dog, Cat, Iron Man, Superman etc (or Use pretrained model)
- For reach image, get the last but one layer weights and flatten it into a matrix
- When a new image is fed, get the flattened matrix of it using feedforward mechanism.
- Calculate distance between new image matrix vs the ones already in the database. All the images with shortest distance to new image can be pulled out from the point 2 database.
I can help you in pointing to right code, if you confirm the approach works for you.