Comments (18)
Dear ayoolaolafenwa
Thank you for the very nice program.
I want to use the Instance segmentation mask values to count and meassure the objects, but with the recently introduced command mask_points_values=True I get an error message, see below.
Without mask_points_values=True it works, but I only get [False False False].
Alternatively, is it possible to generate an output without the original image overlay, like it is possible in the semantic segmentation?
You may implement the command: overlay = False in the Instance Segmentation.
Then I will investigate the areas with Opencv.
My program:
import cv2
import pixellib
from pixellib.instance import instance_segmentation
segment_image = instance_segmentation()
segment_image.load_model("mask_rcnn_coco.h5")
seg, output = segment_image.segmentImage("k.jpg", extract_segmented_objects=True, save_extracted_objects =True,
show_bboxes=True, output_image_name= "a.jpg", mask_points_values=True)
print(seg['masks'])
......
Processed image saved successfully in your current working directory.
Traceback (most recent call last):
File "C:\Users\User\Desktop\ki\in2.py", line 22, in <module>
seg, output = segment_image.segmentImage("k.jpg", extract_segmented_objects=True, save_extracted_objects =True,
File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\pixellib\instance.py", line 284, in segmentImage
for a in range(extract_mask.shape[2]):
IndexError: tuple index out of range
C:\Users\User\Desktop\ki>
from pixellib.
Thank you @whoafridi. The results return boloean values of masks by default. You can convert the mask values to integer if you want to and easily access the mask values only by using this modified code below.
import pixellib
from pixellib.instance import custom_segmentation
seg = custom_segmentation()
seg.inferConfig(num_classes= 2,class_names=["BG", "butterfly", "squirrel"])
seg.load_model("Nature_model_resnet101.h5")
segvalues, output = seg.segmentImage("sample.jpg", show_bboxes=True)
#Access the mask values only and convert the boolean mask values to integer
mask_values = segvalues['masks'].astype('int')
#It will print out the mask values as an array of 0s.
print(mask_values)
from pixellib.
@whoafridi The pixel values of the masks are returned as boolean values. You want to obtain the actual polygon points or values of the masks.
I would soon release a new version of PixelLib, that would provide the option to return the actual polygon values of the masks.
from pixellib.
Great. Is it release next year?
from pixellib.
Soon. Before next year.
from pixellib.
Great & thanks for responding ๐
Hope find something another cool things again.
from pixellib.
@whoafridi upgrade to the latest version of pixellib using
pip3 install pixellib --upgrade
Make use of this modified code to return the polygon points' values of the masks.
import pixellib
from pixellib.instance import custom_segmentation
seg = custom_segmentation()
seg.inferConfig(num_classes= 2,class_names=["BG", "butterfly", "squirrel"])
seg.load_model("Nature_model_resnet101.h5")
#added a new parameter """mask_points_values""" to return the masks's polygon points' values
segvalues, output = seg.segmentImage("sample.jpg", show_bboxes = True, mask_points_values=True)
print(segvalues['masks'])
from pixellib.
The returned polygon points' values would show results like this below;
[[array([[ 809, 173],
[ 808, 174],
[ 803, 174],
[ 802, 175],
[ 798, 175],
[ 797, 176],
[ 796, 176],
[ 795, 177],
[ 794, 177],
[ 793, 178],
[ 792, 178],
[ 789, 181],
[ 788, 181],
[ 787, 182],
[ 786, 182],
[ 785, 183],
[ 784, 183],
[ 783, 184],
[ 782, 184],
[ 781, 185],
[ 780, 185],
[ 777, 188],
[ 776, 188],
[ 772, 192],
[ 771, 192],
[ 769, 194],
[ 768, 194],
[ 766, 196],
[ 765, 196],
[ 764, 197],
[ 763, 197],
[ 757, 203],
[ 757, 204],
[ 754, 207],
[ 754, 208],
[ 749, 213],
[ 749, 214],
[ 748, 215],
[ 748, 216],
[ 747, 217],
[ 747, 219],
[ 746, 220],
[ 746, 224],
[ 745, 225],
[ 745, 228],
[ 744, 229],
[ 744, 231],
[ 743, 232],
[ 743, 234],
[ 742, 235],
[ 742, 236],
[ 741, 237],
[ 741, 238],
[ 740, 239],
[ 740, 240],
[ 739, 241],
[ 739, 243],
[ 738, 244],
[ 738, 246],
[ 737, 247],
[ 737, 250],
[ 736, 251],
[ 736, 254],
[ 735, 255],
[ 735, 259],
[ 734, 260],
[ 734, 264],
[ 733, 265],
[ 733, 267],
[ 732, 268],
[ 732, 269],
[ 731, 270],
[ 731, 271],
[ 728, 274],
[ 728, 275],
[ 726, 277],
[ 726, 280],
[ 725, 281],
[ 725, 286],
[ 724, 287],
[ 724, 294],
[ 723, 295],
[ 723, 316],
[ 722, 317],
[ 722, 329],
[ 721, 330],
[ 721, 336],
[ 720, 337],
[ 720, 339],
[ 719, 340],
[ 719, 342],
[ 718, 343],
[ 718, 344],
[ 717, 345],
[ 717, 346],
[ 716, 347],
[ 716, 348],
[ 715, 349],
[ 715, 351],
[ 714, 352],
[ 714, 353],
[ 713, 354],
[ 713, 357],
[ 712, 358],
[ 712, 361],
[ 711, 362],
[ 711, 370],
[ 710, 371],
[ 710, 374],
[ 711, 375],
[ 711, 376],
[ 712, 377],
[ 712, 378],
[ 715, 381],
[ 715, 382],
[ 720, 387],
[ 721, 387],
[ 724, 390],
[ 725, 390],
[ 726, 391],
[ 727, 391],
[ 728, 392],
[ 729, 392],
[ 730, 393],
[ 731, 393],
[ 732, 394],
[ 733, 394],
[ 734, 395],
[ 735, 395],
[ 736, 396],
[ 738, 396],
[ 739, 397],
[ 741, 397],
[ 742, 398],
[ 743, 398],
[ 744, 399],
[ 745, 399],
[ 746, 400],
[ 747, 400],
[ 748, 401],
[ 749, 401],
[ 750, 402],
[ 751, 402],
[ 752, 403],
[ 753, 403],
[ 754, 404],
[ 756, 404],
[ 757, 405],
[ 758, 405],
[ 759, 406],
[ 762, 406],
[ 763, 407],
[ 766, 407],
[ 767, 408],
[ 770, 408],
[ 771, 409],
[ 773, 409],
[ 774, 410],
[ 776, 410],
[ 777, 411],
[ 778, 411],
[ 780, 413],
[ 781, 413],
[ 783, 415],
[ 784, 415],
[ 785, 416],
[ 788, 416],
[ 789, 417],
[ 794, 417],
[ 795, 418],
[ 799, 418],
[ 800, 419],
[ 804, 419],
[ 805, 420],
[ 809, 420],
[ 810, 421],
[ 813, 421],
[ 814, 422],
[ 816, 422],
[ 817, 423],
[ 820, 423],
[ 821, 424],
[ 865, 424],
[ 866, 425],
[ 882, 425],
[ 883, 426],
[ 906, 426],
[ 907, 425],
[ 916, 425],
[ 917, 424],
[ 919, 424],
[ 920, 423],
[ 922, 423],
[ 923, 422],
[ 925, 422],
[ 926, 421],
[ 928, 421],
[ 929, 420],
[ 950, 420],
[ 951, 419],
[ 962, 419],
[ 963, 418],
[ 975, 418],
[ 976, 417],
[ 981, 417],
[ 982, 416],
[ 985, 416],
[ 986, 415],
[ 988, 415],
[ 989, 414],
[ 990, 414],
[ 991, 413],
[ 992, 413],
[ 991, 412],
[ 990, 412],
[ 988, 410],
[ 987, 410],
[ 985, 408],
[ 984, 408],
[ 980, 404],
[ 979, 404],
[ 978, 403],
[ 977, 403],
[ 976, 402],
[ 975, 402],
[ 974, 401],
[ 962, 401],
[ 961, 400],
[ 959, 400],
[ 958, 399],
[ 956, 399],
[ 955, 398],
[ 954, 398],
[ 953, 397],
[ 951, 397],
[ 950, 396],
[ 949, 396],
[ 948, 395],
[ 947, 395],
[ 942, 390],
[ 941, 390],
[ 939, 388],
[ 939, 387],
[ 936, 384],
[ 936, 383],
[ 937, 382],
[ 937, 380],
[ 938, 379],
[ 938, 377],
[ 939, 376],
[ 939, 373],
[ 940, 372],
[ 940, 371],
[ 941, 370],
[ 941, 369],
[ 942, 368],
[ 942, 367],
[ 943, 366],
[ 943, 365],
[ 945, 363],
[ 946, 363],
[ 948, 361],
[ 949, 361],
[ 950, 360],
[ 951, 360],
[ 952, 359],
[ 956, 359],
[ 957, 358],
[ 962, 358],
[ 963, 357],
[ 972, 357],
[ 973, 356],
[ 978, 356],
[ 979, 355],
[ 983, 355],
[ 984, 354],
[ 988, 354],
[ 989, 353],
[ 992, 353],
[ 993, 352],
[ 997, 352],
[ 998, 351],
[ 999, 351],
[1000, 350],
[1001, 350],
[1002, 349],
[1003, 349],
[1005, 347],
[1006, 347],
[1009, 344],
[1009, 342],
[1010, 341],
[1010, 338],
[1011, 337],
[1011, 334],
[1010, 333],
[1010, 331],
[1009, 330],
[1009, 329],
[1008, 328],
[1008, 326],
[1006, 324],
[1006, 323],
[1004, 321],
[1004, 320],
[1003, 319],
[1003, 318],
[1002, 317],
[1002, 316],
[ 998, 312],
[ 997, 312],
[ 995, 310],
[ 994, 310],
[ 990, 306],
[ 990, 305],
[ 989, 304],
[ 988, 304],
[ 986, 302],
[ 985, 302],
[ 984, 301],
[ 983, 301],
[ 976, 294],
[ 975, 294],
[ 973, 292],
[ 972, 292],
[ 971, 291],
[ 970, 291],
[ 968, 289],
[ 967, 289],
[ 965, 287],
[ 965, 286],
[ 964, 286],
[ 962, 284],
[ 961, 284],
[ 960, 283],
[ 959, 283],
[ 957, 281],
[ 956, 281],
[ 950, 275],
[ 948, 275],
[ 947, 274],
[ 945, 274],
[ 944, 273],
[ 941, 273],
[ 940, 272],
[ 921, 272],
[ 920, 273],
[ 901, 273],
[ 900, 272],
[ 890, 272],
[ 889, 271],
[ 887, 271],
[ 886, 270],
[ 885, 270],
[ 884, 269],
[ 883, 269],
[ 882, 268],
[ 881, 268],
[ 880, 267],
[ 883, 264],
[ 883, 263],
[ 884, 262],
[ 884, 261],
[ 885, 260],
[ 885, 258],
[ 886, 257],
[ 886, 256],
[ 887, 255],
[ 887, 254],
[ 888, 253],
[ 888, 252],
[ 889, 251],
[ 889, 250],
[ 891, 248],
[ 891, 247],
[ 892, 246],
[ 892, 243],
[ 893, 242],
[ 893, 228],
[ 889, 224],
[ 889, 223],
[ 888, 222],
[ 888, 221],
[ 887, 220],
[ 887, 219],
[ 886, 218],
[ 886, 216],
[ 885, 215],
[ 885, 213],
[ 884, 212],
[ 884, 210],
[ 883, 209],
[ 883, 208],
[ 874, 199],
[ 874, 198],
[ 870, 194],
[ 869, 194],
[ 868, 193],
[ 867, 193],
[ 861, 187],
[ 860, 187],
[ 858, 185],
[ 857, 185],
[ 856, 184],
[ 855, 184],
[ 854, 183],
[ 853, 183],
[ 849, 179],
[ 848, 179],
[ 846, 177],
[ 845, 177],
[ 844, 176],
[ 841, 176],
[ 840, 175],
[ 837, 175],
[ 836, 174],
[ 830, 174],
[ 829, 173]])], [array([[471, 138],
[470, 139],
[462, 139],
...,
[492, 139],
[485, 139],
[484, 138]])], [array([[127, 80],
[126, 81],
[124, 81],
[123, 82],
[122, 82],
[119, 85],
[118, 85],
[117, 86],
[114, 86],
[113, 87],
[111, 87],
[110, 88],
[107, 88],
[106, 89],
[105, 89],
[ 98, 96],
[ 97, 96],
[ 95, 98],
[ 94, 98],
[ 93, 99],
[ 92, 99],
[ 90, 101],
[ 89, 101],
[ 87, 103],
[ 87, 106],
[ 86, 107],
[ 86, 111],
[ 85, 112],
[ 85, 121],
[ 84, 122],
[ 84, 140],
[ 85, 141],
[ 85, 152],
[ 86, 153],
[ 86, 158],
[ 87, 159],
[ 87, 162],
[ 88, 163],
[ 88, 166],
[ 89, 167],
[ 89, 171],
[ 90, 172],
[ 90, 176],
[ 89, 177],
[ 89, 179],
[ 88, 180],
[ 88, 183],
[ 87, 184],
[ 87, 187],
[ 86, 188],
[ 86, 190],
[ 85, 191],
[ 85, 194],
[ 84, 195],
[ 84, 198],
[ 83, 199],
[ 83, 200],
[ 82, 201],
[ 82, 202],
[ 81, 203],
[ 81, 205],
[ 80, 206],
[ 80, 209],
[ 79, 210],
[ 79, 233],
[ 78, 234],
[ 78, 241],
[ 77, 242],
[ 77, 245],
[ 76, 246],
[ 76, 248],
[ 75, 249],
[ 75, 251],
[ 74, 252],
[ 74, 255],
[ 73, 256],
[ 73, 260],
[ 72, 261],
[ 72, 264],
[ 71, 265],
[ 71, 268],
[ 70, 269],
[ 70, 273],
[ 69, 274],
[ 69, 280],
[ 70, 281],
[ 70, 282],
[ 74, 286],
[ 74, 287],
[ 76, 289],
[ 78, 289],
[ 79, 290],
[ 80, 290],
[ 81, 291],
[ 83, 291],
[ 84, 292],
[ 86, 292],
[ 87, 293],
[ 89, 293],
[ 90, 294],
[ 91, 294],
[ 94, 297],
[ 94, 298],
[ 95, 299],
[ 95, 300],
[ 96, 301],
[ 96, 306],
[ 97, 307],
[ 97, 315],
[ 96, 316],
[ 96, 318],
[ 95, 319],
[ 95, 322],
[ 94, 323],
[ 94, 332],
[ 95, 333],
[ 95, 338],
[ 96, 339],
[ 96, 341],
[ 97, 342],
[ 97, 343],
[ 98, 344],
[ 98, 346],
[ 99, 347],
[ 99, 349],
[102, 352],
[103, 352],
[105, 354],
[107, 354],
[108, 355],
[109, 355],
[110, 356],
[111, 356],
[112, 357],
[113, 357],
[115, 359],
[116, 359],
[119, 362],
[120, 362],
[121, 363],
[122, 363],
[123, 364],
[124, 364],
[125, 365],
[128, 365],
[129, 366],
[131, 366],
[132, 367],
[134, 367],
[135, 368],
[137, 368],
[138, 369],
[139, 369],
[140, 370],
[142, 370],
[143, 371],
[146, 371],
[147, 372],
[151, 372],
[152, 373],
[154, 373],
[155, 374],
[158, 374],
[159, 375],
[162, 375],
[163, 376],
[167, 376],
[168, 377],
[184, 377],
[185, 376],
[188, 376],
[189, 375],
[190, 375],
[191, 374],
[192, 374],
[203, 363],
[203, 362],
[204, 361],
[204, 355],
[205, 354],
[205, 347],
[206, 346],
[206, 341],
[207, 340],
[207, 335],
[208, 334],
[208, 327],
[209, 326],
[209, 313],
[210, 312],
[210, 308],
[211, 307],
[211, 305],
[212, 304],
[212, 302],
[213, 301],
[213, 299],
[214, 298],
[214, 297],
[215, 296],
[215, 295],
[216, 294],
[216, 292],
[217, 291],
[217, 290],
[218, 289],
[218, 287],
[219, 286],
[219, 285],
[220, 284],
[220, 283],
[221, 282],
[221, 280],
[222, 279],
[221, 278],
[221, 267],
[220, 266],
[220, 264],
[219, 263],
[219, 261],
[218, 260],
[218, 259],
[217, 258],
[217, 257],
[216, 256],
[216, 255],
[215, 254],
[215, 253],
[210, 248],
[210, 247],
[207, 244],
[207, 243],
[206, 242],
[206, 241],
[205, 240],
[205, 238],
[204, 237],
[204, 236],
[203, 235],
[203, 233],
[202, 232],
[203, 231],
[203, 230],
[204, 229],
[204, 228],
[208, 224],
[212, 224],
[213, 223],
[214, 223],
[214, 222],
[219, 217],
[219, 216],
[220, 215],
[220, 214],
[221, 213],
[221, 211],
[222, 210],
[222, 188],
[221, 187],
[221, 182],
[220, 181],
[220, 177],
[219, 176],
[219, 174],
[218, 173],
[218, 171],
[217, 170],
[217, 168],
[216, 167],
[216, 164],
[215, 163],
[215, 160],
[214, 159],
[214, 156],
[213, 155],
[213, 153],
[212, 152],
[212, 151],
[211, 150],
[211, 149],
[210, 148],
[210, 147],
[209, 146],
[209, 145],
[207, 143],
[207, 142],
[206, 141],
[206, 140],
[205, 139],
[205, 137],
[204, 136],
[204, 135],
[203, 134],
[203, 133],
[202, 132],
[202, 131],
[201, 130],
[201, 129],
[200, 128],
[200, 127],
[198, 125],
[198, 124],
[192, 118],
[192, 117],
[191, 116],
[191, 115],
[182, 106],
[182, 105],
[181, 104],
[181, 103],
[179, 101],
[179, 100],
[173, 94],
[173, 93],
[172, 92],
[171, 92],
[168, 89],
[167, 89],
[166, 88],
[165, 88],
[164, 87],
[162, 87],
[161, 86],
[159, 86],
[158, 85],
[156, 85],
[155, 84],
[151, 84],
[150, 83],
[146, 83],
[145, 82],
[144, 82],
[143, 81],
[138, 81],
[137, 80]])]]
from pixellib.
Amazing & thank you for great success in the upcoming time . Take care
from pixellib.
@whoafridi If you want to integrate PixelLib with an API, it depends on you. I have created a detailed tutorial on this repo on how to use PixelLib, it is of you to choose how you want to integrate it with the API you intend to use.
from pixellib.
but the value is only zero . used your code
[[[0 0 0]
[0 0 0]
[0 0 0]
...
[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]
...
[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]
...
[0 0 0]
[0 0 0]
[0 0 0]]
...
[[0 0 0]
[0 0 0]
[0 0 0]
...
[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]
...
[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]
...
[0 0 0]
[0 0 0]
[0 0 0]]]
from pixellib.
Yes that is the mask value nothing is wrong with it. I have commented that it will return an array of 0s as mask values when converted to integer.
from pixellib.
Is it possible to return the actual value instead of 0's . For my project I need that
from pixellib.
What do you mean? That is the value of masks. You can read this article about masks.
from pixellib.
Actually the mask/points have a pixel values. Can an we return the mask/polygon values? 0,1 isn't answer I guess
from pixellib.
Amazing & thank you for great success in the upcoming time . Take care
You are welcome.
from pixellib.
May be late in the party but this might help someone.
segmask, output = ins.segmentImage("input.jpeg", show_bboxes=False, output_image_name="output_image.jpg", extract_segmented_objects= True, mask_points_values=True)
mask_values = segmask['masks'][0][0]
obj_mask_points = [ [p[0], p[1]] for p in mask_values ]
mask = np.zeros(inp_img.shape, dtype = inp_img.dtype)
mask = cv2.fillPoly(mask, [np.array(obj_mask_points)], (255, 255, 255))
from pixellib.
Moving forward the background of image can be removed using the calculated mask using following statment.
bg_removed = cv2.bitwise_and(inp_img, mask)
from pixellib.
Related Issues (20)
- UnpicklingError: A load persistent id instruction was encountered, but no persistent_load function was specified.
- #389 layer
- ImportError: cannot import name 'semantic_segmentation' from 'pixellib.semantic' HOT 7
- Error when checking input: expected input_image_meta to have shape (18,) but got array with shape (16,) during last step HOT 1
- Error when loading a pretrained model
- Loading Custom Dataset error HOT 4
- Is training with different labels in the same image possible? HOT 3
- labelme2coco does not work with Windows 11 HOT 4
- training time does not reduces after increasing batch_size on 32 GB CPU instance HOT 1
- What are the correct corresponding versions of pixlib and TensorFlow๏ผ HOT 1
- sometimes image does not get segmented with polygon bounding boxes but only with rectangle bounding boxes
- Using pixelLib simply for segmetnation. HOT 1
- Custom Segmentation - Errno 13 error HOT 2
- Semantic segmentation output rgb values do not match input class values
- Error:No pointrend_resnet50 model found
- PIL.Image AttributeError HOT 1
- mask label for training
- Make segment overlay invisible
- For newer version of Tensorflow, you should change code.
- not useful
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pixellib.