tensorflow2.x中has no attribute问题,以及模块tensorflow.contrib.slim问题

AttributeError: in user code:

    C:/Users/Administrator/PycharmProjects/FAS-SGTD-master/fas_sgtd_multi_frame/generate_data_train.py:313 parser_fun  *
        ALLDATA=tf.py_func(read_data_decode,

    AttributeError: module 'tensorflow' has no attribute 'py_func'

在跑活体检测代码的时候,报出这样一个错误

tensorflow-gpu的版本是2.2.0

版本过高所致

退回tensorflow-gpu2.0.0,报新的错误

import tensorflow.contrib.slim as slim
ModuleNotFoundError: No module named 'tensorflow.contrib'

继续退到1.8,发现仍然还有slim问题,于是又装回2.2.0

查资料发现slim模块已被弃用,在https://www.pythonheidong.com/blog/article/296246/上找到一位答主给出

pip install git+https://github.com/adrianc-a/tf-slim.git@remove_contrib的解决方案,成功地用tf_slim代替tensorflow.contrib.slim

        再回到‘py_func’的问题,这是因为tf1升到tf2带来的的问题,只需要把tf.py_func改成tf.compat.v1.pyfunc即可。

 

你可能感兴趣的:(tensorflow2.x中has no attribute问题,以及模块tensorflow.contrib.slim问题)