image - 如何使用 Inception Network 进行回归
问题描述
我正在尝试输入图像并获得一个连续数字作为输出。
我构建了一个神经网络,它在隐藏层中仅使用一个节点获取图像,并具有线性激活函数。但是,该模型为给定的输入预测相同的数字。
因此,我想使用 Inception Network 来解决这个问题。基于谷歌最近的一篇论文。
链接:https ://arxiv.org/pdf/1904.06435.pdf
x =密集(1,激活=“线性”)(x)
解决方案
这是绝对可能的!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(...)
这只是训练新的顶层,如果您想微调较低的层,请查看文档中的示例。
推荐阅读
- ruby - 如何使用 Minitest 测试命令行 gem
- javascript - 使用 Brave 浏览器的 Puppeteer?
- react-native - Expo + React Native:升级Expo时OTA更新?
- python - Selenium Web 抓取错误:元素不可交互
- google-sheets - 在 Google 表格中,如何根据在不同列中拆分字符串的结果汇总值(MAX、MIN、AVERAGE)?
- flutter - Flutter:无法检测应用程序是否销毁(AppLifecycleState.detached)
- flutter - Effective Dart 警告避免使用 forEach。使用内置 for-in 代替
- php - MWException Global Default '' 对于字段 liberty-dark 无效
- java - 接收输入后如何通知所有线程
- python - 为什么配置后记录器消失了?