我正在尝试输入图像并获得一个连续的数字作为输出。
我构建了一个神经网络,该网络使用线性激活功能仅在隐藏层中的单个节点上拍摄图像。但是,模型为给定的输入预测相同的数字。
因此,我想使用Inception Network解决此问题。根据Google最近的一篇论文。
链接:https://arxiv.org/pdf/1904.06435.pdf
x =密集(1,激活=“线性”)(x)
答案 0 :(得分:-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。