【发布时间】:2020-07-14 08:25:42
【问题描述】:
我正在处理一个包含 15 个类别的胸部 X 射线图像数据集。图像文件名保留在具有一些非图像值的 CSV 文件中。图像数据集分为训练、测试、验证。我使用 imagedatagenerator 来增强图像。
|---------------------|------------------|---------------|
| Image Index | Patient Gender | View Position |
|---------------------|------------------|---------------|
| 00008236_001.png | 1 | 0 |
|---------------------|------------------|---------------|
| 00016410_014.png | 0 | 1 |
|---------------------|------------------|---------------|
| 00014751_001.png | 1 | 0 |
|---------------------|------------------|---------------|
| 00020318_012.png | 1 | 1 |
|---------------------|------------------|---------------|
[[包含非图像特征的CSV文件(患者性别和胸部X光图像视图位置编码为{0,1})]
我想将这两列的值与 CNN 的扁平层连接起来。
我尝试了以下代码,但显示错误。
train_set_features = train_set[['View Position','Patient Gender']]
input_features =train_set_att.values # Shape=(90771, 2)
from keras.applications import *
from keras.layers import GlobalAveragePooling2D, Dense, Dropout, Flatten,Concatenate
from keras.models import Sequential
base_model = MobileNet( include_top=False,input_shape=(224,224,3))
x = base_model.output
x = Flatten()(x) #output shape = (None,7168)
non_image_features = Input(shape=[2,], name="non_image") #output shape = (None,2)
x= concatenate([x, non_image_features]) #output shape = (None,7170)
# and a logistic layer
predictions = Dense(15, activation="sigmoid",name='visualized_layer')(x)
model = Model(inputs=[base_model.input,non_image_features], outputs=predictions)
opt = Adam(learning_rate=0.001)
model.compile(optimizer=opt, loss='binary_crossentropy',metrics=['binary_accuracy','mae'])
history = model.fit_generator([train_generator,input_features ],
validation_data=valid_generator,
steps_per_epoch=100,
validation_steps=25,
epochs =64,)
predicted_values = model.predict_generator(test_generator, steps = len(test_generator))
这是用扁平层连接值的正确方法吗?
【问题讨论】:
标签: python-3.x tensorflow keras conv-neural-network