首页 > 解决方案 > 如何使用 Inception Network 进行回归

问题描述

我正在尝试输入图像并获得一个连续数字作为输出。

我构建了一个神经网络,它在隐藏层中仅使用一个节点获取图像,并具有线性激活函数。但是,该模型为给定的输入预测相同的数字。

因此,我想使用 Inception Network 来解决这个问题。基于谷歌最近的一篇论文。

链接:https ://arxiv.org/pdf/1904.06435.pdf

x =密集(1,激活=“线性”)(x)

标签: imagemachine-learningdeep-learningregressionconv-neural-network

解决方案


这是绝对可能的!keras 文档中关于预训练模型的示例应该可以帮助您完成工作。确保调整输出层和新模型的损失。

编辑:您的特定案例的代码示例

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(...)

这只是训练新的顶层,如果您想微调较低的层,请查看文档中的示例


推荐阅读