ValueError: You are trying to load a weight file containing 293 layers into a model with 147 layers.
See original GitHub issueHi,
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,
Issue Analytics
- State:
- Created a year ago
- Comments:8
Top Results From Across the Web
You are trying to load a weight file containing 293 layers into a ...
python - ValueError: You are trying to load a weight file containing 293 layers into a model with 147 layers - Stack Overflow....
Read more >you are trying to load a weight file containing 00 layers into a ...
str(len(filtered_layers)) + ' layers.') ValueError: You are trying to load a weight file containing 24 layers into a model with 147 layers.
Read more >You are trying to load a weight file containing 0 layers into a ...
I'am currently using keras 2.1.5 in anaconda(windows). This is the error when I'am trying to load the weights file available online into VGG16...
Read more >'str' object has no attribute 'decode'解决方法:亲测成功。
len(filtered_layers): raise ValueError('You are trying to load a weight file ' 'containing ' + str(len(layer_names)) + ' layers into a model ...
Read more >error during loading a trained model - Kaggle
when i try to load a keras trained model it showing an error ValueError: You are trying to load a weight file containing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.