xuduo35 / STAPLE

C++ implementation of staple algorithm for object tracking.
MIT License
121 stars 48 forks source link

malloc.c:2368: sysmalloc: Assertion failed #2

Closed Oliverwang closed 6 years ago

Oliverwang commented 6 years ago

bg_area.width 96 bg_area.height 95 fg_area.width 40 fg_area.height 39 area_resize_factor 1.5707 norm_bg_area.width 151 norm_bg_area.height 149 norm_target_sz.width 76 norm_target_sz.height 74 norm_pwp_search_area.width 150 norm_pwp_search_area.height 148 track: malloc.c:2368: sysmalloc: Assertion `(old_top == (((mbinptr) (((char ) &((av)->bins[((1) - 1) 2])) - builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 (sizeof(size_t))) - 1)) & ~((2 (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long) old_end & pagemask) == 0)' failed. Aborted

I use SSE2NEON.h replaced sse function and run on my phone, The above error occurred

Oliverwang commented 6 years ago

test this sample is ok
SSE2NEON.h from https://github.com/jratcliff63367/sse2neon/blob/master/SSE2NEON.h Any suggestion for the error? Thanks

xuduo35 commented 6 years ago

Memory is corrupted. Please refer to this issue https://github.com/xuduo35/STAPLE/issues/1. You can try disable compiler optimize option, compile and run it again. Or you have to track how the content of those address mentioned in the assertion is changed, add some variables to memorize their values and compare them with current values at some checkpoints.

Oliverwang commented 6 years ago

I used a memery error check tool, error report ==18014== Memcheck, a memory error detector ==18014== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==18014== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info ==18014== Command: build/stapleCC ==18014== bg_area.width 96 bg_area.height 95 fg_area.width 40 fg_area.height 39 area_resize_factor 1.5707 norm_bg_area.width 151 norm_bg_area.height 149 norm_target_sz.width 76 norm_target_sz.height 74 norm_pwp_search_area.width 150 norm_pwp_search_area.height 148 wxhxc = 151 x 149 x 3 ==18014== Invalid read of size 16 ==18014== at 0x40993C: gradHist(float, float, float, int, int, int, int, int, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40A5D4: fhog(float, float, float, int, int, int, int, int, float) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40A95A: fhog(float, float, int, int, int, int, int, int, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40B558: fhog28(cv::Mat&, cv::Mat const&, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40F3F1: STAPLE_TRACKER::getFeatureMap(cv::Mat&, char const, cv::Mat&) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x419895: STAPLE_TRACKER::tracker_staple_train(cv::Mat const&, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40588E: main (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== Address 0x1dc6f99c is 98,556 bytes inside a block of size 98,568 alloc'd ==18014== at 0x4C2E858: calloc (vg_replace_malloc.c:711) ==18014== by 0x40A59D: fhog(float, float, float, int, int, int, int, int, float) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40A95A: fhog(float, float, int, int, int, int, int, int, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40B558: fhog28(cv::Mat&, cv::Mat const&, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40F3F1: STAPLE_TRACKER::getFeatureMap(cv::Mat&, char const, cv::Mat&) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x419895: STAPLE_TRACKER::tracker_staple_train(cv::Mat const&, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40588E: main (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== ==18014== Invalid write of size 8 ==18014== at 0x40994B: gradHist(float, float, float, int, int, int, int, int, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40A5D4: fhog(float, float, float, int, int, int, int, int, float) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40A95A: fhog(float, float, int, int, int, int, int, int, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40B558: fhog28(cv::Mat&, cv::Mat const&, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40F3F1: STAPLE_TRACKER::getFeatureMap(cv::Mat&, char const, cv::Mat&) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x419895: STAPLE_TRACKER::tracker_staple_train(cv::Mat const&, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40588E: main (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== Address 0x1dc6f9a4 is 98,564 bytes inside a block of size 98,568 alloc'd ==18014== at 0x4C2E858: calloc (vg_replace_malloc.c:711) ==18014== by 0x40A59D: fhog(float, float, float, int, int, int, int, int, float) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40A95A: fhog(float, float, int, int, int, int, int, int, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40B558: fhog28(cv::Mat&, cv::Mat const&, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40F3F1: STAPLE_TRACKER::getFeatureMap(cv::Mat&, char const, cv::Mat&) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x419895: STAPLE_TRACKER::tracker_staple_train(cv::Mat const&, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC) ==18014== by 0x40588E: main (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)

Oliverwang commented 6 years ago

I writed a sample with opencv, only read a image and resize to 1280*720 , call getSubwindow fhog28 fhog31, have the same error

int main(){ Mat image = imread("lena.jpg",IMREAD_COLOR);

for (int i = 0; i < 100; i++)
{
    //Mat fhog_feature = fhog(image);
    //vector<Mat> feats;
    //split(fhog_feature, feats);

    cv::Mat resized;
    //cv::resize(image, resized, cv::Size(960, 640), 0, 0, cv::INTER_AREA);
    cv::resize(image, resized, cv::Size(1280, 720), 0, 0, cv::INTER_AREA);
    //cv::resize(image, resized, cv::Size(151, 149), 0, 0, cv::INTER_AREA);

    cv::Point_<float> centerCoor = cv::Point_<float>(514.5, 439);
    //cv::Point_<float> centerCoor = cv::Point_<float>(510.5, 411);
    cv::Size norm_bg_area = cv::Size(151, 149);
    cv::Size bg_area = cv::Size(96, 95);
    cv::Mat im_patch_bg;
    getSubwindow(resized, centerCoor, norm_bg_area, bg_area, im_patch_bg);

    cv::MatND xt;
    fhog28(xt, im_patch_bg, 4, 9);
    std::cout<<"##############fhog28 = "<<i<<std::endl;

    cv::MatND temp;
    fhog31(temp, im_patch_bg, 4, 9);
    std::cout<<"##############fhog31 = "<<i<<std::endl;
}
#if 0
for (size_t i = 0; i < feats.size(); i++) {
    cout<<feats[i]<<endl;
    imshow("feat", feats[i]);
    waitKey();
}
#endif

return 0;

}

Oliverwang commented 6 years ago

test are all on ubuntu16.04 if resized image to cv::Size(151, 149) , then call fhog28 fhog32, No error occured

xuduo35 commented 6 years ago

So in your sample code, the error is caused by wrong image size. From Valgrind output, it points to function gradHist. You can figure out which line of code is the source of message "==18014== Invalid read of size 16". Please check aMalloc and aFree function, do some change to debug. If you are running tracking code in single thread, maybe you can change aMalloc/aFree function to use a global static array as memory buffer for test.

Oliverwang commented 6 years ago

https://github.com/pdollar/toolbox/issues/8 is this issue ?

xuduo35 commented 6 years ago

I read the post, but not very clear about the author's idea. It's better add some print around gradHist code lines to find the root cause.

Oliverwang commented 6 years ago

modify code below can run without err

           // main rows, has top and bottom bins, use SSE for minor speedup
    if( softBin<0 ) 
        for( ; ; y++ )
        {
            std::cout<<"###########x = "<< x << "y = "<< y <<std::endl;
            yb0 = (int) yb;
            if(yb0>=hb-1)
                break;
            GHinit; 
            //_m0=sse::SET(M0[y]);
            if(hasLf) 
            { 
                //_m=sse::SET(0,0,ms[1],ms[0]); 
                //GH(H0+O0[y],_m,_m0);
                H0[O0[y]] += M0[y]*ms[0];
                //H0[O0[y] + 3] += M0[y]*ms[1];
            }

            if(hasRt)
            { 
                //_m=sse::SET(0,0,ms[3],ms[2]); 
                //GH(H0+O0[y]+hb,_m,_m0);
                H0[O0[y]+hb] += M0[y]*ms[3];
                //H0[O0[y]+hb + 3] += M0[y]*ms[2];
            }
            std::cout<<"o0[y] = "<<O0[y]<<" O0[y]+hb = "<< O0[y]+hb<<std::endl;
        }
Oliverwang commented 6 years ago

test with sequence is ok

xuduo35 commented 6 years ago

Nice 👍

Oliverwang commented 6 years ago

But I don't know if this calculation of hog features is correct, it is not very clear that the hog principle

xuduo35 commented 6 years ago

You can compare the result with PC's program. But make sure opencv is the same version.