如何将多个图像作为卷积神经网络的输入
How to feed multiple images as input to a Convolutional Neural network
我是 CNN 的新手。我计划构建一个分类器,您将在其中将两张图像作为分类器的输入。它应该输出它是否是 "match" .
我不确定从哪里开始以及如何输入两张图像和训练神经网络。如果您能 post 一个示例代码,那将会很有帮助。请帮助
谢谢
您首先需要将两张图片取出并放入一个数组中。因此,如果每个图像都是 26x26,那么数组形状应该是 2x26x26。现在您必须将这些数组中的每一个都放入您的训练数据数组中,但请确保在您开始训练之前将您的训练数据数组重塑为 26x26x2。您可以通过在拟合函数输入中输入 numpy.array(your_array_.reshape(-1, 26, 26, 2)
来执行此操作。
这是一个例子:
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)
我是 CNN 的新手。我计划构建一个分类器,您将在其中将两张图像作为分类器的输入。它应该输出它是否是 "match" .
我不确定从哪里开始以及如何输入两张图像和训练神经网络。如果您能 post 一个示例代码,那将会很有帮助。请帮助
谢谢
您首先需要将两张图片取出并放入一个数组中。因此,如果每个图像都是 26x26,那么数组形状应该是 2x26x26。现在您必须将这些数组中的每一个都放入您的训练数据数组中,但请确保在您开始训练之前将您的训练数据数组重塑为 26x26x2。您可以通过在拟合函数输入中输入 numpy.array(your_array_.reshape(-1, 26, 26, 2)
来执行此操作。
这是一个例子:
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)