Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison between two images #1

Open
riclab opened this issue Nov 29, 2016 · 3 comments
Open

Comparison between two images #1

riclab opened this issue Nov 29, 2016 · 3 comments

Comments

@riclab
Copy link

riclab commented Nov 29, 2016

Hi, is it possible to make a comparison between two images getting a percentage?

Thanks.

@aleju
Copy link
Owner

aleju commented Nov 30, 2016

There isn't a function for that, but it shouldn't be hard to implement. Assuming you have trained the model and the weights were saved under filepath weights_fp and your images are at filepaths img1_fp and img2_fp, then the process should roughly be (not tested):

from scipy import ndimage
from skimage import color
from train import create_model

# create the model
model = create_model() # that function is in train.py

# load trained weights
model.load_weights(weights_fp)

# load images
img1 = ndimage.imread(img1_fp, mode="RGB")
img2 = ndimage.imread(img2_fp, mode="RGB")

# resize images
img1_rs = misc.imresize(img1, (32, 32))
img2_rs = misc.imresize(img2, (32, 32))

# convert images to grayscale images with shape (height, width, 1) in value range 0 to 1.0
img1_gray = color.rgb2gray(img1_rs)[:, :, np.newaxis]
img2_gray = color.rgb2gray(img2_rs)[:, :, np.newaxis]

# convert images to batches
img1_batch = np.array([img1_gray])
img2_batch = np.array([img2_gray])

# predict their similarity
preds = model.predict([img1_batch, img2_batch])

# print similarity
print("Similarity: %.2f" % (preds[0],))

@riclab
Copy link
Author

riclab commented Nov 30, 2016

Thank you, Alexander!

@shubhpy
Copy link

shubhpy commented Nov 23, 2017

@riclab Did you run the script?
It is throwing error "Can't open attribute (can't locate attribute: 'layer_names')" on model.load_weights step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants