Models: [deeplab]AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v1'

Created on 31 Dec 2019  Â·  2Comments  Â·  Source: tensorflow/models

System information
What is the top-level directory of the model you are using: models-master/research/deeplab/
Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows10
TensorFlow installed from (source or binary): binary
TensorFlow version (use command below): 1.12.0
Bazel version (if compiling from source): No
CUDA/cuDNN version: No
GPU model and memory: 16G memory
Exact command to reproduce:
python remove_gt_colormap.py --original_gt_folder=./pascal_voc_seg/VOCdevkit/VOC2012/SegmentationClass --output_dir=./pascal_voc_seg/VOCdevkit/VOC2012/SegmentationClassRaw

Problem description:

I learn semantic segmentation from models-master/research/deeplab.

I use anaconda(python3.6),tensorflow 1.12.0 on window 10.

I don't use CUDA/cuDNN.

I don't use GPU and the memory of my computer is 16G.

When I use this command:

python remove_gt_colormap.py --original_gt_folder=./pascal_voc_seg/VOCdevkit/VOC2012/SegmentationClass --output_dir=./pascal_voc_seg/VOCdevkit/VOC2012/SegmentationClassRaw

There was such a mistake:

Traceback (most recent call last):
File "remove_gt_colormap.py", line 29, in
FLAGS = tf.compat.v1.flags.FLAGS
AttributeError: module 'tensorflow._api.v1.compat' has no attribute 'v1'

So how to fix it?

Most helpful comment

tf.compat.v1 is from tensorflow 2 (s. https://www.tensorflow.org/api_docs/python/tf/compat/v1)
You should use this with TF2.0
Should be mentioned in the docs somewhere.

While you are at it ... the next error will be:

  File "./build_voc2012_data.py", line 60, in <module>
    import build_data
  File "....tensorflow/models/research/deeplab/datasets/build_data.py", line 36, in <module>
AttributeError: module 'tensorflow' has no attribute 'app'

This could be avoided by replacing

import tensorflow as tf

with

import tensorflow.compat.v1 as tf

in build_voc2012_data.py and build_data.py

All 2 comments

tf.compat.v1 is from tensorflow 2 (s. https://www.tensorflow.org/api_docs/python/tf/compat/v1)
You should use this with TF2.0
Should be mentioned in the docs somewhere.

While you are at it ... the next error will be:

  File "./build_voc2012_data.py", line 60, in <module>
    import build_data
  File "....tensorflow/models/research/deeplab/datasets/build_data.py", line 36, in <module>
AttributeError: module 'tensorflow' has no attribute 'app'

This could be avoided by replacing

import tensorflow as tf

with

import tensorflow.compat.v1 as tf

in build_voc2012_data.py and build_data.py

tf.compat.v1 is from tensorflow 2 (s. https://www.tensorflow.org/api_docs/python/tf/compat/v1)
You should use this with TF2.0
Should be mentioned in the docs somewhere.

While you are at it ... the next error will be:

  File "./build_voc2012_data.py", line 60, in <module>
    import build_data
  File "....tensorflow/models/research/deeplab/datasets/build_data.py", line 36, in <module>
AttributeError: module 'tensorflow' has no attribute 'app'

This could be avoided by replacing

import tensorflow as tf

with

import tensorflow.compat.v1 as tf

in build_voc2012_data.py and build_data.py

OK!Thank you for your reply!

Was this page helpful?
0 / 5 - 0 ratings