deep_learning_cookbook icon indicating copy to clipboard operation
deep_learning_cookbook copied to clipboard

13.1 Quick Draw Cat Autoencoder --'Model'object has no attribute '_get_distribution_strategy' --Issue and Solution

Open mikechen66 opened this issue 5 years ago • 4 comments

For Anaconda/miniconda3 Environment, there is an error for no attribute '_get_distribution_strategy' , I have found out the solution to the issue as follows.

Issue:

'Model'object has no attribute '_get_distribution_strategy'

Solution:

Go to the following directory

/home/user/miniconda3/lib/python3.7/site-packages/tensorflow_core/python/keras

Open callbacks.py and make the two changes as follows. Please remember to back up the original callbacks.py in aother file for further reference.

Change the lines of code --callbacks.py --1530 line

    # TensorBoard callback involves writing a summary file in a possibly distributed settings.
    self._log_write_dir = distributed_file_utils.write_dirpath(
        self.log_dir, self.model._get_distribution_strategy())  # pylint: disable=protected-access

to the following lines of code.

    # In case this callback is used via native Keras, _get_distribution_strategy does not exist.
    if hasattr(self.model, '_get_distribution_strategy'):
      # TensorBoard callback involves writing a summary file in a
      # possibly distributed settings.
        self._log_write_dir = distributed_file_utils.write_dirpath(
            self.log_dir, self.model._get_distribution_strategy())  # pylint: disable=protected-access

Change the lines of code --callbacks.py --1728 line

# Safely remove the unneeded temp files.
distributed_file_utils.remove_temp_dirpath(
    self.log_dir, self.model._get_distribution_strategy())  # pylint: disable=protected-access

to the following lines of code

    # In case this callback is used via native Keras, _get_distribution_strategy does not exist.
    if hasattr(self.model, '_get_distribution_strategy'):
      # Safely remove the unneeded temp files.
        distributed_file_utils.remove_temp_dirpath(
            self.log_dir, self.model._get_distribution_strategy())  # pylint: disable=protected-access

Please take the following weblinks for reference.

github1: https://github.com/tensorflow/tensorboard/issues/3125

github2: https://github.com/tensorflow/tensorflow/pull/34870

mikechen66 avatar May 09 '20 03:05 mikechen66

after applying these changes to the lines of code , a new error is coming out ;

AttributeError: 'TensorBoard' object has no attribute '_log_write_dir'

Hadiaz1 avatar May 13 '20 15:05 Hadiaz1

Hi Hadiaz1:

Since I upgraded TensorFlow 1.5 to TensorFlow 2.1, so the TensorBoard has separated from Tensorboad. That means that Tensorboard needs to be installed independently. That is Google's new practice. During running the script in Jupyter Notebook, the script has no any problem with the above-mentioned solution. I will try to install TensorBoard on Ubuntu 18.04 and see what happens with TensorBoard.

Best regards,

Mike

mikechen66 avatar May 14 '20 15:05 mikechen66

Hi Hadiaz1:

I am wondering whether you have installed TensorFlow 2.x. After installation of TensorBoard v2.2.1, I test the script again on TensorFlow 2.1.

1. Add the magic line of code

Load the TensorBoard notebook extension at the beginning of the lines of code.

%load_ext tensorboard

2. Start TensorBoard within the notebook using magics.

Please put them after the section of the first training. For example, it has the lines of code autoencoder.fit(...). It originally has the mark In [5]

%tensorboard --logdir logs

It shows the first tensorboard instance.

3. Start TensorBoard within the notebook using magics.

Please put them after the section of the first training. For example, it has the lines of code variantional_auto_encoder.fit(...). It originally has the mark In [11]

%tensorboard --logdir logs

It shows the second tensorboard instance.

If you have more findings, please feel free to contact me.

Notes:

I tied to add the following line of code in the the scripts but did not succeed.

file_writer = tf.compat.v1.summary.FileWriter('/path/to/logs', graph).

Without the line of code, Tensorboard catches the orginal logs infomration such as LeNet-MNIST-1. It is a compatibility issue between TensorFlow 2.1 and the original script of 13.1 Quick Draw Cat Autoencoder. Google has not further improvement on the issue.

Reference:

tensorboard: https://github.com/tensorflow/tensorboard/blob/master/docs/tensorboard_in_notebooks.ipynb

tensorboard in notebook: https://www.tensorflow.org/tensorboard/tensorboard_in_notebooks

tensorboard v2.2.1: https://github.com/tensorflow/tensorboard

tensorboard v2.2.1 issue: https://github.com/tensorflow/tensorboard/issues/3634

mikechen66 avatar May 14 '20 17:05 mikechen66

my problem was kinda solved suddenly with some restarts and runs .Thanks you so much anyways, those code changes may have made something !

Hadiaz1 avatar May 14 '20 18:05 Hadiaz1