python - 具有图像数据和预提取特征的 CNN 模型

标签 python machine-learning deep-learning keras conv-neural-network

我正在尝试实现一个CNN模型来将一些图像分类到相应的类别。图像尺寸为 64x64x3。我的数据集包含 25,000 张图像以及一个 CSV 文件,其中包含 14 个预先提取的特征,例如颜色、长度等。

我想构建一个 CNN 模型,利用图像数据和特征进行训练和预测。如何使用 KerasPython 中实现这样的模型?

最佳答案

我首先假设您可以毫无问题地导入数据,并且您已经将 x 数据分为图像和特征,并且将 y 数据作为每个图像的标签。

您可以使用 keras 功能 api 让神经网络接受多个输入。

from keras.models import Model
from keras.layers import Conv2D, Dense, Input, Embedding, multiply, Reshape, concatenate

img = Input(shape=(64, 64, 3))
features = Input(shape=(14,))
embedded = Embedding(input_dim=14, output_dim=60*32)(features)
embedded = Reshape(target_shape=(14, 60,32))(embedded)

encoded = Conv2D(32, (3, 3), activation='relu')(img)
encoded = Conv2D(32, (3, 3), activation='relu')(encoded)

x = concatenate([embedded, encoded], axis=1)
x = Dense(64, activation='relu')(x)
x = Dense(64, activation='relu')(x)
main_output = Dense(1, activation='sigmoid', name='main_output')(x)

model = Model([img, features], [main_output])

关于python - 具有图像数据和预提取特征的 CNN 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49833313/

相关文章:

python - GeoJSON 数据未显示在 Python folium map 中

python - 获取多变量模型中单个样本的分数?

python - numpy 数组上的多维矩阵乘法

python - 使用导出/重新加载模型 : "Input type and weight type should be the same" 进行 fastai 错误预测

lua - 重写 torch 中的 updateGradInput 方法不适用于我的自定义模块

python - mod_wsgi python conf解析器

python - 使用多个worker来执行python代码

python - Tensorflow RNN 单元权重共享

Python 3 - ValueError : not enough values to unpack (expected 3, 得到 2)

python - 如何训练 python 函数返回我想要的结果?