Tensorflow中使用gridsearch
1 使用tf.contrib.learn.estimators
使用tf中自帶的Estimator將自定義的tf模型轉換成估計器,輸入到sklearn中的gridesearch運行。
# My custom model.
# Feature request: New params dict with values filled by GridSearchCV
def cnn_model(X, Y, params):
stride = params['stride']
... custom model definition here ...
# Create the Convnet classifier
cnn_classifier = learn.TensorFlowEstimator(model_fn=cnn_model)
# Grid search on different stride values.
parameters = {'stride': [1, 2, 3],}
grid_searcher = GridSearchCV(cnn_classifier, parameters)
grid_searcher.fit(X, Y)
可能的報錯
WARNING:tensorflow:Using temporary folder as model directory: C:\Users\piting.pt\AppData\Local\Temp\tmpufiz6_ts
[Pass grid search params to TensorFlowEstimator custom model #2030 ]
這種方式需要使用到tf.contrib.learn中的estimators,比較麻煩。未測試出來。
[Creating Estimators in tf.contrib.learn ]
2 直接將自定義的模型修改成具有sklearn中estimators的功能
from: -柚子皮-
ref: