我尝试将 Keras 模型(作为函数)从 scikit_learn 传递给 KerasClassifier 包装器,然后使用 GridSearchCV 创建一些设置,最后拟合训练和测试数据集(均为 numpy 数组)然后,我使用相同的 python 脚本,得到了不同的异常,其中一些是:_1.回溯(最近一次调用):文件“mnist_flat_imac.py”,第 63 行,在 grid_result = validator.fit(train_images, train_labels) 文件“/home/longnv/PYTHON_ENV/DataScience/lib/python3.5/site-packages/ sklearn/model_selection/_search.py”,第 626 行,适合 base_estimator = clone(self.estimator) 文件“/home/longnv/PYTHON_ENV/DataScience/lib/python3.5/site-packages/sklearn/base.py”,第 62 行,在 clone new_object_params[name] = clone(param, safe=False) 文件“/home/longnv/PYTHON_ENV/DataScience/lib/python3.5/site-packages/sklearn/base.py”,第 53 行,在克隆剪在这里在 _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) 文件“/home/longnv/PYTHON_ENV/DataScience/lib/python3.5/copy.py”,第 174 行,在 deepcopy rv = reductor(4 ) TypeError: can't pickle SwigPyObject objects Exception异常被忽略:> Traceback (最近一次调用最后一次): File "/home/longnv/PYTHON_ENV/DataScience/lib/python3.5/site-packages/tensorflow/python/framework/c_api_util .py”,第 52 行,在 __del__ c_api.TF_DeleteGraph(self.graph) AttributeError: 'ScopedTFGraph' object has no attribute 'graph'_2.回溯(最近一次调用):文件“mnist_flat_imac.py”,第 63 行,在 grid_result = validator.fit(train_images, train_labels) 文件“/home/longnv/PYTHON_ENV/DataScience/lib/python3.5/site-packages/ sklearn/model_selection/_search.py”,第 626 行,适合 base_estimator = clone(self.estimator) 文件“/home/longnv/PYTHON_ENV/DataScience/lib/python3.5/site-packages/sklearn/base.py”,第 62 行,在 clone new_object_params[name] = clone(param, safe=False) 文件“/home/longnv/PYTHON_ENV/DataScience/lib/python3.5/site-packages/sklearn/base.py”,第 53 行,在clone return copy.deepcopy(estimator) File "/home/longnv/PYTHON_ENV/DataScience/lib/python3.5/copy.py", line 182, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/home/longnv/PYTHON_ENV/DataScience/lib/python3.5/copy.py”,第 297 行,在 _reconstruct
1 回答
慕慕森
TA贡献1856条经验 获得超17个赞
找到了。
应该是: clf = KerasClassifier(build_fn=get_model)
而不是: clf = KerasClassifier(build_fn=get_model())
添加回答
举报
0/150
提交
取消