如何在Keras中使用fit_generator实现Scikit GridSerachCV

时间:2019-01-30 09:04:26

标签: python keras scikit-learn hyperparameters

我想在此GitHub repository上使用scikit-wrapper GirdSearchCV执行超参数扫描。

我正尝试使用scikit-wrapper运行GridSearchCV:

from sklearn.model_Selection import GridSearchCV
from keras.wrappers.sckit_learn import KerasClassifier

#After the compile in frontend.py
model = KerasClassifier(build_fn = TinyYoloFeature, verbose = 0) #TinyYoloFeature is in backend.py

#After the above command in frontend.py
batch_size = [16,32,64]
learning rate = [0.001, 0.0001, 0.00001]
param_grid = dict (epcohs = nb_epochs,
                   batch_size = batch_size)
grid = GridSearchCV(estimator=model, param_grid = param_grid,n_jobs=-1)
grid_result = grid.fit() #How to go about ????

#print result
print ("Best: %f using %s using %
(grid_result.best_score_,grid_result.best_params_,)
means = grid_result.cv_results_['mean_test_score']
stds = grid_result.cv_results_['std_test_score']
params = grid_result.cv_results_['params']  
for mean, stdev, param in zip (means, stds, params):
print("%f (%f) with: %r" %(mean, stdev, param))  

但是代码使用fit_genrator。在线上所有的支持都与model.fit有关。有人可以帮忙吗?

0 个答案:

没有答案