Exception during reading mnist from c++ code





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I got an exception in this function - I am trying to read mnist dataset from this function but I got an exception. I think the dataset file is not reading - During debug the values of reading is blank so its very clear it not reading, how to cope with this situation.



 int main(int argc, char** argv)
{
cout<<"Start of the main function";


long start, end;
start = clock();

vector<Mat> trainX;
vector<Mat> testX;
Mat trainY, testY;

readData(trainX, trainY, "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnisttrain-images-idx3-ubyte", "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnisttrain-labels-idx1-ubyte", 60000);
readData(testX, testY, "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnistt10k-images-idx3-ubyte", "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnistt10k-labels-idx1-ubyte", 10000);

cout<<"Read trainX successfully, including "<<trainX[0].cols * trainX[0].rows<<" features and "<<trainX.size()<<" samples."<<endl;
cout<<"Read trainY successfully, including "<<trainY.cols<<" samples"<<endl;
cout<<"Read testX successfully, including "<<testX[0].cols * testX[0].rows<<" features and "<<testX.size()<<" samples."<<endl;
cout<<"Read testY successfully, including "<<testY.cols<<" samples"<<endl;

int nfeatures = trainX[0].rows * trainX[0].cols;
int imgDim = trainX[0].rows;
int nsamples = trainX.size();
Cvl cvl;
vector<Ntw> HiddenLayers;
SMR smr;

ConvNetInitPrarms(cvl, HiddenLayers, smr, imgDim, nsamples);
// Train network using Back Propogation
batch = nsamples / 100;
Mat tpX = concatenateMat(trainX);
double lrate = getLearningRate(tpX);
cout<<"lrate = "<<lrate<<endl;
trainNetwork(trainX, trainY, cvl, HiddenLayers, smr, 3e-3, 200000, lrate);

if(! G_CHECKING){
// Save the trained kernels, you can load them into Matlab/GNU Octave to see what are they look like.
saveWeight(cvl.layer[0].W, "w0");
saveWeight(cvl.layer[1].W, "w1");
saveWeight(cvl.layer[2].W, "w2");
saveWeight(cvl.layer[3].W, "w3");
saveWeight(cvl.layer[4].W, "w4");
saveWeight(cvl.layer[5].W, "w5");
saveWeight(cvl.layer[6].W, "w6");
saveWeight(cvl.layer[7].W, "w7");

// Test use test set
Mat result = resultProdict(testX, cvl, HiddenLayers, smr, 3e-3);
Mat err(testY);
err -= result;
int correct = err.cols;
for(int i=0; i<err.cols; i++){
if(err.ATD(0, i) != 0) --correct;
}
cout<<"correct: "<<correct<<", total: "<<err.cols<<", accuracy: "<<double(correct) / (double)(err.cols)<<endl;
}
end = clock();
cout<<"Totally used time: "<<((double)(end - start)) / CLOCKS_PER_SEC<<" second"<<endl;
return 0;
}









share|improve this question























  • see or_mnist.cpp from opencv_contrib.

    – sturkmen
    Jan 10 at 17:46


















0















I got an exception in this function - I am trying to read mnist dataset from this function but I got an exception. I think the dataset file is not reading - During debug the values of reading is blank so its very clear it not reading, how to cope with this situation.



 int main(int argc, char** argv)
{
cout<<"Start of the main function";


long start, end;
start = clock();

vector<Mat> trainX;
vector<Mat> testX;
Mat trainY, testY;

readData(trainX, trainY, "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnisttrain-images-idx3-ubyte", "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnisttrain-labels-idx1-ubyte", 60000);
readData(testX, testY, "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnistt10k-images-idx3-ubyte", "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnistt10k-labels-idx1-ubyte", 10000);

cout<<"Read trainX successfully, including "<<trainX[0].cols * trainX[0].rows<<" features and "<<trainX.size()<<" samples."<<endl;
cout<<"Read trainY successfully, including "<<trainY.cols<<" samples"<<endl;
cout<<"Read testX successfully, including "<<testX[0].cols * testX[0].rows<<" features and "<<testX.size()<<" samples."<<endl;
cout<<"Read testY successfully, including "<<testY.cols<<" samples"<<endl;

int nfeatures = trainX[0].rows * trainX[0].cols;
int imgDim = trainX[0].rows;
int nsamples = trainX.size();
Cvl cvl;
vector<Ntw> HiddenLayers;
SMR smr;

ConvNetInitPrarms(cvl, HiddenLayers, smr, imgDim, nsamples);
// Train network using Back Propogation
batch = nsamples / 100;
Mat tpX = concatenateMat(trainX);
double lrate = getLearningRate(tpX);
cout<<"lrate = "<<lrate<<endl;
trainNetwork(trainX, trainY, cvl, HiddenLayers, smr, 3e-3, 200000, lrate);

if(! G_CHECKING){
// Save the trained kernels, you can load them into Matlab/GNU Octave to see what are they look like.
saveWeight(cvl.layer[0].W, "w0");
saveWeight(cvl.layer[1].W, "w1");
saveWeight(cvl.layer[2].W, "w2");
saveWeight(cvl.layer[3].W, "w3");
saveWeight(cvl.layer[4].W, "w4");
saveWeight(cvl.layer[5].W, "w5");
saveWeight(cvl.layer[6].W, "w6");
saveWeight(cvl.layer[7].W, "w7");

// Test use test set
Mat result = resultProdict(testX, cvl, HiddenLayers, smr, 3e-3);
Mat err(testY);
err -= result;
int correct = err.cols;
for(int i=0; i<err.cols; i++){
if(err.ATD(0, i) != 0) --correct;
}
cout<<"correct: "<<correct<<", total: "<<err.cols<<", accuracy: "<<double(correct) / (double)(err.cols)<<endl;
}
end = clock();
cout<<"Totally used time: "<<((double)(end - start)) / CLOCKS_PER_SEC<<" second"<<endl;
return 0;
}









share|improve this question























  • see or_mnist.cpp from opencv_contrib.

    – sturkmen
    Jan 10 at 17:46














0












0








0








I got an exception in this function - I am trying to read mnist dataset from this function but I got an exception. I think the dataset file is not reading - During debug the values of reading is blank so its very clear it not reading, how to cope with this situation.



 int main(int argc, char** argv)
{
cout<<"Start of the main function";


long start, end;
start = clock();

vector<Mat> trainX;
vector<Mat> testX;
Mat trainY, testY;

readData(trainX, trainY, "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnisttrain-images-idx3-ubyte", "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnisttrain-labels-idx1-ubyte", 60000);
readData(testX, testY, "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnistt10k-images-idx3-ubyte", "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnistt10k-labels-idx1-ubyte", 10000);

cout<<"Read trainX successfully, including "<<trainX[0].cols * trainX[0].rows<<" features and "<<trainX.size()<<" samples."<<endl;
cout<<"Read trainY successfully, including "<<trainY.cols<<" samples"<<endl;
cout<<"Read testX successfully, including "<<testX[0].cols * testX[0].rows<<" features and "<<testX.size()<<" samples."<<endl;
cout<<"Read testY successfully, including "<<testY.cols<<" samples"<<endl;

int nfeatures = trainX[0].rows * trainX[0].cols;
int imgDim = trainX[0].rows;
int nsamples = trainX.size();
Cvl cvl;
vector<Ntw> HiddenLayers;
SMR smr;

ConvNetInitPrarms(cvl, HiddenLayers, smr, imgDim, nsamples);
// Train network using Back Propogation
batch = nsamples / 100;
Mat tpX = concatenateMat(trainX);
double lrate = getLearningRate(tpX);
cout<<"lrate = "<<lrate<<endl;
trainNetwork(trainX, trainY, cvl, HiddenLayers, smr, 3e-3, 200000, lrate);

if(! G_CHECKING){
// Save the trained kernels, you can load them into Matlab/GNU Octave to see what are they look like.
saveWeight(cvl.layer[0].W, "w0");
saveWeight(cvl.layer[1].W, "w1");
saveWeight(cvl.layer[2].W, "w2");
saveWeight(cvl.layer[3].W, "w3");
saveWeight(cvl.layer[4].W, "w4");
saveWeight(cvl.layer[5].W, "w5");
saveWeight(cvl.layer[6].W, "w6");
saveWeight(cvl.layer[7].W, "w7");

// Test use test set
Mat result = resultProdict(testX, cvl, HiddenLayers, smr, 3e-3);
Mat err(testY);
err -= result;
int correct = err.cols;
for(int i=0; i<err.cols; i++){
if(err.ATD(0, i) != 0) --correct;
}
cout<<"correct: "<<correct<<", total: "<<err.cols<<", accuracy: "<<double(correct) / (double)(err.cols)<<endl;
}
end = clock();
cout<<"Totally used time: "<<((double)(end - start)) / CLOCKS_PER_SEC<<" second"<<endl;
return 0;
}









share|improve this question














I got an exception in this function - I am trying to read mnist dataset from this function but I got an exception. I think the dataset file is not reading - During debug the values of reading is blank so its very clear it not reading, how to cope with this situation.



 int main(int argc, char** argv)
{
cout<<"Start of the main function";


long start, end;
start = clock();

vector<Mat> trainX;
vector<Mat> testX;
Mat trainY, testY;

readData(trainX, trainY, "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnisttrain-images-idx3-ubyte", "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnisttrain-labels-idx1-ubyte", 60000);
readData(testX, testY, "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnistt10k-images-idx3-ubyte", "C:\UserssadiqDocumentsVisual Studio 2010ProjectscnnmyNewOpenCVmyNewOpenCVmnistt10k-labels-idx1-ubyte", 10000);

cout<<"Read trainX successfully, including "<<trainX[0].cols * trainX[0].rows<<" features and "<<trainX.size()<<" samples."<<endl;
cout<<"Read trainY successfully, including "<<trainY.cols<<" samples"<<endl;
cout<<"Read testX successfully, including "<<testX[0].cols * testX[0].rows<<" features and "<<testX.size()<<" samples."<<endl;
cout<<"Read testY successfully, including "<<testY.cols<<" samples"<<endl;

int nfeatures = trainX[0].rows * trainX[0].cols;
int imgDim = trainX[0].rows;
int nsamples = trainX.size();
Cvl cvl;
vector<Ntw> HiddenLayers;
SMR smr;

ConvNetInitPrarms(cvl, HiddenLayers, smr, imgDim, nsamples);
// Train network using Back Propogation
batch = nsamples / 100;
Mat tpX = concatenateMat(trainX);
double lrate = getLearningRate(tpX);
cout<<"lrate = "<<lrate<<endl;
trainNetwork(trainX, trainY, cvl, HiddenLayers, smr, 3e-3, 200000, lrate);

if(! G_CHECKING){
// Save the trained kernels, you can load them into Matlab/GNU Octave to see what are they look like.
saveWeight(cvl.layer[0].W, "w0");
saveWeight(cvl.layer[1].W, "w1");
saveWeight(cvl.layer[2].W, "w2");
saveWeight(cvl.layer[3].W, "w3");
saveWeight(cvl.layer[4].W, "w4");
saveWeight(cvl.layer[5].W, "w5");
saveWeight(cvl.layer[6].W, "w6");
saveWeight(cvl.layer[7].W, "w7");

// Test use test set
Mat result = resultProdict(testX, cvl, HiddenLayers, smr, 3e-3);
Mat err(testY);
err -= result;
int correct = err.cols;
for(int i=0; i<err.cols; i++){
if(err.ATD(0, i) != 0) --correct;
}
cout<<"correct: "<<correct<<", total: "<<err.cols<<", accuracy: "<<double(correct) / (double)(err.cols)<<endl;
}
end = clock();
cout<<"Totally used time: "<<((double)(end - start)) / CLOCKS_PER_SEC<<" second"<<endl;
return 0;
}






opencv visual-studio-2010 mnist






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 4 at 6:27









SadiqSadiq

165




165













  • see or_mnist.cpp from opencv_contrib.

    – sturkmen
    Jan 10 at 17:46



















  • see or_mnist.cpp from opencv_contrib.

    – sturkmen
    Jan 10 at 17:46

















see or_mnist.cpp from opencv_contrib.

– sturkmen
Jan 10 at 17:46





see or_mnist.cpp from opencv_contrib.

– sturkmen
Jan 10 at 17:46












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54034009%2fexception-during-reading-mnist-from-c-code%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54034009%2fexception-during-reading-mnist-from-c-code%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas