必威体育Betway必威体育官网
当前位置:首页 > IT技术

finetune模型例子

时间:2019-08-31 20:40:00来源:IT技术作者:seo实验室小编阅读:90次「手机版」
 

finetune

from keras.APPlications.inception_v3 import InceptionV3
from keras.preprocessing import image
from keras.models import Model
from keras.layers import Dense, GlobalaveragePooling2D
from keras import backend as K
# create the base pre-trained model
base_model = InceptionV3(weights='imagenet', include_top=False)
base_model.summary()

# add a global spatial average pooling layer
x = base_model.output
x = GlobalAveragePooling2D()(x)
# let's add a fully-connected layer
x = Dense(1024, activation='relu')(x)
# and a logistic layer -- let's say we have 200 classes
predictions = Dense(200, activation='softmax')(x)

# this is the model we will train
model = Model(input=base_model.input, output=predictions)

# 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='categorical_crossentropy')
model.fit_generator(....)
# at this point, the top layers are well trained and we can start fine-tuning
# convolutional layers from inception V3. We will freeze the bottom N layers
# and train the remaining top layers.

# let's visualize layer names and layer indices to see how many layers
# we should freeze:
for i, layer in enumerate(base_model.layers):
   print(i, layer.name)
# we chose to train the top 2 inception blocks, i.e. we will freeze
# the first 172 layers and unfreeze the rest:
for layer in model.layers[:172]:
   layer.trainable = False
for layer in model.layers[172:]:
   layer.trainable = True
# we need to recompile the model for these modifications to take effect
# we use SGD with a low learning rate
from keras.optimizers import SGD
model.compile(optimizer=SGD(lr=0.0001, momentum=0.9), loss='categorical_crossentropy')
model.fit_generator(....)

相关阅读

评估客户价值的三种模型:RFM、CLV、顾客社交价值模型

笔者一直从事于用户运营领域,很多情况下都是要在资源有限情况下,去最大化的撬动效益,如何挖掘能创造最大价值的客户就是用户运营的最

数据分析逻辑:流量转化漏斗模型详解

数据分析能够帮助我们更好地进行运营决策,数据分析能够很好的为转化用户提供参考与数据支撑。商业领域的数据分析,就是为了给商业行

瀑布模型项目中的需求分析之道(一)

在瀑布模型项目中,需求分析的质量直接决定了整个项目的完成质量。需求人员需要尽早的将项目需求和客户及内部开发团队达成一致,并做

案例分析:基于RFM的客户价值分析模型

一、背景与目标1.1 背景在面向客户制定运营策略、营销策略时,我们希望能够针对不同的客户推行不同的策略,实现精准化运营,以期获取最

基于RBAC模型的权限设计:如何设计系统权限体系?

RBAC目前使用最为广泛的权限模型,笔者通过平常工作及工作外的积累,整理了几种比较经典的权限体系,希望对大家有所帮助!一、什么是RABC

分享到:

栏目导航

推荐阅读

热门阅读