Move extraction of name into function in utils
Signed-off-by: Micaela Verucchi <micaelaverucchi@gmail.com>
This commit is contained in:
+17
-45
@@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void convertFilename(std::string &filename,const std::string l_folder, const std::string i_folder, const std::string l_ext,const std::string i_ext)
|
void convertFilename(std::string &filename,const std::string l_folder, const std::string i_folder, const std::string l_ext,const std::string i_ext)
|
||||||
{
|
{
|
||||||
filename.replace(filename.find(l_folder),l_folder.length(),i_folder);
|
filename.replace(filename.find(l_folder),l_folder.length(),i_folder);
|
||||||
@@ -36,7 +34,7 @@ int main(int argc, char *argv[])
|
|||||||
bool show = false;
|
bool show = false;
|
||||||
bool write_dets = false;
|
bool write_dets = false;
|
||||||
bool write_res_on_file = true;
|
bool write_res_on_file = true;
|
||||||
int n_images = 5000;
|
int n_images = 50;
|
||||||
|
|
||||||
bool verbose;
|
bool verbose;
|
||||||
int classes, map_points, map_levels;
|
int classes, map_points, map_levels;
|
||||||
@@ -66,24 +64,12 @@ int main(int argc, char *argv[])
|
|||||||
IoU_thresh, conf_thresh, verbose);
|
IoU_thresh, conf_thresh, verbose);
|
||||||
|
|
||||||
std::ofstream times, memory;
|
std::ofstream times, memory;
|
||||||
std::string name;
|
std::string net_name;
|
||||||
if(write_res_on_file)
|
removePathAndExtension(net, net_name);
|
||||||
{
|
std::cout<<"Network: "<<net_name<<std::endl;
|
||||||
std::string str = net;
|
|
||||||
name = net;
|
if(write_res_on_file){
|
||||||
std::string delim = "/";
|
times.open("times_"+net_name+".csv");
|
||||||
std::size_t current, previous = 0;
|
|
||||||
current = str.find(delim);
|
|
||||||
if (current != std::string::npos) {
|
|
||||||
while (current != std::string::npos) {
|
|
||||||
name = str.substr(previous, current - previous);
|
|
||||||
previous = current + 1;
|
|
||||||
current = str.find(delim, previous);
|
|
||||||
}
|
|
||||||
name = str.substr(previous, current - previous);
|
|
||||||
}
|
|
||||||
std::cout<<"name: "<<name<<std::endl;
|
|
||||||
times.open("times"+name+".csv");
|
|
||||||
memory.open("memory.csv", std::ios_base::app);
|
memory.open("memory.csv", std::ios_base::app);
|
||||||
memory<<net<<";";
|
memory<<net<<";";
|
||||||
}
|
}
|
||||||
@@ -97,8 +83,7 @@ int main(int argc, char *argv[])
|
|||||||
int n_classes = classes;
|
int n_classes = classes;
|
||||||
|
|
||||||
|
|
||||||
switch(ntype)
|
switch(ntype){
|
||||||
{
|
|
||||||
case 'y':
|
case 'y':
|
||||||
detNN = &yolo;
|
detNN = &yolo;
|
||||||
break;
|
break;
|
||||||
@@ -110,13 +95,11 @@ int main(int argc, char *argv[])
|
|||||||
n_classes++;
|
n_classes++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FatalError("Network type not allowed (3rd parameter)\n");
|
FatalError("Network type not allowed (3rd parameter)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
detNN->init(net, n_classes);
|
detNN->init(net, n_classes);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::ifstream all_labels(labels_path);
|
std::ifstream all_labels(labels_path);
|
||||||
std::string l_filename;
|
std::string l_filename;
|
||||||
std::vector<tk::dnn::Frame> images;
|
std::vector<tk::dnn::Frame> images;
|
||||||
@@ -128,8 +111,7 @@ int main(int argc, char *argv[])
|
|||||||
cv::namedWindow("detection", cv::WINDOW_NORMAL);
|
cv::namedWindow("detection", cv::WINDOW_NORMAL);
|
||||||
|
|
||||||
int images_done;
|
int images_done;
|
||||||
for (images_done=0 ; std::getline(all_labels, l_filename) && images_done < n_images ; ++images_done)
|
for (images_done=0 ; std::getline(all_labels, l_filename) && images_done < n_images ; ++images_done) {
|
||||||
{
|
|
||||||
std::cout <<COL_ORANGEB<< "Images done:\t" << images_done<< "\n"<<COL_END;
|
std::cout <<COL_ORANGEB<< "Images done:\t" << images_done<< "\n"<<COL_END;
|
||||||
|
|
||||||
tk::dnn::Frame f;
|
tk::dnn::Frame f;
|
||||||
@@ -162,8 +144,7 @@ int main(int argc, char *argv[])
|
|||||||
myfile.open ("det/"+f.lFilename.substr(f.lFilename.find("000")));
|
myfile.open ("det/"+f.lFilename.substr(f.lFilename.find("000")));
|
||||||
|
|
||||||
// save detections labels
|
// save detections labels
|
||||||
for(auto d:detected_bbox)
|
for(auto d:detected_bbox){
|
||||||
{
|
|
||||||
//convert detected bb in the same format as label
|
//convert detected bb in the same format as label
|
||||||
//<x_center>/<image_width> <y_center>/<image_width> <width>/<image_width> <height>/<image_width>
|
//<x_center>/<image_width> <y_center>/<image_width> <width>/<image_width> <height>/<image_width>
|
||||||
tk::dnn::BoundingBox b;
|
tk::dnn::BoundingBox b;
|
||||||
@@ -187,8 +168,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// read and save groundtruth labels
|
// read and save groundtruth labels
|
||||||
std::ifstream labels(l_filename);
|
std::ifstream labels(l_filename);
|
||||||
for(std::string line; std::getline(labels, line); )
|
for(std::string line; std::getline(labels, line); ){
|
||||||
{
|
|
||||||
std::istringstream in(line);
|
std::istringstream in(line);
|
||||||
tk::dnn::BoundingBox b;
|
tk::dnn::BoundingBox b;
|
||||||
in >> b.cl >> b.x >> b.y >> b.w >> b.h;
|
in >> b.cl >> b.x >> b.y >> b.w >> b.h;
|
||||||
@@ -202,40 +182,32 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
images.push_back(f);
|
images.push_back(f);
|
||||||
|
|
||||||
if(show)
|
if(show){
|
||||||
{
|
|
||||||
cv::imshow("detection", frame);
|
cv::imshow("detection", frame);
|
||||||
cv::waitKey(0);
|
cv::waitKey(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
getMemUsage(vm, rss);
|
getMemUsage(vm, rss);
|
||||||
vm_total += vm;
|
vm_total += vm;
|
||||||
rss_total += rss;
|
rss_total += rss;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
std::cout << "Avg VM[MB]: " << vm_total/images_done/1024.0 << ";Avg RSS[MB]: " << rss_total/images_done/1024.0 << std::endl;
|
||||||
std::cout<<"Done."<<std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//compute mAP
|
//compute mAP
|
||||||
double AP = tk::dnn::computeMapNIoULevels(images,classes,IoU_thresh,conf_thresh, map_points, map_step, map_levels, verbose, write_res_on_file, name);
|
double AP = tk::dnn::computeMapNIoULevels(images,classes,IoU_thresh,conf_thresh, map_points, map_step, map_levels, verbose, write_res_on_file, net_name);
|
||||||
std::cout<<"mAP "<<IoU_thresh<<":"<<IoU_thresh+map_step*(map_levels-1)<<" = "<<AP<<std::endl;
|
std::cout<<"mAP "<<IoU_thresh<<":"<<IoU_thresh+map_step*(map_levels-1)<<" = "<<AP<<std::endl;
|
||||||
|
|
||||||
//compute average precision, recall and f1score
|
//compute average precision, recall and f1score
|
||||||
tk::dnn::computeTPFPFN(images,classes,IoU_thresh,conf_thresh, verbose, write_res_on_file, name);
|
tk::dnn::computeTPFPFN(images,classes,IoU_thresh,conf_thresh, verbose, write_res_on_file, net_name);
|
||||||
std::cout << "Avg VM[MB]: " << vm_total/images_done/1024.0 << ";Avg RSS[MB]: " << rss_total/images_done/1024.0 << std::endl;
|
|
||||||
|
|
||||||
if(write_res_on_file)
|
if(write_res_on_file){
|
||||||
{
|
|
||||||
memory<<vm_total/images_done/1024.0<<";"<<rss_total/images_done/1024.0<<"\n";
|
memory<<vm_total/images_done/1024.0<<";"<<rss_total/images_done/1024.0<<"\n";
|
||||||
times.close();
|
times.close();
|
||||||
memory.close();
|
memory.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,4 +108,5 @@ void matrixMulAdd( cublasHandle_t handle, dnnType* srcData, dnnType* dstData,
|
|||||||
dnnType* add_vector, int dim, dnnType mul);
|
dnnType* add_vector, int dim, dnnType mul);
|
||||||
|
|
||||||
void getMemUsage(double& vm_usage_kb, double& resident_set_kb);
|
void getMemUsage(double& vm_usage_kb, double& resident_set_kb);
|
||||||
|
void removePathAndExtension(const std::string &full_string, std::string &name);
|
||||||
#endif //UTILS_H
|
#endif //UTILS_H
|
||||||
|
|||||||
@@ -201,3 +201,30 @@ void getMemUsage(double& vm_usage_kb, double& resident_set_kb)
|
|||||||
vm_usage_kb = vsize / 1024.0;
|
vm_usage_kb = vsize / 1024.0;
|
||||||
resident_set_kb = rss * page_size_kb;
|
resident_set_kb = rss * page_size_kb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void removePathAndExtension(const std::string &full_string, std::string &name)
|
||||||
|
{
|
||||||
|
name = full_string;
|
||||||
|
std::string tmp_str = full_string;
|
||||||
|
std::string slash = "/";
|
||||||
|
std::string dot = ".";
|
||||||
|
std::size_t current, previous = 0;
|
||||||
|
|
||||||
|
//remove path /path/to/
|
||||||
|
current = tmp_str.find(slash);
|
||||||
|
if (current != std::string::npos) {
|
||||||
|
while (current != std::string::npos) {
|
||||||
|
name = tmp_str.substr(previous, current - previous);
|
||||||
|
previous = current + 1;
|
||||||
|
current = tmp_str.find(slash, previous);
|
||||||
|
}
|
||||||
|
name = tmp_str.substr(previous, current - previous);
|
||||||
|
}
|
||||||
|
// remove extension
|
||||||
|
current = name.find(dot);
|
||||||
|
previous = 0;
|
||||||
|
if (current != std::string::npos)
|
||||||
|
name = name.substr(previous, current);
|
||||||
|
|
||||||
|
// std::cout<<"full string: "<<full_string<<" name: "<<name<<std::endl;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user