I used Pytorch to create 3DCNN
I used the gridsearch function to choose the parameters of the model.
I found this error !
can you help me ?
thank you in advance!
batch_size = [5, 10]
epochs = [50, 100, 500]
learn_rate = [0.01, 0.001, 0.0001, 0.00001, 0.000001]
param_grid = dict(batch_size=batch_size, epochs=epochs, learn_rate=learn_rate)
grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=1,cv=3)
grid_result = grid.fit(data,targets)
print("Best: %f using %s" % (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))

Result
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-ccbe836e4806> in <module>
    147 param_grid = dict(batch_size=batch_size, epochs=epochs, learn_rate=learn_rate)
    148 grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=1,cv=3)
--> 149 grid_result = grid.fit(data,targets)
    150 print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))
    151 means = grid_result.cv_results_['mean_test_score']

/opt/tljh/user/envs/fethi_env/lib/python3.6/site-packages/sklearn/utils/validation.py in inner_f(*args, **kwargs)
     70                           FutureWarning)
     71         kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 72         return f(**kwargs)
     73     return inner_f
     74 

/opt/tljh/user/envs/fethi_env/lib/python3.6/site-packages/sklearn/model_selection/_search.py in fit(self, X, y, groups, **fit_params)
    653 
    654         scorers, self.multimetric_ = _check_multimetric_scoring(
--> 655             self.estimator, scoring=self.scoring)
    656 
    657         if self.multimetric_:

/opt/tljh/user/envs/fethi_env/lib/python3.6/site-packages/sklearn/metrics/_scorer.py in _check_multimetric_scoring(estimator, scoring)
    473     if callable(scoring) or scoring is None or isinstance(scoring,
    474                                                           str):
--> 475         scorers = {"score": check_scoring(estimator, scoring=scoring)}
    476         return scorers, False
    477     else:

/opt/tljh/user/envs/fethi_env/lib/python3.6/site-packages/sklearn/utils/validation.py in inner_f(*args, **kwargs)
     70                           FutureWarning)
     71         kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 72         return f(**kwargs)
     73     return inner_f
     74 

/opt/tljh/user/envs/fethi_env/lib/python3.6/site-packages/sklearn/metrics/_scorer.py in check_scoring(estimator, scoring, allow_none)
    401     if not hasattr(estimator, 'fit'):
    402         raise TypeError("estimator should be an estimator implementing "
--> 403                         "'fit' method, %r was passed" % estimator)
    404     if isinstance(scoring, str):
    405         return get_scorer(scoring)

TypeError: estimator should be an estimator implementing 'fit' method, CNNModel(
  (conv_layer1): Sequential(
    (0): Conv3d(3, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (1): LeakyReLU(negative_slope=0.01)
    (2): MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2), padding=0, dilation=1, ceil_mode=False)
  )
  (conv_layer2): Sequential(
    (0): Conv3d(32, 64, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (1): LeakyReLU(negative_slope=0.01)
    (2): MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2), padding=0, dilation=1, ceil_mode=False)
  )
  (fc1): Linear(in_features=1404928, out_features=2, bias=True)
  (fc2): Linear(in_features=1404928, out_features=2, bias=True)
  (relu): LeakyReLU(negative_slope=0.01)
  (batch): BatchNorm1d(2, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  (drop): Dropout(p=0.15, inplace=True)
) was passed