5

libraries im using

import pixellib
from pixellib.instance import instance_segmentation
import cv2
import matplotlib.pyplot as plt

the script:

segment_image = instance_segmentation()
segment_image.load_model('mask_rcnn_coco.h5')
segmask, output = segment_image.segmentImage("images\example2.jpeg", show_bboxes = True)
cv2.imwrite("exampleoutput.jpeg", output)
print(output.shape)

I don't understand why it can't highlight different parts of the image.

Here is my output:

Here is my output

I looked into how other people used pixellib and it works perfectly with theirs.

output i'm expecting:

output i'm expecting

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
CLR
  • 51
  • 1

3 Answers3

0

Upgrade to the latest version of pixellib.

pip install pixellib --upgrade

And install tensorflow version 2.5.0

pip install tensorflow==2.5.0

Doing this fixed for me.

Arsh
  • 45
  • 1
  • 5
0

Firstly try to downgrade to Tensorflow version 2.8.0.

If it did not help yet, borrowing from GCK's answer in the link below, importing alter_bg solves it.

from pixellib.tune_bg import alter_bg

Custom Image segmentation has different results on different model loads Pixellib

If you still encountered an error saying:

cannot import name 'BatchNormalization' from 'tensorflow.python.keras.layers'

do as Abo_nosa suggests in the link below:

Go to Pixellib folder -> semantic -> deeplab.py and replace this line from tensorflow.python.keras.layers import BatchNormalization with this one from keras.layers.normalization.batch_normalization import BatchNormalization

ImportError: cannot import name 'BatchNormalization' from 'tensorflow.python.keras.layers'

Doing all the above solved it for me. Hope it also works out for you

Saman
  • 23
  • 4
0

Could not fix the problem with the Keras weights or layers hence switched to pointrend. Try downloading the pickled file for pointrend_resnet50 and do the following. It is way faster and accurate.

import torch
import pixellib
from pixellib.torchbackend.instance import instanceSegmentation

ins = instanceSegmentation()
ins.load_model("pointrend_resnet50.pkl")
ins.segmentImage("image_path.jpg", show_bboxes=True, 
output_image_name="image_path_out.jpg")
shrish
  • 1