English 中文(简体)
在开放式学校培训一个神经网络时退学
原标题:Error while training a neural network in opencv

I have been working on this for quite some time now but I am not able to figure out the problem here.I am working on Ubuntu in Opencv using eclipse. I am trying to train the neural network with some values.A few sample values are 62 63 45 0.175925925925926 0.285714285714286 0.247058823529412 1 49 51 37 0.190476190476190 0.274509803921569 0.200000000000000 1

Here is the entire loop of the neural network training. FILE* fid= fopen("treewall","r");

            while (fscanf(fid,"%f",&a)==1)
            {
                    printf("%f
",a);
                    trainsamplecount=trainsamplecount+1;
            }
            cout<<trainsamplecount<<endl;
            rewind(fid);
            float td[2000][7];
            int numoftestpoints;
            CvMat* traindata=cvCreateMat(trainsamplecount,6,CV_32FC1);
            CvMat* trainclasses=cvCreateMat(trainsamplecount,1,CV_32FC1);
            CvMat* samplewts=cvCreateMat(trainsamplecount,1,CV_32FC1);
            CvMat* neurallayers=cvCreateMat(4,1,CV_32SC1);
            CvMat traindata1,trainclasses1,neurallayers1,samplewts1;


            cvGetRows(neurallayers,&neurallayers1,0,4);

            cvSet1D(&neurallayers1, 0, cvScalar(6));
            cvSet1D(&neurallayers1,1,cvScalar(3));
            cvSet1D(&neurallayers1,2,cvScalar(3));
            cvSet1D(&neurallayers1, 3, cvScalar(1));

         // CvMat* outdata=Mat::ones(trainsamplecount/7,1,CV_8U);
         // CvMat* testdata(numoftestpoints,7,CV_32FC1);
            cout<<traindata->rows<<endl;
            cout<<traindata->cols<<endl;
            int i=0,j=0;

            if(fid)
            {
            for(int i=0;i<trainsamplecount;i++)
                fscanf(fid,"%f %f %f %f %f %f %f ",&td[i][0],&td[i][1],&td[i][2],&td[i][3],&td[i][4],&td[i][5],&td[i][6]);


            for (i=0;i<trainsamplecount;i++)
            {
                cout<<i<<endl;
                cvGetRow(traindata,&traindata1,i);
                cvSetReal2D(&traindata1,i,0,(float)td[i][0]);
                cvSetReal2D(&traindata1,i,1,(float)td[i][1]);
                cvSetReal2D(&traindata1,i,2,(float)td[i][2]);
                cvSetReal2D(&traindata1,i,3,(float)td[i][3]);
                cvSetReal2D(&traindata1,i,4,(float)td[i][4]);
                cvSetReal2D(&traindata1,i,5,(float)td[i][5]);
                cvGetRow(trainclasses,&trainclasses1,i);
                cvSet1D(&trainclasses1,i,cvRealScalar(1));
                cvGetRow(samplewts,&samplewts1,i);


                cvSet1D(samplewts,i,cvRealScalar(1));

            }
            }

But this loop terminates at the statement cvGetRow(trainclasses,&trainclasses1,i); Before it used to dispaly a bad argument error at the line cvSet1D(samplewts,i,cvRealScalar(1));

由于我无法考虑解决办法,请帮助我解决这一问题。

问题回答

我认为,这段话

cvSet1D(&trainclasses1,i,cvRealScalar(1));

应当

cvSet1D(&trainclasses1,0,cvRealScalar(1));

由于1号列车将拥有1行和1列。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签