pathak22 / videoseg

[CVPR 2017] Video motion segmentation and tracking
https://people.eecs.berkeley.edu/~pathak/unsupervised_video/
MIT License
182 stars 30 forks source link

crf bugs #1

Open iammarvelous opened 7 years ago

iammarvelous commented 7 years ago

When I try run_full, it throws the following error during crf step.

Traceback (most recent call last):                                                                                                  
  File "run_full.py", line 275, in <module>                                                                                         
    demo_images()                                                                                                                   
  File "run_full.py", line 240, in demo_images                                                                                      
    negTh=negTh, crfParams=args.crfParams)                                                                                          
  File "/backups4/yzl5709/github/unsupervised-video/videoseg/src/crf.py", line 94, in refine_crf                                    
    U = compute_unary(lb, M)                                                                                                        
  File "/backups4/yzl5709/github/unsupervised-video/videoseg/src/../lib/pydensecrf/pydensecrf/utils.py", line 52, in compute_unary  
    return unary_from_labels(labels, M, GT_PROB)                                                                                    
  File "/backups4/yzl5709/github/unsupervised-video/videoseg/src/../lib/pydensecrf/pydensecrf/utils.py", line 40, in unary_from_labe
ls                                                                                                                                  
    U[labels - 1 if zero_unsure else labels, np.arange(U.shape[1])] = p_energy                                                      
IndexError: index 255 is out of bounds for axis 0 with size 3           

In fact, the two versions in crf demo are not the same. The following change should be made.

# PIL version of code:
im = np.array(Image.open(args.inIm))
lb, _, _ = relabel_sequential(np.array(Image.open(args.inL)))
lb[lb==0] = 3; lb[lb==2] = 0; lb[lb==3] = 2
lb = lb.astype(np.int64)
out = refine_crf(im, lb, gtProb=args.gtProb)
Image.fromarray(out * 255).save(args.outIm)
pathak22 commented 7 years ago

Actually, different versions of crf code had different way of shaping the image. I am handling it lazily in comments (i know its not clean! :( ). But yes, if you are using PIL and running on default crf examples, then you need to uncomment the lines as you correctly pointed out above.

Moreover, if you want to handle it programmatically (unlike I did it in comments), then feel free to do a pull request and I will be happy to merge it. Hope this answers your question.

iammarvelous commented 7 years ago

Well, I haven't looked deeper into the code. The demo part is easy to fix. But when I use run_full.py, it returns that error. It looks like similar reason. Did you test run_full.py?

iammarvelous commented 7 years ago

BTW, uncomment that line solely does not solve the problem. You need to convert the type.

sid87 commented 6 years ago

When labels having 0 values are sent to U[labels - 1 if zero_unsure else labels, np.arange(U.shape[1])] = p_energy labels-1 operation gives 255 wherever there is a 0(because dtype of labels is uint8) which causes the IndexOutOfRange range error. We need to make sure that 0s are not passed in labels. As a workaround for now, I've replaced the above line of code with U[labels, np.arange(U.shape[1])] = p_energy