AttributeError:模块“tensorflow.python.training.experimental.mixed_precision"没有属性“_register_wrapper_optimizer_cls" [英] AttributeError: module 'tensorflow.python.training.experimental.mixed_precision' has no attribute '_register_wrapper_optimizer_cls'

查看:84
本文介绍了AttributeError:模块“tensorflow.python.training.experimental.mixed_precision"没有属性“_register_wrapper_optimizer_cls"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Keras 来实现一个神经网络.但是当我使用 model = Sequential() 时,出现以下错误:

I am using Keras to implement a neural network. But when I use model = Sequential(), I get the following error:

AttributeError                            Traceback (most recent call last)
<ipython-input-31-fa9fd3b0e211> in <module>
      8 
      9 # Create the model
---> 10 model = Sequential()
     11 model.add(Dropout(0.1), input_shape=(128,))
     12 model.add(Dense(256, activation='relu', kernel_initializer='he_uniform'))

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/version_utils.py in __new__(cls, *args, **kwargs)
     55     use_v2 = should_use_v2()
     56     cls = swap_class(cls, training.Model, training_v1.Model, use_v2)  # pylint: disable=self-cls-assignment
---> 57     return super(ModelVersionSelector, cls).__new__(cls)
     58 
     59 

/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/lazy_loader.py in __getattr__(self, item)
     60 
     61   def __getattr__(self, item):
---> 62     module = self._load()
     63     return getattr(module, item)
     64 

/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/lazy_loader.py in _load(self)
     43     """Load the module and insert it into the parent's globals."""
     44     # Import the target module and insert it into the parent's namespace
---> 45     module = importlib.import_module(self.__name__)
     46     self._parent_module_globals[self._local_name] = module
     47 

/usr/lib/python3.6/importlib/__init__.py in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 
    128 

/usr/lib/python3.6/importlib/_bootstrap.py in _gcd_import(name, package, level)

/usr/lib/python3.6/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/lib/python3.6/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/usr/lib/python3.6/importlib/_bootstrap.py in _load_unlocked(spec)

/usr/lib/python3.6/importlib/_bootstrap_external.py in exec_module(self, module)

/usr/lib/python3.6/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer_v1.py in <module>
     48 from tensorflow.python.keras.engine import input_spec
     49 from tensorflow.python.keras.mixed_precision import autocast_variable
---> 50 from tensorflow.python.keras.mixed_precision import loss_scale_optimizer
     51 from tensorflow.python.keras.mixed_precision import policy
     52 from tensorflow.python.keras.saving.saved_model import layer_serialization

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/mixed_precision/loss_scale_optimizer.py in <module>
   1152 
   1153 # pylint: disable=protected-access
-> 1154 mixed_precision._register_wrapper_optimizer_cls(optimizer_v2.OptimizerV2,
   1155                                                 LossScaleOptimizerV1)
   1156 

AttributeError: module 'tensorflow.python.training.experimental.mixed_precision' has no attribute '_register_wrapper_optimizer_cls'

我对深度学习比较陌生.任何帮助,将不胜感激.谢谢!

I am relatively new to deep learning. Any help would be appreciated. Thank you!

推荐答案

这个问题可能出现在keras包版本中.

This problem maybe occurs in the keras package version.

因为安装的tensorflow版本与keras版本不匹配.只需卸载keras,重新安装自己的tensorflow对应版本即可.

Because the installed tensorflow version does not match the keras version. Just uninstall keras and reinstall your own tensorflow corresponding version.

总而言之,您需要为您的 Keras 代码匹配正确的环境版本.

In summary, you need to match the correct environment version for your Keras code.

这篇关于AttributeError:模块“tensorflow.python.training.experimental.mixed_precision"没有属性“_register_wrapper_optimizer_cls"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆