Skip to content

Commit

Permalink
accelerate lane evaluation by openmp with 20x
Browse files Browse the repository at this point in the history
  • Loading branch information
atranitell committed Sep 26, 2019
1 parent 2b81eaa commit 4791fa0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ERFNet-CULane-PyTorch/tools/lane_evaluation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BUILD_DIR := build
CXX ?= g++
BUILD_DIR ?= ./build

LIBRARIES += opencv_core opencv_highgui opencv_imgproc
LIBRARIES += opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs

CXXFLAGS += $(COMMON_FLAGS) $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
LDFLAGS += $(COMMON_FLAGS) $(foreach includedir,$(LIBRARY_DIRS),-L$(includedir)) $(foreach library,$(LIBRARIES),-l$(library))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "hungarianGraph.hpp"
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <opencv2/core/core.hpp>

Expand All @@ -26,9 +27,12 @@ class Counter
long getTP(void);
long getFP(void);
long getFN(void);
void setTP(long);
void setFP(long);
void setFN(long);
// direct add tp, fp, tn and fn
// first match with hungarian
vector<int> count_im_pair(const vector<vector<Point2f> > &anno_lanes, const vector<vector<Point2f> > &detect_lanes);
tuple<vector<int>, long, long, long, long> count_im_pair(const vector<vector<Point2f> > &anno_lanes, const vector<vector<Point2f> > &detect_lanes);
void makeMatch(const vector<vector<double> > &similarity, vector<int> &match1, vector<int> &match2);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc.hpp>

using namespace std;
using namespace cv;
Expand Down
28 changes: 19 additions & 9 deletions ERFNet-CULane-PyTorch/tools/lane_evaluation/src/counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,33 @@ long Counter::getFN(void)
return fn;
}

vector<int> Counter::count_im_pair(const vector<vector<Point2f> > &anno_lanes, const vector<vector<Point2f> > &detect_lanes)
void Counter::setTP(long value)
{
tp = value;
}

void Counter::setFP(long value)
{
fp = value;
}

void Counter::setFN(long value)
{
fn = value;
}

tuple<vector<int>, long, long, long, long> Counter::count_im_pair(const vector<vector<Point2f> > &anno_lanes, const vector<vector<Point2f> > &detect_lanes)
{
vector<int> anno_match(anno_lanes.size(), -1);
vector<int> detect_match;
if(anno_lanes.empty())
{
fp += detect_lanes.size();
return anno_match;
return make_tuple(anno_match, 0, detect_lanes.size(), 0, 0);
}

if(detect_lanes.empty())
{
fn += anno_lanes.size();
return anno_match;
return make_tuple(anno_match, 0, 0, 0, anno_lanes.size());
}
// hungarian match first

Expand Down Expand Up @@ -92,10 +105,7 @@ vector<int> Counter::count_im_pair(const vector<vector<Point2f> > &anno_lanes, c
}
int curr_fn = anno_lanes.size() - curr_tp;
int curr_fp = detect_lanes.size() - curr_tp;
tp += curr_tp;
fn += curr_fn;
fp += curr_fp;
return anno_match;
return make_tuple(anno_match, curr_tp, curr_fp, 0, curr_fn);
}


Expand Down
33 changes: 26 additions & 7 deletions ERFNet-CULane-PyTorch/tools/lane_evaluation/src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,20 @@ int main(int argc, char **argv)

vector<int> anno_match;
string sub_im_name;
int count = 0;
while(getline(ifs_im_list, sub_im_name))
// pre-load filelist
vector<string> filelists;
while (getline(ifs_im_list, sub_im_name)) {
filelists.push_back(sub_im_name);
}
ifs_im_list.close();

vector<tuple<vector<int>, long, long, long, long>> tuple_lists;
tuple_lists.resize(filelists.size());

#pragma omp parallel for
for (size_t i = 0; i < filelists.size(); i++)
{
count++;
if (count < frame)
continue;
auto sub_im_name = filelists[i];
string full_im_name = im_dir + sub_im_name;
string sub_txt_name = sub_im_name.substr(0, sub_im_name.find_last_of(".")) + ".lines.txt";
string anno_file_name = anno_dir + sub_txt_name;
Expand All @@ -145,14 +153,25 @@ int main(int argc, char **argv)
read_lane_file(anno_file_name, anno_lanes);
read_lane_file(detect_file_name, detect_lanes);
//cerr<<count<<": "<<full_im_name<<endl;
anno_match = counter.count_im_pair(anno_lanes, detect_lanes);
tuple_lists[i] = counter.count_im_pair(anno_lanes, detect_lanes);
if (show)
{
auto anno_match = get<0>(tuple_lists[i]);
visualize(full_im_name, anno_lanes, detect_lanes, anno_match, width_lane);
waitKey(0);
}
}
ifs_im_list.close();

long tp = 0, fp = 0, tn = 0, fn = 0;
for (auto result: tuple_lists) {
tp += get<1>(result);
fp += get<2>(result);
// tn = get<3>(result);
fn += get<4>(result);
}
counter.setTP(tp);
counter.setFP(fp);
counter.setFN(fn);

double precision = counter.get_precision();
double recall = counter.get_recall();
Expand Down

0 comments on commit 4791fa0

Please sign in to comment.