我想用以下输入和输出创建模型。
-输入:图像和值
-输出:值(回归)
使用flow_from_dataframe读取输入图像以进行扩充。
然后将输入值从csv文件加载到数据帧。
我正在尝试使其成为2输入->串联-> 1输出。
但是我无法在2种不同类型的输入上使用它。
也许我应该制造一个新的发电机。.但是我找不到办法。
感谢您的任何建议或帮助。
这是我的一些代码。
train_df = pd.read_csv("train.csv")
test_df = pd.read_csv("test.csv")
file_num = train_df.loc[:,'NUM']
value = train_df.loc[:,'VALUE']
# ------------------------------------------
train_datagen=ImageDataGenerator(rescale=1./255.,
rotation_range=90,
validation_split=0.1)
test_datagen=ImageDataGenerator(rescale=1./255.)
train_img=train_datagen.flow_from_dataframe(
dataframe=train_df,
directory="./DATA_train/",
x_col='NUM',
y_col='VALUE',
subset="training",
batch_size=16,
seed=4,
shuffle=True,
class_mode="other",
target_size=TARGET_SIZE)
valid_img=train_datagen.flow_from_dataframe(
dataframe=train_df,
directory="./DATA_train/",
x_col='NUM',
y_col='VALUE',
subset="validation",
batch_size=4,
seed=4,
shuffle=True,
class_mode="other",
target_size=TARGET_SIZE)
test_img=test_datagen.flow_from_dataframe(
dataframe=test_df,
directory="./DATA_test/",
x_col='NUM',
y_col='VALUE',
batch_size=1,
shuffle=False,
class_mode=None,
target_size=TARGET_SIZE)
max_val = train_df.loc[:,'VALUE'].max()
min_val = train_df.loc[:,'VALUE'].min()
train_val = (train_df.loc[:,'VALUE']-min_val) / (max_val - min_val)
# ------------------------------------------
inputs_image = Input(shape=(64,64,1))
inputs_val = Input(shape=(1,))
x1 = Conv2D(32, (3,3), activation='relu')(inputs_image)
x1 = BatchNormalization()(x1)
x1 = Flatten()(x1)
x1 = Dense(64, activation='relu')(x1)
x1 = Model(inputs=inputs_image, outputs=x1)
x2 = Dense(256, activation='relu')(inputs_mass)
x2 = Dense(64, activation='relu')(x2)
x2 = Model(inputs=inputs_mass, outputs=x2)
combined = layers.concatenate([x1.output,x2.output], axis=-1)
combined = Dense(128, activation='relu')(combined)
outputs = Dense(1, activation='linear')(combined)
model = Model([inputs_image, inputs_val], outputs)
model.compile(optimizer='adam', loss='mean_squared_error', metrics = ['mae'])
# ------------------------------------------
hist = model.fit_generator(generator=train_img, ## This should be modified..??
steps_per_epoch=STEP_SIZE_TRAIN*1,
validation_data=valid_img,
validation_steps=STEP_SIZE_VALID,
epochs = EPOCHS,
verbose=1
)