J Agustin Barrachina
J Agustin Barrachina

Reputation: 4100

AttributeError: module 'tensorflow.compat.v2.summary' has no attribute 'scalar'

I have been running a u-net on oxford_iiit_pet dataset.

I followed quite similar the code from this medium.

Here you have my code.

When running the fit method I got the following error message:

 File "/home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/keras/engine/training.py", line 1184, in fit
    tmp_logs = self.train_function(iterator)
  File "/home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py", line 885, in __call__
    result = self._call(*args, **kwds)
  File "/home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py", line 933, in _call
    self._initialize(args, kwds, add_initializers_to=initializers)
  File "/home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py", line 759, in _initialize
    self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
  File "/home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/tensorflow/python/eager/function.py", line 3066, in _get_concrete_function_internal_garbage_collected
    graph_function, _ = self._maybe_define_function(args, kwargs)
  File "/home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/tensorflow/python/eager/function.py", line 3463, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "/home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/tensorflow/python/eager/function.py", line 3298, in _create_graph_function
    func_graph_module.func_graph_from_py_func(
  File "/home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/tensorflow/python/framework/func_graph.py", line 1007, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py", line 668, in wrapped_fn
    out = weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "/home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/tensorflow/python/framework/func_graph.py", line 994, in wrapper
    raise e.ag_error_metadata.to_exception(e)
AttributeError: in user code:

    /home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/keras/engine/training.py:853 train_function  *
        return step_function(self, iterator)
    /home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/keras/engine/training.py:845 step_function  **
        write_scalar_summaries(outputs, step=model._train_counter)  # pylint: disable=protected-access
    /home/barrachina/anaconda3/envs/tf-pip/lib/python3.9/site-packages/keras/engine/training.py:2977 write_scalar_summaries
        tf.summary.scalar('batch_' + name, value, step=step)

    AttributeError: module 'tensorflow.compat.v2.summary' has no attribute 'scalar'

After seeing more carefully, I realized I got the following warning:

WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.

I tried pip install tensorboard but it says I already have it. I tried uninstalling and installing it back and nothing.


I am using python version 3.9.6 and tensorflow 2.6.0 and tensorboard 2.6.0.

Output (cropped) of pip list:

tensorboard              2.6.0
tensorboard-data-server  0.6.1
tensorboard-plugin-wit   1.8.0
tensorflow               2.6.0
tensorflow-datasets      4.4.0
tensorflow-estimator     2.6.0
tensorflow-metadata      1.2.0
tensorflow-probability   0.13.0

Actually using a conda environment so conda list gives:

python                    3.9.6           h49503c6_1_cpython    conda-forge
...
tensorboard               2.6.0                    pypi_0    pypi
tensorboard-data-server   0.6.1                    pypi_0    pypi
tensorboard-plugin-wit    1.8.0                    pypi_0    pypi
tensorflow                2.6.0                    pypi_0    pypi
tensorflow-datasets       4.4.0                    pypi_0    pypi
tensorflow-estimator      2.6.0                    pypi_0    pypi
tensorflow-metadata       1.2.0                    pypi_0    pypi
tensorflow-probability    0.13.0                   pypi_0    pypi

Upvotes: 2

Views: 2399

Answers (1)

J Agustin Barrachina
J Agustin Barrachina

Reputation: 4100

Ok, I had, in my project, a file called tensorboard.py. Renaming it solved the issue. I realized thanks to this answer

Upvotes: 3

Related Questions