1

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 !!

2
  • It shows you have setup with TF2.2, Does this help you? Commented Apr 20, 2021 at 5:02
  • 1
    I solved using !pip install tensorflow --upgrade --user . Thank you ! Commented Apr 20, 2021 at 17:13

1 Answer 1

1

From comments

Issue was resolved after upgrading Tensorflow as below

!pip install tensorflow --upgrade --user
Sign up to request clarification or add additional context in comments.

5 Comments

not working for me please help.. my tensorflow version is 2.5.0, win 10
@AshishSaini, Did you tried workarounds discussed in this thread?
@thread, yes i have done all the alternatives and when i try to installl 2.2.4 it says "ERROR: Could not find a version that satisfies the requirement tensorflow==2.1.0 (from versions: 2.5.0rc0, 2.5.0rc1, 2.5.0rc2, 2.5.0rc3, 2.5.0)".. I have tried installing all these version but none of them solved my problem .\
@AshishSaini, the reason that you have received above error because you are using python 3.9. it can be resolved when you downgrade python version to 3.7/3.8. Here you can refer version compatibility between tensorflow, python, cuda and cudnn.
thanks a lot I got it, its started working when I install anaconda and setup virtualenv there and installed python 3.8.8 its started working, thanks a lot...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.