Giter Site home page Giter Site logo

Comments (6)

mrocklin avatar mrocklin commented on August 26, 2024

from dask-searchcv.

AlexSchuy avatar AlexSchuy commented on August 26, 2024

The following code using dask_searchcv.GridSearchCV crashes, but if you comment-out the dask_searchcv import and uncomment the sklearn import, it runs.

from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split

from dask_searchcv import GridSearchCV
#from sklearn.model_selection import GridSearchCV

def simple_nn(hidden_neurons):
  model = Sequential()
  model.add(Dense(hidden_neurons, activation='relu', input_dim=30))
  model.add(Dense(1, activation='sigmoid'))
  model.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
  return model

param_grid = {'hidden_neurons': [100, 200, 300]}
cv = GridSearchCV(KerasClassifier(build_fn=simple_nn), param_grid)
X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y)
cv.fit(X_train, y_train)
score = cv.score(X_test, y_test)
print('score = {} on train set with params={}.'.format(score, cv.best_params_))

from dask-searchcv.

mrocklin avatar mrocklin commented on August 26, 2024

from dask-searchcv.

AlexSchuy avatar AlexSchuy commented on August 26, 2024

File "kerasexample.py", line 21, in
cv.fit(X_train, y_train)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/dask_searchcv/model_selection.py", line 867, in fit
out = scheduler(dsk, keys, num_workers=n_jobs)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/dask/threaded.py", line 75, in get
pack_exception=pack_exception, **kwargs)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/dask/local.py", line 521, in get_async
raise_exception(exc, tb)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/dask/local.py", line 290, in execute_task
result = _execute_task(task, data)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/dask/local.py", line 271, in _execute_task
return func(*args2)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/dask_searchcv/methods.py", line 280, in fit_and_score
fields, params, fit_params)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/dask_searchcv/methods.py", line 216, in fit
est.fit(X, y, **fit_params)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/keras/wrappers/scikit_learn.py", line 203, in fit
return super(KerasClassifier, self).fit(x, y, **kwargs)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/keras/wrappers/scikit_learn.py", line 147, in fit
history = self.model.fit(x, y, **fit_args)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/keras/models.py", line 960, in fit
validation_steps=validation_steps)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/keras/engine/training.py", line 1657, in fit
validation_steps=validation_steps)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/keras/engine/training.py", line 1213, in _fit_loop
outs = f(ins_batch)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 2357, in call
**self.session_kwargs)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 889, in run
run_metadata_ptr)
File "/phys/users/schuya/.local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1067, in _run
+ e.args[0])
TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("dense_1_input:0", shape=(?, 30), dtype=float32) is not an element of this graph.

from dask-searchcv.

mrocklin avatar mrocklin commented on August 26, 2024

I believe that TensorFlow may have an issue where it doesn't like running in multiple Python threads. cc @bnaul who has dealt with this before. You might also want to do a web search on TensorFlow, Python, and Threads.

from dask-searchcv.

mrocklin avatar mrocklin commented on August 26, 2024

To answer your original question. To use Dask with the multi-threading scheduler your code should be able to be run in multiple threads (most code is, just not TensorFlow). To use Dask with the multiprocessing or distributed schedulers your code should be able to be serialized (most code is). You can always use Dask with the single-threaded scheduler if you want to see how things work out. To try this run the following line:

dask.set_options(get=dask.local.get_sync)

from dask-searchcv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.