如何将数据输入此模型?

时间:2018-02-07 03:38:05

标签: python-3.x machine-learning neural-network keras conv-neural-network

目前,我正在制作输入翼型图像文件的CNN,并输出其升力系数。模型本身是:

input_img = Input(shape(100,100,1), dtype='int32', name = 'img_input')

Layer = Conv2D(32,(3,3))(input_img)

Layer = MaxPooling2D((3,3))(Layer)

Layer = Conv2D(32,(3,3))(Layer)

Layer = MaxPooling2D((3,3))(Layer)

Layer = Flatten()(Layer)

Layer = Dense(32, activation = 'relu')(Layer)

end_out = Dense(1, kernel_initializer = 'normal')

model = Model(inputs=[img_input],outputs=[end_out])

model.compile(loss='mean_squared_error',optimizer='adam')

对我来说,似乎我必须将图像数据与输出数据配对,然后在配对的数据集上训练网络。但是,我不确定这是否是正确的方法,如果是,我不知道该怎么做。如何将此模型作为输入训练图像数据,将数值数据(升力系数)作为输出? 谢谢!

1 个答案:

答案 0 :(得分:0)

从Keras文档中,您必须符合数据并从数据中学习权重

# For a single-input model with 10 classes (categorical classification):

model = Sequential()
model.add(Dense(32, activation='relu', input_dim=100))
model.add(Dense(10, activation='softmax'))
model.compile(optimizer='rmsprop',
              loss='categorical_crossentropy',
              metrics=['accuracy'])

# Generate dummy data
import numpy as np
data = np.random.random((1000, 100))
labels = np.random.randint(10, size=(1000, 1))

# Convert labels to categorical one-hot encoding
one_hot_labels = keras.utils.to_categorical(labels, num_classes=10)

# Train the model, iterating on the data in batches of 32 samples
model.fit(data, one_hot_labels, epochs=10, batch_size=32)