Mask_RCNN icon indicating copy to clipboard operation
Mask_RCNN copied to clipboard

Tensorflow / Keras Google Colab dependency problems `AttributeError: module 'tensorflow._api.v1.compat.v2' has no attribute '__internal__'`

Open bhsnada opened this issue 3 years ago • 41 comments

I have running a MASK RCNN Model with tensorflow 1.15 and keras 2.1.6 every thing worked correctly but today when I want to run it again I get this error "module 'tensorflow._api.v1.compat.v2' has no attribute 'internal'"

image

bhsnada avatar May 26 '21 07:05 bhsnada

Even I am facing the same problem, the code was working fine yesterday but today for some reason Google Colab gives this error

aaronadb avatar May 26 '21 08:05 aaronadb

Even I am facing the same problem, the code was working fine yesterday but today for some reason Google Colab gives this error

Hello @aaronadb if you find a solution inform me please I will appreciate your help

bhsnada avatar May 26 '21 10:05 bhsnada

Me to facing the same issue......

peppyguy avatar May 26 '21 12:05 peppyguy

I have the same problem.

dariodellamura avatar May 26 '21 12:05 dariodellamura

I have the same problem from yesterday and I have not found any solution.

francycar avatar May 26 '21 13:05 francycar

I have the same problem from yesterday and I have not found any solution.

Me too I didn't find a solution, I am blocked :/

bhsnada avatar May 26 '21 13:05 bhsnada

I've got the same problem. Yesterday no problem, today this error, without making changes to the code. Thanks

paolopac avatar May 26 '21 15:05 paolopac

I've got the same problem. Yesterday no problem, today this error, without making changes to the code. Thanks

The same problem yesterday everything is Ok, but today I can't run mun code I am looking to find a solution

bhsnada avatar May 26 '21 17:05 bhsnada

Hi guys, I have the same issue. I managed to find out what happens but it's unsuccessful. When I try to do with various versions of Keras and TensorFlow, I get different error announcements. Have you fixed? Please let me know. Thanks a lot.

QuanNguyenAUT avatar May 27 '21 02:05 QuanNguyenAUT

Guys I am tried with in build tensorflow/magic function of tensorflow 1x with different versions of keras but ended with some errors...If it is fixed please let us know

peppyguy avatar May 27 '21 03:05 peppyguy

same here :(

nastaran-Ahmadi avatar May 27 '21 06:05 nastaran-Ahmadi

I don't know this issue comes from Keras, TF or Colab, or whatever

QuanNguyenAUT avatar May 27 '21 06:05 QuanNguyenAUT

I tried to run my code on my machine, same error. so I think the issue hasn't caused by colab

nastaran-Ahmadi avatar May 27 '21 06:05 nastaran-Ahmadi

I solved the problem when I try to :

!pip uninstall keras-nightly pip uninstall -y tensorflow

and then install tensorflow and kerass with version you want to use

bhsnada avatar May 27 '21 07:05 bhsnada

I solved the problem when I try to :

!pip uninstall keras-nightly pip uninstall -y tensorflow

and then install tensorflow and kerass with version you want to use

could you please share keras and tensorflow version that you are using?

nastaran-Ahmadi avatar May 27 '21 07:05 nastaran-Ahmadi

I solved the problem when I try to : !pip uninstall keras-nightly pip uninstall -y tensorflow and then install tensorflow and kerass with version you want to use

could you please share keras and tensorflow version that you are using?

pip install tensorflow-gpu==1.15.0 pip install keras==2.1.6

bhsnada avatar May 27 '21 07:05 bhsnada

After Uninstalling using

!pip uninstall keras-nightly !pip uninstall -y tensorflow

and Installing my required versions tensorflow == 1.15.0 and keras == 2.2.5 , while training i got below error

**Traceback (most recent call last): File "beagle.py", line 397, in "mrcnn_bbox", "mrcnn_mask"]) File "/usr/local/lib/python3.7/dist-packages/mask_rcnn-2.1-py3.7.egg/mrcnn/model.py", line 2130, in load_weights File "/usr/local/lib/python3.7/dist-packages/keras/engine/saving.py", line 1224, in load_weights_from_hdf5_group_by_name original_keras_version = f.attrs['keras_version'].decode('utf8')

<ctrl+b>AttributeError: 'str' object has no attribute 'decode'** <ctrl+b>

<ctrl+b>..................More details of error are below...............<ctrl+b>

Using TensorFlow backend. Weights: coco Dataset: beagle Logs: /content/logs

Configurations: BACKBONE resnet101 BACKBONE_STRIDES [4, 8, 16, 32, 64] BATCH_SIZE 2 BBOX_STD_DEV [0.1 0.1 0.2 0.2] COMPUTE_BACKBONE_SHAPE None DETECTION_MAX_INSTANCES 100 DETECTION_MIN_CONFIDENCE 0.9 DETECTION_NMS_THRESHOLD 0.3 FPN_CLASSIF_FC_LAYERS_SIZE 1024 GPU_COUNT 1 GRADIENT_CLIP_NORM 5.0 IMAGES_PER_GPU 2 IMAGE_CHANNEL_COUNT 3 IMAGE_MAX_DIM 1024 IMAGE_META_SIZE 19 IMAGE_MIN_DIM 800 IMAGE_MIN_SCALE 0 IMAGE_RESIZE_MODE square IMAGE_SHAPE [1024 1024 3] LEARNING_MOMENTUM 0.9 LEARNING_RATE 0.001 LOSS_WEIGHTS {'rpn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_class_loss': 1.0, 'mrcnn_bbox_loss': 1.0, 'mrcnn_mask_loss': 1.0} MASK_POOL_SIZE 14 MASK_SHAPE [28, 28] MAX_GT_INSTANCES 100 MEAN_PIXEL [123.7 116.8 103.9] MINI_MASK_SHAPE (56, 56) NAME beagle NUM_CLASSES 7 POOL_SIZE 7 POST_NMS_ROIS_INFERENCE 1000 POST_NMS_ROIS_TRAINING 2000 PRE_NMS_LIMIT 6000 ROI_POSITIVE_RATIO 0.33 RPN_ANCHOR_RATIOS [0.5, 1, 2] RPN_ANCHOR_SCALES (32, 64, 128, 256, 512) RPN_ANCHOR_STRIDE 1 RPN_BBOX_STD_DEV [0.1 0.1 0.2 0.2] RPN_NMS_THRESHOLD 0.7 RPN_TRAIN_ANCHORS_PER_IMAGE 256 STEPS_PER_EPOCH 100 TOP_DOWN_PYRAMID_SIZE 256 TRAIN_BN False TRAIN_ROIS_PER_IMAGE 200 USE_MINI_MASK True USE_RPN_ROIS True VALIDATION_STEPS 50 WEIGHT_DECAY 0.0001

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:541: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:66: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:4432: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:2139: The name tf.nn.fused_batch_norm is deprecated. Please use tf.compat.v1.nn.fused_batch_norm instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:4267: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:2239: The name tf.image.resize_nearest_neighbor is deprecated. Please use tf.compat.v1.image.resize_nearest_neighbor instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow_core/python/ops/array_ops.py:1475: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.where in 2.0, which has the same broadcast rule as np.where WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/mask_rcnn-2.1-py3.7.egg/mrcnn/model.py:553: The name tf.random_shuffle is deprecated. Please use tf.random.shuffle instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/mask_rcnn-2.1-py3.7.egg/mrcnn/utils.py:202: The name tf.log is deprecated. Please use tf.math.log instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/mask_rcnn-2.1-py3.7.egg/mrcnn/model.py:600: calling crop_and_resize_v1 (from tensorflow.python.ops.image_ops_impl) with box_ind is deprecated and will be removed in a future version. Instructions for updating: box_ind is deprecated, use box_indices instead Downloading pretrained model to /content/mask_rcnn_coco.h5 ... ... done downloading pretrained model! Loading weights /content/mask_rcnn_coco.h5 Traceback (most recent call last): File "beagle.py", line 397, in "mrcnn_bbox", "mrcnn_mask"]) File "/usr/local/lib/python3.7/dist-packages/mask_rcnn-2.1-py3.7.egg/mrcnn/model.py", line 2130, in load_weights File "/usr/local/lib/python3.7/dist-packages/keras/engine/saving.py", line 1224, in load_weights_from_hdf5_group_by_name original_keras_version = f.attrs['keras_version'].decode('utf8') AttributeError: 'str' object has no attribute 'decode'

peppyguy avatar May 27 '21 07:05 peppyguy

After Uninstalling using

!pip uninstall keras-nightly !pip uninstall -y tensorflow

and Installing my required versions tensorflow == 1.15.0 and keras == 2.2.5 , while training i got below error

**Traceback (most recent call last): File "beagle.py", line 397, in "mrcnn_bbox", "mrcnn_mask"]) File "/usr/local/lib/python3.7/dist-packages/mask_rcnn-2.1-py3.7.egg/mrcnn/model.py", line 2130, in load_weights File "/usr/local/lib/python3.7/dist-packages/keras/engine/saving.py", line 1224, in load_weights_from_hdf5_group_by_name original_keras_version = f.attrs['keras_version'].decode('utf8')

<ctrl+b>AttributeError: 'str' object has no attribute 'decode'** <ctrl+b>

<ctrl+b>..................More details of error are below...............<ctrl+b>

Using TensorFlow backend. Weights: coco Dataset: beagle Logs: /content/logs

Configurations: BACKBONE resnet101 BACKBONE_STRIDES [4, 8, 16, 32, 64] BATCH_SIZE 2 BBOX_STD_DEV [0.1 0.1 0.2 0.2] COMPUTE_BACKBONE_SHAPE None DETECTION_MAX_INSTANCES 100 DETECTION_MIN_CONFIDENCE 0.9 DETECTION_NMS_THRESHOLD 0.3 FPN_CLASSIF_FC_LAYERS_SIZE 1024 GPU_COUNT 1 GRADIENT_CLIP_NORM 5.0 IMAGES_PER_GPU 2 IMAGE_CHANNEL_COUNT 3 IMAGE_MAX_DIM 1024 IMAGE_META_SIZE 19 IMAGE_MIN_DIM 800 IMAGE_MIN_SCALE 0 IMAGE_RESIZE_MODE square IMAGE_SHAPE [1024 1024 3] LEARNING_MOMENTUM 0.9 LEARNING_RATE 0.001 LOSS_WEIGHTS {'rpn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_class_loss': 1.0, 'mrcnn_bbox_loss': 1.0, 'mrcnn_mask_loss': 1.0} MASK_POOL_SIZE 14 MASK_SHAPE [28, 28] MAX_GT_INSTANCES 100 MEAN_PIXEL [123.7 116.8 103.9] MINI_MASK_SHAPE (56, 56) NAME beagle NUM_CLASSES 7 POOL_SIZE 7 POST_NMS_ROIS_INFERENCE 1000 POST_NMS_ROIS_TRAINING 2000 PRE_NMS_LIMIT 6000 ROI_POSITIVE_RATIO 0.33 RPN_ANCHOR_RATIOS [0.5, 1, 2] RPN_ANCHOR_SCALES (32, 64, 128, 256, 512) RPN_ANCHOR_STRIDE 1 RPN_BBOX_STD_DEV [0.1 0.1 0.2 0.2] RPN_NMS_THRESHOLD 0.7 RPN_TRAIN_ANCHORS_PER_IMAGE 256 STEPS_PER_EPOCH 100 TOP_DOWN_PYRAMID_SIZE 256 TRAIN_BN False TRAIN_ROIS_PER_IMAGE 200 USE_MINI_MASK True USE_RPN_ROIS True VALIDATION_STEPS 50 WEIGHT_DECAY 0.0001

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:541: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:66: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:4432: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:2139: The name tf.nn.fused_batch_norm is deprecated. Please use tf.compat.v1.nn.fused_batch_norm instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:4267: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/keras/backend/tensorflow_backend.py:2239: The name tf.image.resize_nearest_neighbor is deprecated. Please use tf.compat.v1.image.resize_nearest_neighbor instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow_core/python/ops/array_ops.py:1475: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.where in 2.0, which has the same broadcast rule as np.where WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/mask_rcnn-2.1-py3.7.egg/mrcnn/model.py:553: The name tf.random_shuffle is deprecated. Please use tf.random.shuffle instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/mask_rcnn-2.1-py3.7.egg/mrcnn/utils.py:202: The name tf.log is deprecated. Please use tf.math.log instead.

WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/mask_rcnn-2.1-py3.7.egg/mrcnn/model.py:600: calling crop_and_resize_v1 (from tensorflow.python.ops.image_ops_impl) with box_ind is deprecated and will be removed in a future version. Instructions for updating: box_ind is deprecated, use box_indices instead Downloading pretrained model to /content/mask_rcnn_coco.h5 ... ... done downloading pretrained model! Loading weights /content/mask_rcnn_coco.h5 Traceback (most recent call last): File "beagle.py", line 397, in "mrcnn_bbox", "mrcnn_mask"]) File "/usr/local/lib/python3.7/dist-packages/mask_rcnn-2.1-py3.7.egg/mrcnn/model.py", line 2130, in load_weights File "/usr/local/lib/python3.7/dist-packages/keras/engine/saving.py", line 1224, in load_weights_from_hdf5_group_by_name original_keras_version = f.attrs['keras_version'].decode('utf8') AttributeError: 'str' object has no attribute 'decode'

try with keras 2.1.6

bhsnada avatar May 27 '21 07:05 bhsnada

@bhsnada

The same issue repeats again after using keras 2.1.6

Traceback (most recent call last): File "beagle.py", line 397, in "mrcnn_bbox", "mrcnn_mask"]) File "/usr/local/lib/python3.7/dist-packages/mask_rcnn-2.1-py3.7.egg/mrcnn/model.py", line 2130, in load_weights File "/usr/local/lib/python3.7/dist-packages/keras/engine/topology.py", line 3418, in load_weights_from_hdf5_group_by_name original_keras_version = f.attrs['keras_version'].decode('utf8') AttributeError: 'str' object has no attribute 'decode'

peppyguy avatar May 27 '21 07:05 peppyguy

@peppyguy, Could you detail it? only downgrading h5py or anything else? Thanks

QuanNguyenAUT avatar May 27 '21 08:05 QuanNguyenAUT

I solved the problem when I try to : !pip uninstall keras-nightly pip uninstall -y tensorflow and then install tensorflow and kerass with version you want to use

could you please share keras and tensorflow version that you are using?

pip install tensorflow-gpu==1.15.0 pip install keras==2.1.6

thanks a lot! worked for me.

nastaran-Ahmadi avatar May 27 '21 08:05 nastaran-Ahmadi

@peppyguy, Could you detail it? only downgrading h5py or anything else? Thanks

After following the steps suggested by @bhsnada , I downgraded the version of h5py to 2.10.0 then it works Thanks @bhsnada

peppyguy avatar May 27 '21 09:05 peppyguy

Thank you so much, @peppyguy and @bhsnada Now it works fine

QuanNguyenAUT avatar May 27 '21 09:05 QuanNguyenAUT

If you don't use tensorflow-gpu, try this tensorflow 1.14, keras 2.1.5 and h5py 2.10.0 (works for me)

dariodellamura avatar May 27 '21 09:05 dariodellamura

I solved the problem when I try to :

!pip uninstall keras-nightly pip uninstall -y tensorflow

and then install tensorflow and kerass with version you want to use

Fixed, for me! I added: !pip uninstall h5py !pip install h5py==2.10.0

Thanks so much

paolopac avatar May 27 '21 14:05 paolopac

!pip uninstall keras-nightly
!pip install h5py==2.10.0

I added this to the top of my code and the problem is now solved

ronithsaju avatar May 27 '21 15:05 ronithsaju

I added the code below in the beginning part and !pip uninstall keras-nightly !pip install h5py==2.10.0 then !pip uninstall keras-nightly !pip uninstall keras then !pip install keras==2.1.6 %tensorflow_version 1.x #this version is for google colab and then probem is solved

denashamss avatar May 27 '21 21:05 denashamss

Hello, I also faced the same problem. But I got stuck when unstalling keras-nighty on colab. What to type on colab?

  1. --yes
  2. -y 3)y

10Capture

Thanks in advance.

jasminjahanpuspo avatar May 28 '21 18:05 jasminjahanpuspo

Hello, I also faced the same problem. But I got stuck when unstalling keras-nighty on colab. What to type on colab?

  1. --yes
  2. -y 3)y

10Capture

Thanks in advance.

just type y and click enter

denashamss avatar May 28 '21 18:05 denashamss

@denashamss yes I type y but it didn't work. or it takes much time?

jasminjahanpuspo avatar May 28 '21 18:05 jasminjahanpuspo