image-processing - 如何将多个图像作为输入提供给卷积神经网络
问题描述
我对CNN很陌生。我计划构建一个分类器,您将在其中将两个图像作为输入提供给分类器。它应该输出它是否“匹配”。
我不确定从哪里开始以及如何输入两个图像并训练神经网络。如果您可以发布示例代码,那将有很大帮助。请帮忙
谢谢你
解决方案
您首先需要获取这两个图像并将它们放入一个数组中。因此,如果每个图像都是 26x26,那么阵列形状应该是 2x26x26。现在您必须将这些数组中的每一个都放入您的训练数据数组中,但请确保在训练之前将您的训练数据数组重塑为 26x26x2。您可以通过键入numpy.array(your_array_.reshape(-1, 26, 26, 2)
您的 fit 函数输入来执行此操作。
这是一个例子:
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)
推荐阅读
- c++ - 在 Visual Studio 2019 中使用 Qt 时出错
- python - 如何在 python 中使用 ccxt 制作币安期货订单?
- r - 如何仅将 lapply 用于函数的一个特定参数?
- android - 应用程序图标徽章未显示 Android
- android - 如何在 Android 中从 JSON 中提取数据
- ruby-on-rails - 使用 Rails 6 获取未定义的方法“add_role”,使用 UUID 进行 Rolify
- machine-learning - 强化学习收敛于平均损失,但不是针对每个训练数据
- google-apps-script - 将行内容移动到 Google 表格中的下一个打开行
- c++ - 使用 TBB 并行创建向量
- flutter - 在 Flutter 中显示小吃店