Reputation: 490
I'm doing a Detection model and I'm in the step of Configuration For Transfer Learning. The error shows when I try to do these import:
import tensorflow as tf
from keras import utils
from object_detection.utils import config_util
from object_detection.protos import pipeline_pb2
from google.protobuf import text_format
I have already insert
def populate_dict_with_module_objects(target_dict, modules, obj_filter):
for module in modules:
for name in dir(module):
obj = getattr(module, name)
if obj_filter(obj):
target_dict[name] = obj
in C:\Users\Chiara\AppData\Local\Programs\Python\Python38\Lib\site-packages\tensorflow\python\keras\utils but it doesn't work.
I don't have tf.nighly installed.
This is the traceback:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-74-1865ce426368> in <module>
----> 1 from tensorflow.keras.utils import to_categorical
2 import tensorflow as tf
3 from keras import utils
4 from object_detection.utils import config_util
5 from object_detection.protos import pipeline_pb2
c:\users\chiara\appdata\local\programs\python\python38\lib\site-packages\tensorflow\__init__.py in <module>
39 import sys as _sys
40
---> 41 from tensorflow.python.tools import module_util as _module_util
42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
43
c:\users\chiara\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\__init__.py in <module>
82 from tensorflow.python import data
83 from tensorflow.python import distribute
---> 84 from tensorflow.python import keras
85 from tensorflow.python.feature_column import feature_column_lib as feature_column
86 from tensorflow.python.layers import layers
c:\users\chiara\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\keras\__init__.py in <module>
25
26 # See b/110718070#comment18 for more details about this import.
---> 27 from tensorflow.python.keras import models
28
29 from tensorflow.python.keras.engine.input_layer import Input
c:\users\chiara\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\keras\models.py in <module>
22 from tensorflow.python.framework import ops
23 from tensorflow.python.keras import backend as K
---> 24 from tensorflow.python.keras import metrics as metrics_module
25 from tensorflow.python.keras import optimizers
26 from tensorflow.python.keras.engine import network
c:\users\chiara\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\keras\metrics.py in <module>
35 from tensorflow.python.framework import tensor_spec
36 from tensorflow.python.keras import backend as K
---> 37 from tensorflow.python.keras.engine import base_layer
38 from tensorflow.python.keras.engine import base_layer_utils
39 from tensorflow.python.keras.losses import binary_crossentropy
c:\users\chiara\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in <module>
49 from tensorflow.python.keras import backend
50 from tensorflow.python.keras import constraints
---> 51 from tensorflow.python.keras import initializers
52 from tensorflow.python.keras import regularizers
53 from tensorflow.python.keras.engine import base_layer_utils
c:\users\chiara\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\keras\initializers\__init__.py in <module>
125 # from ALL_OBJECTS. We make no guarantees as to whether these objects will
126 # using their correct version.
--> 127 populate_deserializable_objects()
128 globals().update(LOCAL.ALL_OBJECTS)
129
c:\users\chiara\appdata\local\programs\python\python38\lib\site-packages\tensorflow\python\keras\initializers\__init__.py in populate_deserializable_objects()
83 v2_objs = {}
84 base_cls = initializers_v2.Initializer
---> 85 generic_utils.populate_dict_with_module_objects(
86 v2_objs,
87 [initializers_v2],
AttributeError: module 'tensorflow.python.keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
Also from the pip list
I understand that I have installed tensorflow 2.4.1
but if I do tf .__ version__
it tells me 2.2.0. I have Python 3.8.1.
Thank you so much !!
Upvotes: 1
Views: 5144
Reputation:
From comments
Issue was resolved after upgrading Tensorflow as below
!pip install tensorflow --upgrade --user
Upvotes: 1