I am using Keras to create an ANN and do a grid search on the network. I have encountered the following error while running the code below:
model = KerasClassifier(build_fn=create_model(input_dim), verbose=0)
# define the grid search parameters
batch_size = [10, 20]
epochs = [50, 100]
dropout = [0.3, 0.5, 0.7]
param_grid = dict(dropout_rate=dropout, batch_size=batch_size, nb_epoch=epochs)
pipe.append(('classify', model))
params.append(param_grid)
pipeline=Pipeline(pipe)
#the pipeline also contains feature selector, but for convenience I do not include code here
piped_classifier = GridSearchCV(estimator=pipeline, param_grid=params, n_jobs=-1,cv=nfold)
piped_classifier.fit(X_train, y_train) #this is line 246 of classifier_gridsearch.py causing error, see below,def create_model(input_dim,dropout_rate=0.0):# create modelmodel = Sequential()model.add(Dense(80,input_dim=input_dim,kernel_initializer='uniform', activation='relu'))model.add(Dropout(dropout_rate))model.add(Dense(1, kernel_initializer='uniform', activation='sigmoid'))# Compile modelmodel.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])return model
The error of line 246 throws an error as below, with a long stacktrace:
Traceback (most recent call last):File "/home/zqz/Work/chase/python/src/exp/classifier_gridsearch_main.py", line 176, in <module>classifier.gridsearch()File "/home/zqz/Work/chase/python/src/exp/classifier_gridsearch_main.py", line 155, in gridsearchself.fs_option,self.fs_gridsearch)File "/home/zqz/Work/chase/python/src/ml/classifier_gridsearch.py", line 246, in learn_dnnpiped_classifier.fit(X_train, y_train)File "/home/zqz/Programs/anaconda3/lib/python3.6/site-packages/sklearn/model_selection/_search.py", line 945, in fitreturn self._fit(X, y, groups, ParameterGrid(self.param_grid))File "/home/zqz/Programs/anaconda3/lib/python3.6/site-packages/sklearn/model_selection/_search.py", line 550, in _fitbase_estimator = clone(self.estimator)File "/home/zqz/Programs/anaconda3/lib/python3.6/site-packages/sklearn/base.py", line 69, in clonenew_object_params[name] = clone(param, safe=False)File "/home/zqz/Programs/anaconda3/lib/python3.6/site-packages/sklearn/base.py", line 57, in clonereturn estimator_type([clone(e, safe=safe) for e in estimator])File "/home/zqz/Programs/anaconda3/lib/python3.6/site-packages/sklearn/base.py", line 57, in <listcomp>return estimator_type([clone(e, safe=safe) for e in estimator])File "/home/zqz/Programs/anaconda3/lib/python3.6/site-packages/sklearn/base.py", line 57, in clonereturn estimator_type([clone(e, safe=safe) for e in estimator])File "/home/zqz/Programs/anaconda3/lib/python3.6/site-packages/sklearn/base.py", line 57, in <listcomp>return estimator_type([clone(e, safe=safe) for e in estimator])File "/home/zqz/Programs/anaconda3/lib/python3.6/site-packages/sklearn/base.py", line 69, in clonenew_object_params[name] = clone(param, safe=False)File "/home/zqz/Programs/anaconda3/lib/python3.6/site-packages/sklearn/base.py", line 60, in clonereturn copy.deepcopy(estimator)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 180, in deepcopyy = _reconstruct(x, memo, *rv)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 280, in _reconstructstate = deepcopy(state, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 150, in deepcopyy = copier(x, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 240, in _deepcopy_dicty[deepcopy(key, memo)] = deepcopy(value, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 150, in deepcopyy = copier(x, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 215, in _deepcopy_listappend(deepcopy(a, memo))File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 180, in deepcopyy = _reconstruct(x, memo, *rv)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 280, in _reconstructstate = deepcopy(state, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 150, in deepcopyy = copier(x, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 240, in _deepcopy_dicty[deepcopy(key, memo)] = deepcopy(value, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 150, in deepcopyy = copier(x, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 215, in _deepcopy_listappend(deepcopy(a, memo))File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 180, in deepcopyy = _reconstruct(x, memo, *rv)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 280, in _reconstructstate = deepcopy(state, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 150, in deepcopyy = copier(x, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 240, in _deepcopy_dicty[deepcopy(key, memo)] = deepcopy(value, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 180, in deepcopyy = _reconstruct(x, memo, *rv)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 280, in _reconstructstate = deepcopy(state, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 150, in deepcopyy = copier(x, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 240, in _deepcopy_dicty[deepcopy(key, memo)] = deepcopy(value, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 180, in deepcopyy = _reconstruct(x, memo, *rv)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 280, in _reconstructstate = deepcopy(state, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 150, in deepcopyy = copier(x, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 240, in _deepcopy_dicty[deepcopy(key, memo)] = deepcopy(value, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 180, in deepcopyy = _reconstruct(x, memo, *rv)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 280, in _reconstructstate = deepcopy(state, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 150, in deepcopyy = copier(x, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 240, in _deepcopy_dicty[deepcopy(key, memo)] = deepcopy(value, memo)File "/home/zqz/Programs/anaconda3/lib/python3.6/copy.py", line 169, in deepcopyrv = reductor(4)
TypeError: can't pickle _thread.lock objects
Any suggestions how to fix this please, thanks