提交 223cdcd0 编写于 作者: V Vadim Pisarevsky

fixed compilation of some samples; fixed ANN_MLP::predict

上级 e368f17c
......@@ -262,9 +262,9 @@ public:
int cols = layer_sizes[j];
layer_out = Mat(dn, cols, CV_64F, data);
Mat w = weights[i].rowRange(0, layer_in.cols);
Mat w = weights[j].rowRange(0, layer_in.cols);
gemm(layer_in, w, 1, noArray(), 0, layer_out);
calc_activ_func( layer_out, weights[i] );
calc_activ_func( layer_out, weights[j] );
layer_in = layer_out;
}
......@@ -682,6 +682,8 @@ public:
train_backprop( inputs, outputs, sw, termcrit ) :
train_rprop( inputs, outputs, sw, termcrit );
trained = true;
return iter;
}
......
......@@ -23,6 +23,7 @@
#define DEBUG_DESC_PROGRESS
using namespace cv;
using namespace cv::ml;
using namespace std;
const string paramsFile = "params.xml";
......@@ -677,7 +678,7 @@ void VocData::writeClassifierResultsFile( const string& out_dir, const string& o
result_file.close();
} else {
string err_msg = "could not open classifier results file '" + output_file + "' for writing. Before running for the first time, a 'results' subdirectory should be created within the VOC dataset base directory. e.g. if the VOC data is stored in /VOC/VOC2010 then the path /VOC/results must be created.";
CV_Error(CV_StsError,err_msg.c_str());
CV_Error(Error::StsError,err_msg.c_str());
}
}
......@@ -701,9 +702,9 @@ void VocData::writeClassifierResultsFile( const string& out_dir, const string& o
string VocData::getResultsFilename(const string& obj_class, const VocTask task, const ObdDatasetType dataset, const int competition, const int number)
{
if ((competition < 1) && (competition != -1))
CV_Error(CV_StsBadArg,"competition argument should be a positive non-zero number or -1 to accept the default");
CV_Error(Error::StsBadArg,"competition argument should be a positive non-zero number or -1 to accept the default");
if ((number < 1) && (number != -1))
CV_Error(CV_StsBadArg,"number argument should be a positive non-zero number or -1 to accept the default");
CV_Error(Error::StsBadArg,"number argument should be a positive non-zero number or -1 to accept the default");
string dset, task_type;
......@@ -815,7 +816,7 @@ void VocData::calcClassifierPrecRecall(const string& input_file, vector<float>&
scoregt_file.close();
} else {
string err_msg = "could not open scoregt file '" + scoregt_file_str + "' for writing.";
CV_Error(CV_StsError,err_msg.c_str());
CV_Error(Error::StsError,err_msg.c_str());
}
}
......@@ -974,7 +975,7 @@ void VocData::calcClassifierConfMatRow(const string& obj_class, const vector<Obd
if (target_idx_it == output_headers.end())
{
string err_msg = "could not find the target object class '" + obj_class + "' in list of valid classes.";
CV_Error(CV_StsError,err_msg.c_str());
CV_Error(Error::StsError,err_msg.c_str());
}
/* convert iterator to index */
target_idx = (int)std::distance(output_headers.begin(),target_idx_it);
......@@ -1037,7 +1038,7 @@ void VocData::calcClassifierConfMatRow(const string& obj_class, const vector<Obd
if (class_idx_it == output_headers.end())
{
string err_msg = "could not find object class '" + img_objects[obj_idx].object_class + "' specified in the ground truth file of '" + images[ranking[image_idx]].id +"'in list of valid classes.";
CV_Error(CV_StsError,err_msg.c_str());
CV_Error(Error::StsError,err_msg.c_str());
}
/* convert iterator to index */
int class_idx = (int)std::distance(output_headers.begin(),class_idx_it);
......@@ -1189,7 +1190,7 @@ void VocData::calcDetectorConfMatRow(const string& obj_class, const ObdDatasetTy
if (class_idx_it == output_headers.end())
{
string err_msg = "could not find object class '" + img_objects[max_gt_obj_idx].object_class + "' specified in the ground truth file of '" + images[ranking[image_idx]].id +"'in list of valid classes.";
CV_Error(CV_StsError,err_msg.c_str());
CV_Error(Error::StsError,err_msg.c_str());
}
/* convert iterator to index */
int class_idx = (int)std::distance(output_headers.begin(),class_idx_it);
......@@ -1282,7 +1283,7 @@ void VocData::savePrecRecallToGnuplot(const string& output_file, const vector<fl
plot_file.close();
} else {
string err_msg = "could not open plot file '" + output_file_std + "' for writing.";
CV_Error(CV_StsError,err_msg.c_str());
CV_Error(Error::StsError,err_msg.c_str());
}
}
......@@ -1446,7 +1447,7 @@ void VocData::readClassifierGroundTruth(const string& filename, vector<string>&
if (!gtfile.is_open())
{
string err_msg = "could not open VOC ground truth textfile '" + filename + "'.";
CV_Error(CV_StsError,err_msg.c_str());
CV_Error(Error::StsError,err_msg.c_str());
}
string line;
......@@ -1462,7 +1463,7 @@ void VocData::readClassifierGroundTruth(const string& filename, vector<string>&
image_codes.push_back(image);
object_present.push_back(obj_present == 1);
} else {
if (!gtfile.eof()) CV_Error(CV_StsParseError,"error parsing VOC ground truth textfile.");
if (!gtfile.eof()) CV_Error(Error::StsParseError,"error parsing VOC ground truth textfile.");
}
}
gtfile.close();
......@@ -1488,13 +1489,13 @@ void VocData::readClassifierResultsFile(const string& input_file, vector<string>
image_codes.push_back(image);
scores.push_back(score);
} else {
if(!result_file.eof()) CV_Error(CV_StsParseError,"error parsing VOC classifier results file.");
if(!result_file.eof()) CV_Error(Error::StsParseError,"error parsing VOC classifier results file.");
}
}
result_file.close();
} else {
string err_msg = "could not open classifier results file '" + input_file + "' for reading.";
CV_Error(CV_StsError,err_msg.c_str());
CV_Error(Error::StsError,err_msg.c_str());
}
}
......@@ -1545,13 +1546,13 @@ void VocData::readDetectorResultsFile(const string& input_file, vector<string>&
bounding_boxes[image_idx].push_back(bounding_box);
}
} else {
if(!result_file.eof()) CV_Error(CV_StsParseError,"error parsing VOC detector results file.");
if(!result_file.eof()) CV_Error(Error::StsParseError,"error parsing VOC detector results file.");
}
}
result_file.close();
} else {
string err_msg = "could not open detector results file '" + input_file + "' for reading.";
CV_Error(CV_StsError,err_msg.c_str());
CV_Error(Error::StsError,err_msg.c_str());
}
}
......@@ -1595,23 +1596,23 @@ void VocData::extractVocObjects(const string filename, vector<ObdObject>& object
//object class -------------
if (extractXMLBlock(object_contents, "name", 0, tag_contents) == -1) CV_Error(CV_StsError,"missing <name> tag in object definition of '" + filename + "'");
if (extractXMLBlock(object_contents, "name", 0, tag_contents) == -1) CV_Error(Error::StsError,"missing <name> tag in object definition of '" + filename + "'");
object.object_class.swap(tag_contents);
//object bounding box -------------
int xmax, xmin, ymax, ymin;
if (extractXMLBlock(object_contents, "xmax", 0, tag_contents) == -1) CV_Error(CV_StsError,"missing <xmax> tag in object definition of '" + filename + "'");
if (extractXMLBlock(object_contents, "xmax", 0, tag_contents) == -1) CV_Error(Error::StsError,"missing <xmax> tag in object definition of '" + filename + "'");
xmax = stringToInteger(tag_contents);
if (extractXMLBlock(object_contents, "xmin", 0, tag_contents) == -1) CV_Error(CV_StsError,"missing <xmin> tag in object definition of '" + filename + "'");
if (extractXMLBlock(object_contents, "xmin", 0, tag_contents) == -1) CV_Error(Error::StsError,"missing <xmin> tag in object definition of '" + filename + "'");
xmin = stringToInteger(tag_contents);
if (extractXMLBlock(object_contents, "ymax", 0, tag_contents) == -1) CV_Error(CV_StsError,"missing <ymax> tag in object definition of '" + filename + "'");
if (extractXMLBlock(object_contents, "ymax", 0, tag_contents) == -1) CV_Error(Error::StsError,"missing <ymax> tag in object definition of '" + filename + "'");
ymax = stringToInteger(tag_contents);
if (extractXMLBlock(object_contents, "ymin", 0, tag_contents) == -1) CV_Error(CV_StsError,"missing <ymin> tag in object definition of '" + filename + "'");
if (extractXMLBlock(object_contents, "ymin", 0, tag_contents) == -1) CV_Error(Error::StsError,"missing <ymin> tag in object definition of '" + filename + "'");
ymin = stringToInteger(tag_contents);
object.boundingBox.x = xmin-1; //convert to 0-based indexing
......@@ -1714,11 +1715,11 @@ void VocData::extractDataFromResultsFilename(const string& input_file, string& c
size_t fnameend = input_file_std.rfind(".txt");
if ((fnamestart == input_file_std.npos) || (fnameend == input_file_std.npos))
CV_Error(CV_StsError,"Could not extract filename of results file.");
CV_Error(Error::StsError,"Could not extract filename of results file.");
++fnamestart;
if (fnamestart >= fnameend)
CV_Error(CV_StsError,"Could not extract filename of results file.");
CV_Error(Error::StsError,"Could not extract filename of results file.");
//extract dataset and class names, triggering exception if the filename format is not correct
string filename = input_file_std.substr(fnamestart, fnameend-fnamestart);
......@@ -1729,11 +1730,11 @@ void VocData::extractDataFromResultsFilename(const string& input_file, string& c
size_t classend = filename.find("_",classstart+1);
if (classend == filename.npos) classend = filename.size();
if ((datasetstart == filename.npos) || (classstart == filename.npos))
CV_Error(CV_StsError,"Error parsing results filename. Is it in standard format of 'comp<n>_{cls/det}_<dataset>_<objclass>.txt'?");
CV_Error(Error::StsError,"Error parsing results filename. Is it in standard format of 'comp<n>_{cls/det}_<dataset>_<objclass>.txt'?");
++datasetstart;
++classstart;
if (((datasetstart-classstart) < 1) || ((classend-datasetstart) < 1))
CV_Error(CV_StsError,"Error parsing results filename. Is it in standard format of 'comp<n>_{cls/det}_<dataset>_<objclass>.txt'?");
CV_Error(Error::StsError,"Error parsing results filename. Is it in standard format of 'comp<n>_{cls/det}_<dataset>_<objclass>.txt'?");
dataset_name = filename.substr(datasetstart,classstart-datasetstart-1);
class_name = filename.substr(classstart,classend-classstart);
......@@ -1781,7 +1782,7 @@ bool VocData::getClassifierGroundTruthImage(const string& obj_class, const strin
return m_classifier_gt_all_present[std::distance(m_classifier_gt_all_ids.begin(),it)] != 0;
} else {
string err_msg = "could not find classifier ground truth for image '" + id + "' and class '" + obj_class + "'";
CV_Error(CV_StsError,err_msg.c_str());
CV_Error(Error::StsError,err_msg.c_str());
}
return true;
......@@ -1814,7 +1815,7 @@ void VocData::getSortOrder(const vector<float>& values, vector<size_t>& order, b
void VocData::readFileToString(const string filename, string& file_contents)
{
std::ifstream ifs(filename.c_str());
if (!ifs.is_open()) CV_Error(CV_StsError,"could not open text file");
if (!ifs.is_open()) CV_Error(Error::StsError,"could not open text file");
stringstream oss;
oss << ifs.rdbuf();
......@@ -1829,7 +1830,7 @@ int VocData::stringToInteger(const string input_str)
stringstream ss(input_str);
if ((ss >> result).fail())
{
CV_Error(CV_StsBadArg,"could not perform string to integer conversion");
CV_Error(Error::StsBadArg,"could not perform string to integer conversion");
}
return result;
}
......@@ -1841,7 +1842,7 @@ string VocData::integerToString(const int input_int)
stringstream ss;
if ((ss << input_int).fail())
{
CV_Error(CV_StsBadArg,"could not perform integer to string conversion");
CV_Error(Error::StsBadArg,"could not perform integer to string conversion");
}
result = ss.str();
return result;
......@@ -2325,7 +2326,7 @@ static void removeBowImageDescriptorsByCount( vector<ObdImage>& images, vector<M
CV_Assert( bowImageDescriptors.size() == objectPresent.size() );
}
static void setSVMParams( CvSVMParams& svmParams, CvMat& class_wts_cv, const Mat& responses, bool balanceClasses )
static void setSVMParams( const SVM::Params& svmParams, Mat& class_wts_cv, const Mat& responses, bool balanceClasses )
{
int pos_ex = countNonZero(responses == 1);
int neg_ex = countNonZero(responses == -1);
......
......@@ -2,6 +2,7 @@
#include "opencv2/ml.hpp"
using namespace cv;
using namespace cv::ml;
int main( int /*argc*/, char** /*argv*/ )
{
......@@ -34,8 +35,9 @@ int main( int /*argc*/, char** /*argv*/ )
samples = samples.reshape(1, 0);
// cluster the data
EM em_model(N, EM::COV_MAT_SPHERICAL, TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 300, 0.1));
em_model.train( samples, noArray(), labels, noArray() );
Ptr<EM> em_model = EM::train( samples, noArray(), labels, noArray(),
EM::Params(N, EM::COV_MAT_SPHERICAL,
TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 300, 0.1)));
// classify every image pixel
for( i = 0; i < img.rows; i++ )
......@@ -44,7 +46,7 @@ int main( int /*argc*/, char** /*argv*/ )
{
sample.at<float>(0) = (float)j;
sample.at<float>(1) = (float)i;
int response = cvRound(em_model.predict( sample )[1]);
int response = cvRound(em_model->predict2( sample, noArray() )[1]);
Scalar c = colors[response];
circle( img, Point(j, i), 1, c*0.75, FILLED );
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册