【问题标题】:After downgrading Tensorflow 2.0 to 1.5 results changed and results reproduction is not available将 Tensorflow 2.0 降级到 1.5 后,结果发生了变化,结果再现不可用
【发布时间】:2020-05-18 07:56:02
【问题描述】:

您能帮我在不重新启动 Python 内核的情况下使用 Tensorflow 1.15 实现可重现的结果吗?为什么 TF 2.0 和 TF 1.5 的输出结果在参数和数据集完全相同的情况下会有所不同?是否可以实现相同的输出?

更多详情: 我试图通过以下方式解释 TF 2.0 中的模型结果:

import shap
background = df3.iloc[np.random.choice(df3.shape[0], 100, replace=False)]
explainer = shap.DeepExplainer(model,  background)

我收到一个错误:

`get_session` is not available when using TensorFlow 2.0.`get_session` is not available when using TensorFlow 2.0.

根据SO topic,我尝试通过在我的代码前面使用来设置 TF 2.0 与 TF 1 的兼容性:

import tensorflow.compat.v1 as tf

但是错误又出现了。 根据许多用户的建议,我将 TF2 降级到 TF 1.15 它解决了问题,并且 shap 模块解释了结果,但是: 1) 为了使结果可重现,我必须在 tf.random.set_random_seed(7) 上更改 tf.random.set_seed(7) 并每次都重新启动 Python 内核!在 TF2 中,我不必重新启动内核。 2) 预测结果发生了变化,尤其是经济效率(即TF1.5.错误分类比TF2.0更重要的样本)。

特遣部队2: 准确度:94.95%,经济效率=64%

TF 1: 准确度:94.85%,经济效率=56%

型号代码为here

【问题讨论】:

    标签: python-3.x tensorflow tensorflow2.0 shap


    【解决方案1】:

    首先,结果不仅TF1和TF2版本不同,TF2.0和TF2.2版本也不同。可能,它取决于包中不同的内部参数。

    其次,TensorFlow2 与 DeepExplainer 在以下版本中协同工作:

    import tensorflow
    import pandas as pd
    import keras
    import xgboost
    import numpy
    import shap
    print(tensorflow.__version__)
    print(pd.__version__)
    print(keras.__version__)
    print(xgboost.__version__)
    print(numpy.__version__)
    print(shap.__version__) 
    

    输出:

    2.2.0
    0.24.2
    2.3.1
    0.90
    1.17.5
    0.35.0
    

    但是更新库会遇到一些困难。

    在 Python 3.5 中,运行 TF2.2,您将面临错误“DLL 加载失败:找不到指定的模块”。 通过安装更新​​的 C++ 包可以 100% 解决。看到这个:https://github.com/tensorflow/tensorflow/issues/22794#issuecomment-573297027 下载包链接:https://support.microsoft.com/ru-ru/help/2977003/the-latest-supported-visual-c-downloads

    在 Python 3.7 中,您将找不到带有 whl 扩展的 shap 0.35.0 版本。只有 tar.gz 扩展会给出错误:“安装 Visual C++ 包”。但是安装没有帮助。 然后在此处下载适用于 Python 3.7 的 shap 0.35.0:https://anaconda.org/conda-forge/shap/files。运行 Anaconda 外壳。类型:conda install -c conda-forge C:\shap-0.35.0-py37h3bbf574_0.tar.bz2。

    【讨论】:

      猜你喜欢
      • 2014-10-15
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-21
      • 1970-01-01
      相关资源
      最近更新 更多