【问题标题】:How to use Inception Network for Regression如何使用 Inception Network 进行回归
【发布时间】:2020-02-25 20:56:44
【问题描述】:
我正在尝试输入图像并获得一个连续数字作为输出。
我构建了一个神经网络,它使用一个线性激活函数获取隐藏层中只有一个节点的图像。但是,该模型为给定的输入预测相同的数字。
因此我想使用 Inception Network 来解决这个问题。基于 Google 最近的一篇论文。
链接:https://arxiv.org/pdf/1904.06435.pdf
x = Dense(1, activation="linear")(x)
【问题讨论】:
标签:
image
machine-learning
deep-learning
regression
conv-neural-network
【解决方案1】:
这绝对是可能的! keras 文档中关于预训练模型的example 应该可以帮助您完成工作。确保调整输出层和新模型的损失。
编辑:具体案例的代码示例
from keras.applications.inception_v3 import InceptionV3
from keras.preprocessing import image
from keras.models import Model
from keras.layers import Dense
from keras import backend as K
# create the base pre-trained model
base_model = InceptionV3(weights='imagenet', include_top=False)
# add a global spatial average pooling layer
x = base_model.output
# let's add a fully-connected layer
x = Dense(1024, activation='relu')(x)
# and a linear output layer
prediction = Dense(1, activation='linear')(x)
# this is the model we will train
model = Model(inputs=base_model.input, outputs=prediction)
# first: train only the top layers (which were randomly initialized)
# i.e. freeze all convolutional InceptionV3 layers
for layer in base_model.layers:
layer.trainable = False
# compile the model (should be done *after* setting layers to non trainable)
model.compile(optimizer='rmsprop', loss='mean_squared_error')
# train the model on the new data for a few epochs
model.fit_generator(...)
这只是训练新的顶层,如果您还想微调较低的层,请查看文档中的example。