ayoolaolafenwa / PixelLib

Visit PixelLib's official documentation https://pixellib.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValueError: You are trying to load a weight file containing 293 layers into a model with 147 layers.

Danish366 opened this issue · comments

Hi,

So, I was trying to use Pixellib to do some segmentation on a video and wanted to load the xception model that was trained on the Pascal voc dataset. Should've been a straight forward task with 5 lines of code, however, I ran into some issue:

I used the following link to download the model: https://github.com/ayoolaolafenwa/PixelLib/releases/download/1.1/deeplabv3_xception_tf_dim_ordering_tf_kernels.h5

But when I try to load the load, I get this error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 segment_video.load_pascalvoc_model("deeplabv3_xception_tf_dim_ordering_tf_kernels.h5")

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\pixellib\semantic\__init__.py:49, in semantic_segmentation.load_pascalvoc_model(self, model_path)
     46   self.sess = tf.compat.v1.Session(graph=self.graph)
     48 else:
---> 49   self.model.load_weights(model_path)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\keras\engine\training.py:2350, in Model.load_weights(self, filepath, by_name, skip_mismatch, options)
   2347       hdf5_format.load_weights_from_hdf5_group_by_name(
   2348           f, self.layers, skip_mismatch=skip_mismatch)
   2349     else:
-> 2350       hdf5_format.load_weights_from_hdf5_group(f, self.layers)
   2352 # Perform any layer defined finalization of the layer state.
   2353 for layer in self.layers:

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\keras\saving\hdf5_format.py:688, in load_weights_from_hdf5_group(f, layers)
    686 layer_names = filtered_layer_names
    687 if len(layer_names) != len(filtered_layers):
--> 688   raise ValueError('You are trying to load a weight file '
    689                    'containing ' + str(len(layer_names)) +
    690                    ' layers into a model with ' + str(len(filtered_layers)) +
    691                    ' layers.')
    693 # We batch weight value assignments in a single backend call
    694 # which provides a speedup in TensorFlow.
    695 weight_value_tuples = []

ValueError: You are trying to load a weight file containing 293 layers into a model with 147 layers.

Following is the code that I am using:

import pixellib
from pixellib.semantic import semantic_segmentation
segment_video = semantic_segmentation()
segment_video.load_pascalvoc_model("deeplabv3_xception_tf_dim_ordering_tf_kernels.h5")

Kindly look into this issue and let me know how to resolve it.

Thanks,

I fixed using installing Tensorflow==2.6.0 and Keras==2.6.0

!pip3 install tensorflow==2.6.0
!pip3 install keras==2.6.0

I fixed using installing Tensorflow==2.6.0 and Keras==2.6.0

!pip3 install tensorflow==2.6.0 !pip3 install keras==2.6.0

Thanks. So, the potential fix is to downgrade the TF from 2.9.1 to 2.6.0 and Keras from 2.9.0 to 2.6.0 because PixelLib is not compatible with the newer versions?

I fixed using installing Tensorflow==2.6.0 and Keras==2.6.0
!pip3 install tensorflow==2.6.0 !pip3 install keras==2.6.0

Thanks. So, the potential fix is to downgrade the TF from 2.9.1 to 2.6.0 and Keras from 2.9.0 to 2.6.0 because PixelLib is not compatible with the newer versions?

I think so.
One more thing!!
When you are training there are more error maybe will come.
So in that case
Try...
!pip3 install tensorflow==2.6.0
!pip3 install keras==2.6.0
!pip3 install imgaug
!pip3 install pillow==8.2.0
!pip install pixellib==0.5.2
!pip install labelme2coco==0.1.2

In the Evaluation Step if you may get
like this!!
/content/mask_rcnn_models/mask_rcnn_model.001-2.073964.h5 evaluation using iou_threshold 0.5 is 0.000000

I this case try this..
!pip3 install tensorflow==2.5.0

Gotcha! Thanks.

I fixed using installing Tensorflow==2.6.0 and Keras==2.6.0
!pip3 install tensorflow==2.6.0 !pip3 install keras==2.6.0

Thanks. So, the potential fix is to downgrade the TF from 2.9.1 to 2.6.0 and Keras from 2.9.0 to 2.6.0 because PixelLib is not compatible with the newer versions?

I think so. One more thing!! When you are training there are more error maybe will come. So in that case Try... !pip3 install tensorflow==2.6.0 !pip3 install keras==2.6.0 !pip3 install imgaug !pip3 install pillow==8.2.0 !pip install pixellib==0.5.2 !pip install labelme2coco==0.1.2

In the Evaluation Step if you may get like this!! /content/mask_rcnn_models/mask_rcnn_model.001-2.073964.h5 evaluation using iou_threshold 0.5 is 0.000000

I this case try this.. !pip3 install tensorflow==2.5.0

Gotcha! Thanks.

!pip3 install tensorflow==2.6.0
!pip3 install keras==2.6.0

Hey!
I have had the same value error issue even after downgrading TensorFlow to 2.6.0 and Keras to 2.6.0. Do you know the reason?

!pip3 install tensorflow==2.6.0
!pip3 install keras==2.6.0

Hey! I have had the same value error issue even after downgrading TensorFlow to 2.6.0 and Keras to 2.6.0. Do you know the reason?

I don't know the reason !!
Its working or NOT?

Yeah this worked...

I fixed using installing Tensorflow==2.6.0 and Keras==2.6.0
!pip3 install tensorflow==2.6.0 !pip3 install keras==2.6.0

Thanks. So, the potential fix is to downgrade the TF from 2.9.1 to 2.6.0 and Keras from 2.9.0 to 2.6.0 because PixelLib is not compatible with the newer versions?

I think so. One more thing!! When you are training there are more error maybe will come. So in that case Try... !pip3 install tensorflow==2.6.0 !pip3 install keras==2.6.0 !pip3 install imgaug !pip3 install pillow==8.2.0 !pip install pixellib==0.5.2 !pip install labelme2coco==0.1.2

In the Evaluation Step if you may get like this!! /content/mask_rcnn_models/mask_rcnn_model.001-2.073964.h5 evaluation using iou_threshold 0.5 is 0.000000

I this case try this.. !pip3 install tensorflow==2.5.0

Thanks! This did the job for me in colab.

I fixed using installing Tensorflow==2.6.0 and Keras==2.6.0

!pip3 install tensorflow==2.6.0 !pip3 install keras==2.6.0

I tried this and still same error

@baselsaad123
I did this in very long back.
Maybe its due to new version of other packages.