2

I am pretty new to CNN. I am planning to build a classifier where you will be feeding two images as input to the classifier. And it should output whether its a "match" or not .

I am not sure where to start and how to feed two images and train the neural networks. It would of great help if you can post a sample code. Please help

Thank You

1 Answers1

2

You first need to take the two images and put them into an array. So if each image is 26x26 the array shape should then be 2x26x26. Now you must put each of these arrays into you training data array, BUT make sure that you reshape your training data array to 26x26x2 before you hit train. You can do this by typing in numpy.array(your_array_.reshape(-1, 26, 26, 2) to your fit function input.

Here is an example:

import numpy as np

image1 = # put your image array here
image2 = # put other image array here
both_images = [image1, image2]

training_data.append(both_images) # Feel free to add as much training data as you would like

same = 0
labels = [same]

model = create_model() # Make a function to create your model and set your model to a variable

model.fit(np.array(training_data).reshape(-1, 26, 26, 2), np.array(labels), batch_size=32)