AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objectss' - tensorflow

When I try to import tensorflow or any sort of deep learning models or libraries, it throws similar errors. Any suggestions on this please
I tried, uninstalling and reinstallin and downgraded but still throws different erors like
AttributeError: module 'this ' has no attribute 'this'

Related

pandas: df.to_csv() creates AttributeError

I'm trying to export a pandas dataframe with df.to_csv(), which should be easy enough. Unfortunately, this code:
df.to_csv(r'C:/Users/my/path/to/file.csv', index=FALSE, encoding='utf-8')
Gives me this error:
AttributeError: '_io.BufferedReader' object has no attribute 'to_csv'
What am I doing wrong? I'm working in a jupyter notebook on a mac in case that's important. Sorry for such a noob question, I know this should be super easy
I googled similar issues where attribute so-and-so is missing, but none of the ones I found helped my problem

Tensorflow 2.0 : AttributeError: module 'tensorflow' has no attribute 'matrix_band_part'

While running the code tf.matrix_band_part , i get the following error
AttributeError: module 'tensorflow' has no attribute 'matrix_band_part'
My tensorflow version : 2.0
Any solution for this problem is needed.
I have found the answer. So i would like to share.
Compatible version for the function for tensorflow 2.0 is
tf.compat.v1.matrix_band_part
Ref : https://www.tensorflow.org/api_docs/python/tf/linalg/band_part
if someone find this issue, just try alternate version: tf.linalg.band_part

MLengine 'module' object has no attribute 'estimator'

Running this example on ML engine using Cloud composer but am receiving the following error:
AttributeError: 'module' object has no attribute 'estimator'
Even though I am importing import tensorflow as tf and it exits on the following line:
estimator = tf.estimator.Estimator(model_fn = image_classifier,
Runtime version is 1.8 similar to the version using the repo.
t3 = MLEngineTrainingOperator(
task_id='ml_engine_training_op',
project_id=PROJECT_ID,
job_id=job_id,
package_uris=["gs://us-central1-ml/trainer-0.1.tar.gz"],
training_python_module=MODULE_NAME,
training_args=training_args,
region=REGION,
scale_tier='BASIC_GPU',
runtimeVersion = '1.8',
dag=dag
)
Please check the setup.py, make sure you put tensorflow in it as
REQUIRED_PACKAGES = ['tensorflow==1.8.0']. or some other version. Then don't forget to re-generate tar and upload.
Also, in my case, MLEngineTrainingOperator doesn't seem to pick runtime_version or python_version at all into ML Engine.

Tensorflow: Registering two proto functions with name 'local_variables' error

I'm trying to import a metagraph in tensorflow and when I want to initialize my weights variable:
W = tf.get_collection('W')[0]
session.run([W.initializer])
I get the error:
'Tensor' object has no attribute 'initializer'"
I found here (TensorFlow:'Tensor' object has no attribute 'initializer', occurs after several turns when reading dataset) that this problem is related to the fact that "local variables on target collection is not Variable but Tensor because local variable do not have it's proto fn registered". They propose to add this code to the model core:
from tensorflow.core.framework import variable_pb2
from tensorflow.python.framework import ops
from tensorflow.python.ops import variables
from tensorflow.python.framework.ops import register_proto_function
register_proto_function(
ops.GraphKeys.LOCAL_VARIABLES,
proto_type=variable_pb2.VariableDef,
to_proto=variables.Variable.to_proto,
from_proto=variables.Variable.from_proto)
So I added the above code in my add_final_training_ops function but now get the following error:
KeyError: "Registering two proto functions with name 'local_variables' !(Previous registration was in _find_and_load_unlocked <frozen importlib._bootstrap>:950)"
Can someone help?

TensorFlow New Op: AttributeError: 'module' object has no attribute 'custom_op'

I am creating new ops (https://www.tensorflow.org/extend/adding_an_op) for TensorFlow (r1.0) running both on x86 and ARMv7.
Minor code modifications are necessary to run TensorFlow on ARMv7, but this guide helps a lot:
https://github.com/samjabrahams/tensorflow-on-raspberry-pi/blob/master/GUIDE.md.
But I noticed that the custom operations do not work on my ARMv7 installation of TensorFlow.
For example, when I test my custom operation in a Python script on ARMv7:
import tensorflow as tf
_custom_op_module = tf.load_op_library('custom_op.so')
custom_op = _custom_op_module.add_stub
I get the following error (that does not show up on x86):
$ python test_custom_op.py
Traceback (most recent call last):
File "custom_op.py", line 3, in <module>
add_stub = _custom_op_module.add_stub
AttributeError: 'module' object has no attribute 'custom_op'
I further investigated the issue, and apparently there is not my custom operation in the .so library file.
$ python
>>> import tensorflow as tf
>>> _custom_op_module = tf.load_op_library('custom_op.so')
>>> dir(_custom_op_module)
>>> ['LIB_HANDLE', 'OP_LIST', '_InitOpDefLibrary', '__builtins__', '__doc__', '__name__', '__package__', '_collections', '_common_shapes', '_op_def_lib', '_op_def_library', '_op_def_pb2', '_op_def_registry', '_ops', '_text_format']
>>> _custom_op_module.OP_LIST
>>>
The same commands on x86 have the following output:
>>> import tensorflow as tf
>>> _custom_op_module = tf.load_op_library('custom_op.so')
>>> dir(_custom_op_module)
>>> ['LIB_HANDLE', 'OP_LIST', '_InitOpDefLibrary', '__builtins__', '__doc__', '__name__', '__package__', '_add_stub_outputs', '_collections', '_common_shapes', '_op_def_lib', '_op_def_library', '_op_def_pb2', '_op_def_registry', '_ops', '_text_format', 'custom_op']
>>> _custom_op_module.OP_LIST
op {
name: "CustomOp"
...
}
>>>
Does anybody have similar issue? Can we consider this a bug?
I hit a similar issue with a similar error message when I tried to load my new op, however, my problem was I tried to register a customized op that had the same op name as tensorflow, and that led to a name collision. Changing the name fixed it without recompiling TF.
The error message I encountered:
AttributeError: module '6e237d88703da016805889179d3f5baa' has no attribute 'custom_op'
Apparently, recompiling and re-installing the TF made it works.