fix formatting issues
This commit is contained in:
parent
8e1a62651d
commit
5867b339f4
|
@ -195,7 +195,7 @@ void SORT::update(TargetsInFrame& tgts)
|
||||||
tracklet.age = 0;
|
tracklet.age = 0;
|
||||||
tracklet.hits = 1;
|
tracklet.hits = 1;
|
||||||
tracklet.misses = 0;
|
tracklet.misses = 0;
|
||||||
tracklet.frame_id=tgts.frame_id;
|
tracklet.frame_id = tgts.frame_id;
|
||||||
tracklet.tentative = true;
|
tracklet.tentative = true;
|
||||||
// initate the motion
|
// initate the motion
|
||||||
pair<Matrix<double, 8, 1>, Matrix<double, 8, 8> > motion = kf.initiate(tracklet.bbox);
|
pair<Matrix<double, 8, 1>, Matrix<double, 8, 8> > motion = kf.initiate(tracklet.bbox);
|
||||||
|
@ -245,13 +245,13 @@ void SORT::update(TargetsInFrame& tgts)
|
||||||
int detectionIndex = match.second;
|
int detectionIndex = match.second;
|
||||||
if (trackletIndex >= 0 && detectionIndex >= 0)
|
if (trackletIndex >= 0 && detectionIndex >= 0)
|
||||||
{
|
{
|
||||||
if (iouMatrix[match.first][match.second] >= _iou_threshold)//iou_thrshold
|
if (iouMatrix[match.first][match.second] >= _iou_threshold) // iou_thrshold
|
||||||
{
|
{
|
||||||
sv::Box box;
|
sv::Box box;
|
||||||
tgts.targets[detectionIndex].getBox(box);
|
tgts.targets[detectionIndex].getBox(box);
|
||||||
this->_tracklets[trackletIndex].age = 0;
|
this->_tracklets[trackletIndex].age = 0;
|
||||||
this->_tracklets[trackletIndex].hits++;
|
this->_tracklets[trackletIndex].hits++;
|
||||||
this->_tracklets[trackletIndex].frame_id=tgts.frame_id;
|
this->_tracklets[trackletIndex].frame_id = tgts.frame_id;
|
||||||
this->_tracklets[trackletIndex].bbox << box.x1, box.y1, box.x2-box.x1, box.y2-box.y1;
|
this->_tracklets[trackletIndex].bbox << box.x1, box.y1, box.x2-box.x1, box.y2-box.y1;
|
||||||
|
|
||||||
auto[mean, covariance] = kf.update(this->_tracklets[trackletIndex].mean, this->_tracklets[trackletIndex].covariance, box);
|
auto[mean, covariance] = kf.update(this->_tracklets[trackletIndex].mean, this->_tracklets[trackletIndex].covariance, box);
|
||||||
|
@ -264,7 +264,7 @@ void SORT::update(TargetsInFrame& tgts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create new tracklets for unmatched detections
|
// create new tracklets for unmatched detections
|
||||||
for (int i = 0; i < tgts.targets.size(); i++)
|
for (int i=0; i<tgts.targets.size(); i++)
|
||||||
{
|
{
|
||||||
if (match_det[i] == -1)
|
if (match_det[i] == -1)
|
||||||
{
|
{
|
||||||
|
@ -277,7 +277,7 @@ void SORT::update(TargetsInFrame& tgts)
|
||||||
tracklet.age = 0;
|
tracklet.age = 0;
|
||||||
tracklet.hits = 1;
|
tracklet.hits = 1;
|
||||||
tracklet.misses = 0;
|
tracklet.misses = 0;
|
||||||
tracklet.frame_id=tgts.frame_id;
|
tracklet.frame_id = tgts.frame_id;
|
||||||
tracklet.tentative = true;
|
tracklet.tentative = true;
|
||||||
|
|
||||||
auto[new_mean, new_covariance] = kf.initiate(tracklet.bbox);
|
auto[new_mean, new_covariance] = kf.initiate(tracklet.bbox);
|
||||||
|
@ -295,7 +295,7 @@ void SORT::update(TargetsInFrame& tgts)
|
||||||
{
|
{
|
||||||
tracklet.tentative = false;
|
tracklet.tentative = false;
|
||||||
}
|
}
|
||||||
if ((tgts.frame_id-tracklet.frame_id <= _max_age) || (!tracklet.tentative && tracklet.frame_id==tgts.frame_id))
|
if ((tgts.frame_id-tracklet.frame_id <= _max_age) || (!tracklet.tentative && tracklet.frame_id == tgts.frame_id))
|
||||||
{
|
{
|
||||||
_new_tracklets.push_back(tracklet);
|
_new_tracklets.push_back(tracklet);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,11 +51,11 @@ struct Tracklet
|
||||||
/* data */
|
/* data */
|
||||||
public:
|
public:
|
||||||
Eigen::Vector4d bbox; // double x, y, w, h;
|
Eigen::Vector4d bbox; // double x, y, w, h;
|
||||||
int id=0;
|
int id = 0;
|
||||||
int age;
|
int age;
|
||||||
int hits;
|
int hits;
|
||||||
int misses;
|
int misses;
|
||||||
int frame_id=0;
|
int frame_id = 0;
|
||||||
bool tentative;
|
bool tentative;
|
||||||
std::vector<double> features;
|
std::vector<double> features;
|
||||||
Eigen::Matrix<double, 8, 1> mean;
|
Eigen::Matrix<double, 8, 1> mean;
|
||||||
|
|
|
@ -11,19 +11,19 @@ if __name__ == '__main__':
|
||||||
# use COCO API to load forecast results and annotations
|
# use COCO API to load forecast results and annotations
|
||||||
cocoGt = COCO(anno_json)
|
cocoGt = COCO(anno_json)
|
||||||
with open(pred_json,'r') as file:
|
with open(pred_json,'r') as file:
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
|
|
||||||
# align anno_json with pred_json category_id
|
# align anno_json with pred_json category_id
|
||||||
gtCatDicts = {}
|
gtCatDicts = {}
|
||||||
for anns in range(len(cocoGt.getCatIds())):
|
for anns in range(len(cocoGt.getCatIds())):
|
||||||
gtCatDicts[anns] = cocoGt.getCatIds()[anns]
|
gtCatDicts[anns] = cocoGt.getCatIds()[anns]
|
||||||
|
|
||||||
pdCatIds=list(set([d['category_id'] for d in data]))
|
pdCatIds=list(set([d['category_id'] for d in data]))
|
||||||
|
|
||||||
if not set(pdCatIds).issubset(set(cocoGt.getCatIds())):
|
if not set(pdCatIds).issubset(set(cocoGt.getCatIds())):
|
||||||
for ins in data:
|
for ins in data:
|
||||||
temp = int(gtCatDicts[ins['category_id']])
|
temp = int(gtCatDicts[ins['category_id']])
|
||||||
ins['category_id'] = temp
|
ins['category_id'] = temp
|
||||||
|
|
||||||
# load prediction results
|
# load prediction results
|
||||||
cocoDt = cocoGt.loadRes(data)
|
cocoDt = cocoGt.loadRes(data)
|
||||||
|
|
|
@ -8,17 +8,21 @@ using namespace cv;
|
||||||
|
|
||||||
//extract name
|
//extract name
|
||||||
std::string GetImageFileName(const std::string& imagePath) {
|
std::string GetImageFileName(const std::string& imagePath) {
|
||||||
size_t lastSlash = imagePath.find_last_of("/\\");
|
size_t lastSlash = imagePath.find_last_of("/\\");
|
||||||
if (lastSlash == std::string::npos) {
|
if (lastSlash == std::string::npos)
|
||||||
return imagePath;
|
{
|
||||||
} else {
|
return imagePath;
|
||||||
std::string fileName = imagePath.substr(lastSlash + 1);
|
}
|
||||||
size_t lastDot = fileName.find_last_of(".");
|
else
|
||||||
if (lastDot != std::string::npos) {
|
{
|
||||||
return fileName.substr(0, lastDot);
|
std::string fileName = imagePath.substr(lastSlash + 1);
|
||||||
}
|
size_t lastDot = fileName.find_last_of(".");
|
||||||
return fileName;
|
if (lastDot != std::string::npos)
|
||||||
|
{
|
||||||
|
return fileName.substr(0, lastDot);
|
||||||
}
|
}
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,8 +64,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < val_image.size(); i++) {
|
for (int i = 0; i < val_image.size(); i++)
|
||||||
|
{
|
||||||
//create pred file
|
//create pred file
|
||||||
std::string val_image_name = GetImageFileName(val_image[i]);
|
std::string val_image_name = GetImageFileName(val_image[i]);
|
||||||
std::string filename = folder+"/"+ val_image_name + ".txt";
|
std::string filename = folder+"/"+ val_image_name + ".txt";
|
||||||
|
@ -84,11 +88,12 @@ int main(int argc, char *argv[])
|
||||||
// reslusts
|
// reslusts
|
||||||
for (int j = 0; j < tgts.targets.size(); j++)
|
for (int j = 0; j < tgts.targets.size(); j++)
|
||||||
{
|
{
|
||||||
sv::Box b;
|
sv::Box b;
|
||||||
tgts.targets[j].getBox(b);
|
tgts.targets[j].getBox(b);
|
||||||
file<<tgts.targets[j].category_id<<" "<<(float)(b.x1+b.x2)/(2*cols)<<" "<<(float)(b.y1+b.y2)/(2*rows)<<" "<<(float)(b.x2-b.x1)/cols<<" "<<(float)(b.y2-b.y1)/rows<<" "<<(float)tgts.targets[j].score<<"\n";
|
file << tgts.targets[j].category_id << " " << (float)(b.x1+b.x2) / (2*cols) << " " << (float)(b.y1+b.y2) / (2*rows) << \
|
||||||
}
|
" " << (float)(b.x2-b.x1) / cols << " " << (float)(b.y2-b.y1) / rows << " " << (float)tgts.targets[j].score << "\n";
|
||||||
file.close();
|
|
||||||
}
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ import os
|
||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
# revert prediction results to coco_json
|
# revert prediction results to coco_json
|
||||||
path = os.path.abspath(os.path.join(os.getcwd(),"../../.."))
|
path = os.path.abspath(os.path.join(os.getcwd(), "../../.."))
|
||||||
|
|
||||||
# all files dir
|
# all files dir
|
||||||
images_path = path+'/val2017/val2017'
|
images_path = path + '/val2017/val2017'
|
||||||
preds_path = path+'/val2017/preds'
|
preds_path = path + '/val2017/preds'
|
||||||
coco_json_save ='pd_coco.json'
|
coco_json_save ='pd_coco.json'
|
||||||
|
|
||||||
# config coco_json
|
# config coco_json
|
||||||
|
@ -27,25 +27,26 @@ for image in images:
|
||||||
# read pred's txt
|
# read pred's txt
|
||||||
pred_path = preds_path + '/' + image_name + '.txt'
|
pred_path = preds_path + '/' + image_name + '.txt'
|
||||||
if not os.path.exists(pred_path):
|
if not os.path.exists(pred_path):
|
||||||
continue
|
continue
|
||||||
with open(pred_path, 'r') as f:
|
with open(pred_path, 'r') as f:
|
||||||
preds = f.readlines()
|
preds = f.readlines()
|
||||||
preds = [l.strip() for l in preds]
|
preds = [l.strip() for l in preds]
|
||||||
for j,pred in enumerate(preds):
|
for j,pred in enumerate(preds):
|
||||||
pred = pred.split(' ')
|
pred = pred.split(' ')
|
||||||
category_id = int(pred[0])
|
category_id = int(pred[0])
|
||||||
x = float(pred[1]) * width
|
x = float(pred[1]) * width
|
||||||
y = float(pred[2]) * height
|
y = float(pred[2]) * height
|
||||||
w = float(pred[3]) * width
|
w = float(pred[3]) * width
|
||||||
h = float(pred[4]) * height
|
h = float(pred[4]) * height
|
||||||
xmin = x - w / 2
|
xmin = x - w / 2
|
||||||
ymin = y - h / 2
|
ymin = y - h / 2
|
||||||
|
|
||||||
coco_json.append({
|
coco_json.append({
|
||||||
'image_id': int(image_name),
|
'image_id': int(image_name),
|
||||||
'category_id': int(category_id),
|
'category_id': int(category_id),
|
||||||
'bbox': [xmin, ymin, w, h],
|
'bbox': [xmin, ymin, w, h],
|
||||||
'score': float(pred[5])})
|
'score': float(pred[5])
|
||||||
|
})
|
||||||
|
|
||||||
# save json
|
# save json
|
||||||
with open(os.path.join(coco_json_save), 'w') as f:
|
with open(os.path.join(coco_json_save), 'w') as f:
|
||||||
|
|
Loading…
Reference in New Issue