【问题标题】:How do I feed data into this model? [closed]如何将数据输入此模型? [关闭]
【发布时间】:2018-07-17 06:10:35
【问题描述】:

目前,我正在制作一个输入翼型图像文件并输出其升力系数的 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')

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

【问题讨论】:

  • 你需要让这个例子可以重现。 stackoverflow.com/help/mcve
  • 这也是统计问题还是编程问题?您是否遇到了可以通过编程知识解决的语法或其他错误?
  • 我会将其切换到统计数据。我只是认为具有 ML 知识的人会知道如何做到这一点。另外,我想我的问题应该改为“如何在这个回归问题中标记数据?”谢谢!

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


【解决方案1】:

从 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)

【讨论】:

  • 我唯一遇到的问题是它是一个回归问题。因此,我需要用输出标记我的数据,但我不知道该怎么做。
  • 你的意思是你有未标记的数据?
  • 对于监督学习,必须有 对来学习。如果您有标记数据,可以尝试检查线性回归briandolhansky.com/blog/…。您的输出值将是一个整数输出。
  • 正如您在问题中提到的那样,您输入的是一个尺寸为 shape(100,100,1) 的图像,并且每个图像的值都是 dtype='int32' 输出将是单个值即 dtype='int32' 的密集函数的输出或基于您期望输出的值范围的更大数据类型的输出
猜你喜欢
  • 2018-08-09
  • 1970-01-01
  • 2019-05-15
  • 1970-01-01
  • 1970-01-01
  • 2015-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多