haven-jeon / PyKoSpacing

Automatic Korean word spacing with Python
GNU General Public License v3.0
403 stars 118 forks source link

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

Closed abigailJung closed 3 years ago

abigailJung commented 3 years ago

Hello, I'm new to this Package. When I tried to execute a test code, I've got the error below. Would you give some help for me?

For your information, my development environment is :

and the test code was this.

from pykospacing import Spacing
kospacing_sent = Spacing(new_sent)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-190-c1528fddd67b> in <module>
----> 1 from pykospacing import Spacing
      2 
      3 kospacing_sent = Spacing(new_sent)
      4 print(sent)

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/pykospacing/__init__.py in <module>
----> 1 from pykospacing.kospacing import *

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/pykospacing/kospacing.py in <module>
     15 dic_path = pkg_resources.resource_filename(
     16     'pykospacing', os.path.join('resources', 'dicts', 'c2v.dic'))
---> 17 MODEL = load_model(model_path)
     18 MODEL.make_predict_function()
     19 W2IDX, _ = load_vocab(dic_path)

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/saving/save.py in load_model(filepath, custom_objects, compile)
    182       options: Optional `tf.saved_model.LoadOptions` object that specifies
    183         options for loading from SavedModel.
--> 184 
    185   Returns:
    186       A Keras model instance. If the original model was compiled, and saved with

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/saving/hdf5_format.py in load_model_from_hdf5(filepath, custom_objects, compile)
    176       raise ValueError('No model found in config file.')
    177     if hasattr(model_config, 'decode'):
--> 178       model_config = model_config.decode('utf-8')
    179     model_config = json_utils.decode(model_config)
    180     model = model_config_lib.model_from_config(model_config,

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/saving/model_config.py in model_from_config(config, custom_objects)
     53   """
     54   if isinstance(config, list):
---> 55     raise TypeError('`model_from_config` expects a dictionary, not a list. '
     56                     'Maybe you meant to use '
     57                     '`Sequential.from_config(config)`?')

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/layers/serialization.py in deserialize(config, custom_objects)
    107 
    108   # Prevent circular dependencies.
--> 109   from tensorflow.python.keras import models  # pylint: disable=g-import-not-at-top
    110   from tensorflow.python.keras.premade.linear import LinearModel  # pylint: disable=g-import-not-at-top
    111   from tensorflow.python.keras.premade.wide_deep import WideDeepModel  # pylint: disable=g-import-not-at-top

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    371     registered_name = package + '>' + class_name
    372 
--> 373     if tf_inspect.isclass(arg) and not hasattr(arg, 'get_config'):
    374       raise ValueError(
    375           'Cannot register a class that does not have a get_config() method.')

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py in from_config(cls, config, custom_objects)

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py in reconstruct_from_config(config, custom_objects, created_layers)

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py in process_layer(layer_data)

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/layers/serialization.py in deserialize(config, custom_objects)
    107 
    108   # Prevent circular dependencies.
--> 109   from tensorflow.python.keras import models  # pylint: disable=g-import-not-at-top
    110   from tensorflow.python.keras.premade.linear import LinearModel  # pylint: disable=g-import-not-at-top
    111   from tensorflow.python.keras.premade.wide_deep import WideDeepModel  # pylint: disable=g-import-not-at-top

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    373     if tf_inspect.isclass(arg) and not hasattr(arg, 'get_config'):
    374       raise ValueError(
--> 375           'Cannot register a class that does not have a get_config() method.')
    376 
    377     if registered_name in _GLOBAL_CUSTOM_OBJECTS:

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in from_config(cls, config)
    653         synchronization=synchronization,
    654         aggregation=aggregation,
--> 655         caching_device=caching_device)
    656     if regularizer is not None:
    657       # TODO(fchollet): in the future, this should be handled at the

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/utils/version_utils.py in __new__(cls, *args, **kwargs)
     55 
     56 
---> 57 class LayerVersionSelector(object):
     58   """Chooses between Keras v1 and v2 Layer class."""
     59 

~/anaconda3/envs/tf22-py36/lib/python3.6/site-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 

~/anaconda3/envs/tf22-py36/lib/python3.6/site-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 

~/anaconda3/envs/tf22-py36/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 

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer_v1.py in <module>
     43 from tensorflow.python.keras.engine import input_spec
     44 from tensorflow.python.keras.mixed_precision import autocast_variable
---> 45 from tensorflow.python.keras.mixed_precision import loss_scale_optimizer
     46 from tensorflow.python.keras.mixed_precision import policy
     47 from tensorflow.python.keras.saving.saved_model import layer_serialization

~/anaconda3/envs/tf22-py36/lib/python3.6/site-packages/tensorflow/python/keras/mixed_precision/loss_scale_optimizer.py in <module>
   1192 
   1193 # pylint: disable=protected-access
-> 1194 mixed_precision._register_wrapper_optimizer_cls(optimizer_v2.OptimizerV2,
   1195                                                 LossScaleOptimizerV1)
   1196 

AttributeError: module 'tensorflow.python.training.experimental.mixed_precision' has no attribute '_register_wrapper_optimizer_cls' 
==========================
haven-jeon commented 3 years ago

How about trying with https://github.com/haven-jeon/PyKoSpacing/blob/master/requirements.txt.

Please note, the code has not been tested other than the above settings.

abigailJung commented 3 years ago

It must be a tensorflow version issue. I'll check it.
Thank you for your reply.