首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >学习率的GridSearchCV

学习率的GridSearchCV
EN

Stack Overflow用户
提问于 2020-07-31 02:26:21
回答 1查看 1.3K关注 0票数 0

我试图使用GridSearchCV在CNN中找到最佳参数,但当我试图找到学习率和批量大小的最佳组合时,代码不起作用(如果我使用学习率而不是学习率,那么它就会起作用)。你知道为什么它不工作吗?

代码语言:javascript
复制
# NEURAL NETWORK
# ======================================================================================================================
# region Now we build and train the CNN=================================================================================
vgg16_model = keras.applications.vgg16.VGG16()  # We import VGG16 model to copy f rom it the structure


def create_model():
    model = Sequential()  # We create our model with Sequential
    for layer in vgg16_model.layers:  # For each layer of VGG16 we add the same layer to our model
        model.add(layer)

    model.layers.pop()  # We remove the last layer to change it to what we need
    for layers in model.layers:  # We make the layers comming from VGG16 not trainables
        layers.trainable = False

    model.add(Dense(2, activation='softmax'))  # We add the last layer to have only 2 outputs: Cracked, Uncracked
    opt = Adam(lr=lrn_rate)
    model.compile(optimizer = opt, loss='categorical_crossentropy', metrics=['accuracy'])

    return model


model = KerasClassifier(build_fn=create_model,epochs=2, verbose=0)


# ====================================================================================
# define the grid search parameters
batch_size = [16, 32]
# epochs = [2,5]
lr=[0.1,0.2]
param_grid = dict(batch_size=batch_size, learn_rate=lr)
grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=1, cv=3)

X, Y = train_batches.next()    # Batch of images to be analyzed
#grid_result = grid.fit_generator(train_imgs, train_labels )

grid_result = grid.fit(X,Y)

我得到的错误是'ValueError: learn_rate不是一个合法的参数‘,但我这样做了,就像我在一个例子中发现的那样,它适用于纪元,但不适用于学习率。

EN

回答 1

Stack Overflow用户

发布于 2021-02-08 23:56:17

尝试: def create_model(lrn_rate):

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63179185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档