为了账号安全,请及时绑定邮箱和手机立即绑定

运行 Keras 和 scikit-learn 时发生了不同的异常

运行 Keras 和 scikit-learn 时发生了不同的异常

潇潇雨雨 2021-07-05 12:17:32
我尝试将 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())


查看完整回答
反对 回复 2021-07-13
  • 1 回答
  • 0 关注
  • 232 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信