How to get centre of the segmentation (dusty-nv)

Hi,

I am looking at this forum

I did my own segmentation, and when I tried to print out the number of class, I got 21, but I only have 4 classes including background… not sure why.
P.S.: My classes.txt only has four lines.
P.S.: I follow this link for custom-segmentation (maybe the problem is from here…?)

	num_classes = net.GetNumClasses()

	print("######################")
	print("grid size:  {:d}x{:d}".format(grid_width,grid_height))
	print("num classes:  {:d}".format(num_classes))
	print("######################")
	class_mask = buffers.mask
	mask_array = jetson.utils.cudaToNumpy(class_mask)
	# compute the number of times each class occurs in the mask
	class_histogram, _ = np.histogram(mask_array, num_classes)

	print('grid size:   {:d}x{:d}'.format(grid_width, grid_height))
	print('num classes: {:d}'.format(num_classes))

	print('-----------------------------------------')
	print(' ID  class name        count     %')
	print('-----------------------------------------')

	for n in range(num_classes):
		percentage = float(class_histogram[n]) / float(grid_width * grid_height)
		print(' {:>2d}  {:<18s} {:>3d}   {:f}'.format(n, str(net.GetClassDesc(n)),class_histogram[n], percentage)) 
######################
grid size:   10x10
num classes: 21
-----------------------------------------
 ID  class name        count     %
-----------------------------------------
  0  background         651332   6513.320000
  1 label1      1942   19.420000
  2  label2           1765   17.650000
  3  label3           1695   16.950000
  4  None               1598   15.980000
  5  None               1530   15.300000
  6  None               1514   15.140000
  7  None               1493   14.930000
  8  None               1429   14.290000
  9  None               1390   13.900000
 10  None               1372   13.720000
 11  None               1356   13.560000
 12  None               1347   13.470000
 13  None               1335   13.350000
 14  None               1347   13.470000
 15  None               1316   13.160000
 16  None               1328   13.280000
 17  None               1322   13.220000
 18  None               1357   13.570000
 19  None               1388   13.880000
 20  None               12044   120.440000

And I would like to get the center point of each segment, top, bottom, far left and far right points. Is there any easy way to do it? If not, I may need to use the opencv contour for each segment…Thx

Hi,

I saw this option,

  --output-blob=OUTPUT name of the output layer (default: 'score_fr_21classes')

I am currently using this

--output_blob="output_0"

How can I change back to 4 classes? Thx

It would seem like your model was still trained with 21 classes and not 4. From the training script, it looks like you would need to specify --classes=4 during training.

Yes, I think you would need to use OpenCV to do the blobbing of the segmentation mask and extract the bounding coordinates from that.

Yep, it is working now. Thx Dusty
It is funny if I add
“import cv2” in the segnet.py, there is no display window…
Still trying to figure it out…

This is rather un-Pythonic, but try doing the import cv2 after the jetson.utils.videoOutput object is created. It seems possible that OpenCV does things with the OpenGL bindings.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.