Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load model during image segmentation #68

Closed
alic-xc opened this issue Jun 2, 2021 · 3 comments
Closed

Unable to load model during image segmentation #68

alic-xc opened this issue Jun 2, 2021 · 3 comments

Comments

@alic-xc
Copy link

alic-xc commented Jun 2, 2021

HI guys,
I'm having trouble during loading of model.

WARNING:tensorflow:From /Users/aladelekan/.local/share/virtualenvs/testsegment-3avR_sav/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py:605: calling map_fn_v2 (from tensorflow.python.ops.map_fn) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Use fn_output_signature instead
2021-06-02 15:28:25.934049: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
Traceback (most recent call last):
  File "/Users/aladelekan/Documents/testsegment/test-detect.py", line 15, in <module>
    segment_image.load_model("mask_rcnn_model.h5")
  File "/Users/aladelekan/.local/share/virtualenvs/testsegment-3avR_sav/lib/python3.7/site-packages/pixellib/instance.py", line 60, in load_model
    self.model.load_weights(model_path, by_name= True)
  File "/Users/aladelekan/.local/share/virtualenvs/testsegment-3avR_sav/lib/python3.7/site-packages/pixellib/mask_rcnn.py", line 2111, in load_weights
    hdf5_format.load_weights_from_hdf5_group_by_name(f, layers)
  File "/Users/aladelekan/.local/share/virtualenvs/testsegment-3avR_sav/lib/python3.7/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 788, in load_weights_from_hdf5_group_by_name
    str(weight_values[i].shape) + '.')
ValueError: Layer #221 (named "mrcnn_bbox_fc"), weight <tf.Variable 'mrcnn_bbox_fc/kernel:0' shape=(1024, 324) dtype=float32> has shape (1024, 324), but the saved weight has shape (1024, 8).

Process finished with exit code 1

any help will be appreciated.

@ayoolaolafenwa
Copy link
Owner

@alic-xc Share the code you used for inference.

@alic-xc
Copy link
Author

alic-xc commented Jun 5, 2021

After i've trained my model. i tried instance segmentation which gave me error.

import os

import pixellib
from pixellib.instance import instance_segmentation
segment_image = instance_segmentation()
segment_image.load_model("mask_rcnn_coco.h5")
segment_image.segmentImage("earlyFingerling111.jpg", show_bboxes = True, output_image_name = "image_new.jpg")

WARNING:tensorflow:From /Users/aladelekan/.local/share/virtualenvs/testsegment-3avR_sav/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py:605: calling map_fn_v2 (from tensorflow.python.ops.map_fn) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Use fn_output_signature instead
2021-06-05 08:40:47.395083: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
Traceback (most recent call last):
  File "test-detect.py", line 16, in <module>
    segment_image.load_model("mask_rcnn_coco.h5")
  File "/Users/aladelekan/.local/share/virtualenvs/testsegment-3avR_sav/lib/python3.7/site-packages/pixellib/instance.py", line 60, in load_model
    self.model.load_weights(model_path, by_name= True)
  File "/Users/aladelekan/.local/share/virtualenvs/testsegment-3avR_sav/lib/python3.7/site-packages/pixellib/mask_rcnn.py", line 2111, in load_weights
    hdf5_format.load_weights_from_hdf5_group_by_name(f, layers)
  File "/Users/aladelekan/.local/share/virtualenvs/testsegment-3avR_sav/lib/python3.7/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 788, in load_weights_from_hdf5_group_by_name
    str(weight_values[i].shape) + '.')
ValueError: Layer #221 (named "mrcnn_bbox_fc"), weight <tf.Variable 'mrcnn_bbox_fc/kernel:0' shape=(1024, 324) dtype=float32> has shape (1024, 324), but the saved weight has shape (1024, 8).

@ayoolaolafenwa
Copy link
Owner

@alic-xc you used the wrong code for inference. This is the code for performing inference with your custom trained model.

import pixellib
from pixellib.instance import custom_segmentation

segment_image = custom_segmentation()
#inference configuration for your cutom model to state  the number of classes and class names
#change it to your trained model configuration
segment_image.inferConfig(num_classes= 2, class_names= ["BG", "butterfly", "squirrel"])
segment_image.load_model("mask_rcnn_model/Nature_model_resnet101.h5")
segment_image.segmentImage("sample2.jpg", show_bboxes=True) 

Read my tutorial on performing inference with custom models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants