AttributeError: module 'tensorflow.python.keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
Author: stas00
Pull request: no

Problem and solution:

This happened several times as of recent. Some env gets messed up and I end up with most tests failing with:
```____________________________________________________ ERROR collecting tests/test_benchmark_tf.py ____________________________________________________
tests/test_benchmark_tf.py:6: in <module>
    from transformers import AutoConfig, is_tf_available
src/transformers/__init__.py:22: in <module>
    from .integrations import (  # isort:skip
src/transformers/integrations.py:58: in <module>
    from .file_utils import is_torch_tpu_available
src/transformers/file_utils.py:59: in <module>
    import tensorflow as tf
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/tensorflow/__init__.py:41: in <module>
    from tensorflow.python.tools import module_util as _module_util
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/tensorflow/python/__init__.py:84: in <module>
    from tensorflow.python import keras
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/tensorflow/python/keras/__init__.py:27: in <module>
    from tensorflow.python.keras import models
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/tensorflow/python/keras/models.py:24: in <module>
    from tensorflow.python.keras import metrics as metrics_module
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/tensorflow/python/keras/metrics.py:37: in <module>
    from tensorflow.python.keras.engine import base_layer
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py:51: in <module>
    from tensorflow.python.keras import initializers
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/tensorflow/python/keras/initializers/__init__.py:127: in <module>
    populate_deserializable_objects()
/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/tensorflow/python/keras/initializers/__init__.py:85: in populate_deserializable_objects
    generic_utils.populate_dict_with_module_objects(
E   AttributeError: module 'tensorflow.python.keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
collected 0 items / 1 error   
```

I think it's conda installing a broken tensorflow, I'm not 100% sure - see the solution in the next comment.


Comments:
### Solution

If you encounter the same, here is how to fix it:

```
pip uninstall -y tensorflow-gpu tensorflow
pip install tensorflow-gpu -U 
```
(I assume you want the gpu version - adjust if not)


I think that for the last few versions, when installing `tensorflow` you get a `tensorflow` that can use your GPU out of the box, so there's no need to play with `tensorflow-gpu`/`tensorflow`!

I think it's another package's dependency pulling in `tensorflow-gpu` - e.g. I see: `wandb/requirements.txt:tensorflow-gpu==2.3.1`

In my case, after `conda install tensorflow-gpu` - to install `tensorflow` version 2.2,
I then tried `pip install autokeras` (because conda does not have this package). 
`pip` would install **_another_** `tensorflow`  (in this case, version 2.3).

And this is when the problem happened.

```
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/longnv/.conda/envs/testENV/lib/python3.6/site-packages/tensorflow/__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "/home/longnv/.conda/envs/testENV/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 84, in <module>
    from tensorflow.python import keras
  File "/home/longnv/.conda/envs/testENV/lib/python3.6/site-packages/tensorflow/python/keras/__init__.py", line 27, in <module>
    from tensorflow.python.keras import models
  File "/home/longnv/.conda/envs/testENV/lib/python3.6/site-packages/tensorflow/python/keras/models.py", line 24, in <module>
    from tensorflow.python.keras import metrics as metrics_module
  File "/home/longnv/.conda/envs/testENV/lib/python3.6/site-packages/tensorflow/python/keras/metrics.py", line 37, in <module>
    from tensorflow.python.keras.engine import base_layer
  File "/home/longnv/.conda/envs/testENV/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 51, in <module>
    from tensorflow.python.keras import initializers
  File "/home/longnv/.conda/envs/testENV/lib/python3.6/site-packages/tensorflow/python/keras/initializers/__init__.py", line 127, in <module>
    populate_deserializable_objects()
  File "/home/longnv/.conda/envs/testENV/lib/python3.6/site-packages/tensorflow/python/keras/initializers/__init__.py", line 85, in populate_deserializable_objects
    generic_utils.populate_dict_with_module_objects(
AttributeError: module 'tensorflow.python.keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
>>> conda uninstall keras

```
It seems like we have similar error.
I am not sure  what you have done with your env but your solution worked in my case too, obviously.

Please add the snippet of the code into the program of general_utils.py

**1. Find out your path**

For me, the path is listed as follows:

/home/user/miniconda3/lib/python3.7/site-packages/tensorflow/python/keras/utils/generic_utils.py

**2. Paste the code into the program of generic_utils.py**
```
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
```

**3. Initialize the dev tool**
It will be working after initializing  the dev tool (it is Terminal for me in Linux)