tensorflow / skflow

Simplified interface for TensorFlow (mimicking Scikit Learn) for Deep Learning
Apache License 2.0
3.18k stars 439 forks source link

GridSearchCV is not work in TensorFlowDNNClassifier #42

Closed HiuNaoki closed 8 years ago

HiuNaoki commented 8 years ago

Hello

I try DNNMetaParameter optimization using GridSearchCV..

but not wok it

Statck Trace..

File "/usr/local/lib/python2.7/site-packages/sklearn/grid_search.py", line 804, in fit return self._fit(X, y, ParameterGrid(self.param_grid)) File "/usr/local/lib/python2.7/site-packages/sklearn/grid_search.py", line 553, in _fit for parameters in parameter_iterable File "/usr/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 804, in call while self.dispatch_one_batch(iterator): File "/usr/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 662, in dispatch_one_batch self._dispatch(tasks) File "/usr/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 570, in _dispatch job = ImmediateComputeBatch(batch) File "/usr/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 183, in init self.results = batch() File "/usr/local/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 72, in call return [func(_args, *_kwargs) for func, args, kwargs in self.items] File "/usr/local/lib/python2.7/site-packages/sklearn/cross_validation.py", line 1531, in _fit_and_score estimator.fit(X_train, y_train, **fit_params) File "/usr/local/lib/python2.7/site-packages/skflow/init.py", line 163, in fit self._setup_training() File "/usr/local/lib/python2.7/site-packages/skflow/init.py", line 113, in _setup_training self._inp, self._out) File "/usr/local/lib/python2.7/site-packages/skflow/models.py", line 73, in dnn_estimator layers = dnn(X, hidden_units) File "/usr/local/lib/python2.7/site-packages/skflow/ops/dnn_ops.py", line 41, in dnn for i, n_units in enumerate(hidden_units): TypeError: 'NoneType' object is not iterable

Problem

"hidden_units" is None Type in GridSearchCV

"hidden_units" is member of TensorFlowEstimator but not member of TensorFlowDNNClassifier

https://github.com/google/skflow/blob/master/skflow/__init__.py#L415

GridSearchCV can'find "hidden_units"

HiuNaoki commented 8 years ago

information

http://scikit-learn.org/stable/developers/contributing.html#parameters-and-init

ilblackdragon commented 8 years ago

Ic, the problem currently is that model_fn is called in the __init__ and that is where hidden_state variable is captured inside the closure. I didn't realize that meta optimizers use set_params for their operations. Some underlaying design needs to be altered for this to work corrently.

HiuNaoki commented 8 years ago

Thank you for your support!