JianqiangWan / Super-BPD

Super-BPD: Super Boundary-to-Pixel Direction for Fast Image Segmentation (CVPR 2020)
Apache License 2.0
200 stars 37 forks source link

Could you explain the output data meaning? #9

Open chamecall opened 3 years ago

chamecall commented 3 years ago

The point is that the model works fast but bpd_cuda.forward call takes a large amount of time so the question is: what output data is and can I not to call bpd_cuda.forward to get data about segments?

Also is the network orientied for specific domain image content? Cause for my test images it results bad.

Original image 716c971s-960

Visualization grid result

root root

super_BPDs super_BPDs

super_BPDs_before_dilation super_BPDs_before_dilation

super_BPDs_after_dilation super_BPDs_after_dilation

my code to inference single image:

model = VGG16()
model.load_state_dict(torch.load('/home/algernone/git_projects/Super-BPD/saved/PascalContext_400000.pth'))

model.eval()
model.cuda()

image_path = '/home/algernone/test_imgs/716c971s-960.jpg'
image = cv2.imread(image_path, 1)
src_img = image.copy()
height, width = image.shape[:2]
image = image.astype(np.float32)
image -= IMAGE_MEAN
image = image.transpose(2, 0, 1)
image = image[np.newaxis]
image = torch.from_numpy(image)

tik = time()
pred_flux = model(image.cuda())
flux = pred_flux.data[0, ...]

vis_flux(src_img, flux)

angles = torch.atan2(flux[1,...], flux[0,...]) 
angles[angles < 0] += 2*math.pi 

height, width = angles.shape 

# unit: degree 
# theta_a, theta_l, theta_s, S_o, 45, 116, 68, 5 
results = bpd_cuda.forward(angles, height, width, 45, 116, 68, 5) 
root_points, super_BPDs_before_dilation, super_BPDs_after_dilation, super_BPDs = results 

root_points = root_points.cpu().numpy()
super_BPDs_before_dilation = super_BPDs_before_dilation.cpu().numpy()
super_BPDs_after_dilation = super_BPDs_after_dilation.cpu().numpy()
super_BPDs = super_BPDs.cpu().numpy()

cv2.imwrite('root.png', 255*(root_points > 0))
cv2.imwrite('super_BPDs.png', label2color(super_BPDs))
cv2.imwrite('super_BPDs_before_dilation.png', label2color(super_BPDs_before_dilation))
cv2.imwrite('super_BPDs_after_dilation.png', label2color(super_BPDs_after_dilation))
JianqiangWan commented 3 years ago

You may need to retrain BPD on your own dataset. There is a gap between the pictures in the PascalContext dataset and the ones you provided above.