tensorflow / models

Models and examples built with TensorFlow
Other
77.16k stars 45.76k forks source link

module 'tensorflow_core.keras.utils' has no attribute 'register_keras_serializable' #7644

Closed johnwu0604 closed 5 years ago

johnwu0604 commented 5 years ago

I'm getting the following error when trying to import bert_models repository

image

Seems like register_keras_serializable is not an attribute in the tf.keras.utils libary...?

saberkun commented 5 years ago

Hi, are you using tf-nightly? If you are using tf 2.0 release, the symbol is not added. Overall, it is not really useful. You can delete them.

saberkun commented 5 years ago

If you just want to use TF2.0 ver, please use this branch https://github.com/tensorflow/models/tree/tf_2_0_rc1

Swamy54 commented 4 years ago

I am getting below error while trying

from rasa.jupyter import chat chat(model_path)


AttributeError Traceback (most recent call last)

in 1 from rasa.jupyter import chat ----> 2 chat(model_path) D:\Software\Machine_Learning\rasa\jupyter.py in chat(model_path, agent, interpreter) 31 from rasa.run import create_agent 32 ---> 33 agent = create_agent(model_path) 34 35 elif agent is not None and interpreter is not None: D:\Software\Machine_Learning\rasa\run.py in create_agent(model, endpoints) 75 tracker_store=_tracker_store, 76 lock_store=_lock_store, ---> 77 action_endpoint=_endpoints.action, 78 ) D:\Software\Machine_Learning\rasa\core\agent.py in load(cls, model_path, interpreter, generator, tracker_store, lock_store, action_endpoint, model_server, remote_storage, path_to_model_archive) 420 421 if not interpreter and nlu_model: --> 422 interpreter = NaturalLanguageInterpreter.create(nlu_model) 423 424 domain = None D:\Software\Machine_Learning\rasa\core\interpreter.py in create(obj, endpoint) 52 return obj 53 elif isinstance(obj, str) and os.path.exists(obj): ---> 54 return RasaNLUInterpreter(model_directory=obj) 55 elif isinstance(obj, str) and not os.path.exists(obj): 56 # user passed in a string, but file does not exist D:\Software\Machine_Learning\rasa\core\interpreter.py in __init__(self, model_directory, config_file, lazy_init) 272 273 if not lazy_init: --> 274 self._load_interpreter() 275 else: 276 self.interpreter = None D:\Software\Machine_Learning\rasa\core\interpreter.py in _load_interpreter(self) 295 from rasa.nlu.model import Interpreter 296 --> 297 self.interpreter = Interpreter.load(self.model_directory) 298 299 D:\Software\Machine_Learning\rasa\nlu\model.py in load(model_dir, component_builder, skip_validation) 299 300 Interpreter.ensure_model_compatibility(model_metadata) --> 301 return Interpreter.create(model_metadata, component_builder, skip_validation) 302 303 @staticmethod D:\Software\Machine_Learning\rasa\nlu\model.py in create(model_metadata, component_builder, skip_validation) 321 # lets check if all required packages are available 322 if not skip_validation: --> 323 components.validate_requirements(model_metadata.component_classes) 324 325 for i in range(model_metadata.number_of_components): D:\Software\Machine_Learning\rasa\nlu\components.py in validate_requirements(component_names) 44 """ 45 ---> 46 from rasa.nlu import registry 47 48 # Validate that all required packages are installed D:\Software\Machine_Learning\rasa\nlu\registry.py in 11 from rasa.constants import DOCS_URL_COMPONENTS 12 ---> 13 from rasa.nlu.classifiers.diet_classifier import DIETClassifier 14 from rasa.nlu.classifiers.keyword_intent_classifier import KeywordIntentClassifier 15 from rasa.nlu.classifiers.mitie_intent_classifier import MitieIntentClassifier D:\Software\Machine_Learning\rasa\nlu\classifiers\diet_classifier.py in 7 import scipy.sparse 8 import tensorflow as tf ----> 9 import tensorflow_addons as tfa 10 11 from typing import Any, Dict, List, Optional, Text, Tuple, Union, Type, NamedTuple D:\Software\Machine_Learning\tensorflow_addons\__init__.py in 19 20 # Local project imports ---> 21 from tensorflow_addons import activations 22 from tensorflow_addons import callbacks 23 from tensorflow_addons import image D:\Software\Machine_Learning\tensorflow_addons\activations\__init__.py in 19 from __future__ import print_function 20 ---> 21 from tensorflow_addons.activations.gelu import gelu 22 from tensorflow_addons.activations.hardshrink import hardshrink 23 from tensorflow_addons.activations.lisht import lisht D:\Software\Machine_Learning\tensorflow_addons\activations\gelu.py in 25 26 ---> 27 @tf.keras.utils.register_keras_serializable(package='Addons') 28 def gelu(x, approximate=True): 29 """Gaussian Error Linear Unit. AttributeError: module 'tensorflow.python.keras.api._v2.keras.utils' has no attribute 'register_keras_serializable'
pmj714 commented 4 years ago

Hi, so I just struggled with this problem for a few days. Here is how I solved it: it turns out I was using the wrong python folder. I was dealing with conda environments and had everything installed on my conda environment but was using the default path to my local installation of python as a kernel. I fixed this by changing what kernel I was using with my jupyter notebook to be my conda environment. While you may not have the exact same issue, I can almost 100% guarantee that it has to do with your environment and installation of tensorflow. Make sure that the directory referenced in the error, (the path to gelu.py) is the same directory that you are installing tensorflow in.

user37112898 commented 4 years ago

Hi, so I just struggled with this problem for a few days. Here is how I solved it: it turns out I was using the wrong python folder. I was dealing with conda environments and had everything installed on my conda environment but was using the default path to my local installation of python as a kernel. I fixed this by changing what kernel I was using with my jupyter notebook to be my conda environment. While you may not have the exact same issue, I can almost 100% guarantee that it has to do with your environment and installation of tensorflow. Make sure that the directory referenced in the error, (the path to gelu.py) is the same directory that you are installing tensorflow in.

@pmj714 which version of tensorflow and python you are using?

Jayanth1812 commented 4 years ago

I tried installing tensorflow 2.2.0. but it doesn't work for me. So, I re-installed tensorflow 2.0.0. I am getting the following error.

(tensorflow) C:\tensorflow\models\research\object_detection>python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config

Traceback (most recent call last): File "train.py", line 54, in from object_detection.builders import model_builder File "C:\Users\Jayanth\anaconda3\envs\tensorflow\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\builders\model_builder.py", line 66, in from object_detection.models import ssd_efficientnet_bifpn_feature_extractor as ssd_efficientnet_bifpn File "C:\Users\Jayanth\anaconda3\envs\tensorflow\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\models\ssd_efficientnet_bifpn_feature_extractor.py", line 33, in from official.vision.image_classification.efficientnet import efficientnet_model File "C:\Users\Jayanth\anaconda3\envs\tensorflow\lib\site-packages\official\vision\image_classification\efficientnet\efficientnet_model.py", line 35, in from official.modeling import tf_utils File "C:\Users\Jayanth\anaconda3\envs\tensorflow\lib\site-packages\official\modeling\tf_utils.py", line 25, in from official.modeling import activations File "C:\Users\Jayanth\anaconda3\envs\tensorflow\lib\site-packages\official\modeling\activationsinit.py", line 16, in from official.modeling.activations.gelu import gelu File "C:\Users\Jayanth\anaconda3\envs\tensorflow\lib\site-packages\official\modeling\activations\gelu.py", line 26, in @tf.keras.utils.register_keras_serializable(package='Text') AttributeError: module 'tensorflow_core.keras.utils' has no attribute 'register_keras_serializable'