// Copyright (c) Facebook, Inc. and its affiliates.
#include "cocoeval.h"
#include <time.h>
#include <algorithm>
#include <cstdint>
#include <numeric>
using namespace pybind11::literals;
namespace detectron2 {
namespace COCOeval {
// Sort detections from highest score to lowest, such that
// detection_instances[detection_sorted_indices[t]] >=
// detection_instances[detection_sorted_indices[t+1]]. Use stable_sort to match
// original COCO API
void SortInstancesByDetectionScore(
const std::vector<InstanceAnnotation>& detection_instances,
std::vector<uint64_t>* detection_sorted_indices) {
detection_sorted_indices->resize(detection_instances.size());
std::iota(
detection_sorted_indices->begin(), detection_sorted_indices->end(), 0);
std::stable_sort(
detection_sorted_indices->begin(),
detection_sorted_indices->end(),
[&detection_instances](size_t j1, size_t j2) {
return detection_instances[j1].score > detection_instances[j2].score;
});
}
// Partition the ground truth objects based on whether or not to ignore them
// based on area
void SortInstancesByIgnore(
const std::array<double, 2>& area_range,
const std::vector<InstanceAnnotation>& ground_truth_instances,
std::vector<uint64_t>* ground_truth_sorted_indices,
std::vector<bool>* ignores) {
ignores->clear();
ignores->reserve(ground_truth_instances.size());
for (auto o : ground_truth_instances) {
ignores->push_back(
o.ignore || o.area < area_range[0] || o.area > area_range[1]);
}
ground_truth_sorted_indices->resize(ground_truth_instances.size());
std::iota(
ground_truth_sorted_indices->begin(),
ground_truth_sorted_indices->end(),
0);
std::stable_sort(
ground_truth_sorted_indices->begin(),
ground_truth_sorted_indices->end(),
[&ignores](size_t j1, size_t j2) {
return (int)(*ignores)[j1] < (int)(*ignores)[j2];
});
}
// For each IOU threshold, greedily match each detected instance to a ground
// truth instance (if possible) and store the results
void MatchDetectionsToGroundTruth(
const std::vector<InstanceAnnotation>& detection_instances,
const std::vector<uint64_t>& detection_sorted_indices,
const std::vector<InstanceAnnotation>& ground_truth_instances,
const std::vector<uint64_t>& ground_truth_sorted_indices,
const std::vector<bool>& ignores,
const std::vector<std::vector<double>>& ious,
const std::vector<double>& iou_thresholds,
const std::array<double, 2>& area_range,
ImageEvaluation* results) {
// Initialize memory to store return data matches and ignore
const int num_iou_thresholds = iou_thresholds.size();
const int num_ground_truth = ground_truth_sorted_indices.size();
const int num_detections = detection_sorted_indices.size();
std::vector<uint64_t> ground_truth_matches(
num_iou_thresholds * num_ground_truth, 0);
std::vector<uint64_t>& detection_matches = results->detection_matches;
std::vector<bool>& detection_ignores = results->detection_ignores;
std::vector<bool>& ground_truth_ignores = results->ground_truth_ignores;
detection_matches.resize(num_iou_thresholds * num_detections, 0);
detection_ignores.resize(num_iou_thresholds * num_detections, false);
ground_truth_ignores.resize(num_ground_truth);
for (auto g = 0; g < num_ground_truth; ++g) {
ground_truth_ignores[g] = ignores[ground_truth_sorted_indices[g]];
}
for (auto t = 0; t < num_iou_thresholds; ++t) {
for (auto d = 0; d < num_detections; ++d) {
// information about best match so far (match=-1 -> unmatched)
double best_iou = std::min(iou_thresholds[t], 1 - 1e-10);
int match = -1;
for (auto g = 0; g < num_ground_truth; ++g) {
// if this ground truth instance is already matched and not a
// crowd, it cannot be matched to another detection
if (ground_truth_matches[t * num_ground_truth + g] > 0 &&
!ground_truth_instances[ground_truth_sorted_indices[g]].is_crowd) {
continue;
}
// if detected instance matched to a regular ground truth
// instance, we can break on the first ground truth instance
// tagged as ignore (because they are sorted by the ignore tag)
if (match >= 0 && !ground_truth_ignores[match] &&
ground_truth_ignores[g]) {
break;
}
// if IOU overlap is the best so far, store the match appropriately
if (ious[d][ground_truth_sorted_indices[g]] >= best_iou) {
best_iou = ious[d][ground_truth_sorted_indices[g]];
match = g;
}
}
// if match was made, store id of match for both detection and
// ground truth
if (match >= 0) {
detection_ignores[t * num_detections + d] = ground_truth_ignores[match];
detection_matches[t * num_detections + d] =
ground_truth_instances[ground_truth_sorted_indices[match]].id;
ground_truth_matches[t * num_ground_truth + match] =
detection_instances[detection_sorted_indices[d]].id;
}
// set unmatched detections outside of area range to ignore
const InstanceAnnotation& detection =
detection_instances[detection_sorted_indices[d]];
detection_ignores[t * num_detections + d] =
detection_ignores[t * num_detections + d] ||
(detection_matches[t * num_detections + d] == 0 &&
(detection.area < area_range[0] || detection.area > area_range[1]));
}
}
// store detection score results
results->detection_scores.resize(detection_sorted_indices.size());
for (size_t d = 0; d < detection_sorted_indices.size(); ++d) {
results->detection_scores[d] =
detection_instances[detection_sorted_indices[d]].score;
}
}
std::vector<ImageEvaluation> EvaluateImages(
const std::vector<std::array<double, 2>>& area_ranges,
int max_detections,
const std::vector<double>& iou_thresholds,
const ImageCategoryInstances<std::vector<double>>& image_category_ious,
const ImageCategoryInstances<InstanceAnnotation>&
image_category_ground_truth_instances,
const ImageCategoryInstances<InstanceAnnotation>&
image_category_detection_instances) {
const int num_area_ranges = area_ranges.size();
const int num_images = image_category_ground_truth_instances.size();
const int num_categories =
image_category_ious.size() > 0 ? image_category_ious[0].size() : 0;
std::vector<uint64_t> detection_sorted_indices;
std::vector<uint64_t> ground_truth_sorted_indices;
std::vector<bool> ignores;
std::vector<ImageEvaluation> results_all(
num_images * num_area_ranges * num_categories);
// Store results for each image, category, and area range combination. Results
// for each IOU threshold are packed into the same ImageEvaluation object
for (auto i = 0; i < num_images; ++i) {
for (auto c = 0; c < num_categories; ++c) {
const std::vector<InstanceAnnotation>& ground_truth_instances =
image_category_ground_truth_instances[i][c];
const std::vector<InstanceAnnotation>& detection_instances =
image_category_detection_instances[i][c];
SortInstancesByDetectionScore(
detection_instances, &detection_sorted_indices);
if ((int)detection_sorted_indices.size() > max_detections) {
detection_sorted_indices.resize(max_detections);
}
for (size_t a = 0; a < area_ranges.size(); ++a) {
SortInstancesByIgnore(
area_ranges[a],
ground_truth_instances,
&ground_truth_sorted_indices,
&ignores);
MatchDetectionsToGroundTruth(
detection_instances,
detection_sorted_indices,
ground_truth_instances,
ground_truth_sorted_indices,
ignores,
image_category_ious[i][c],
iou_thresholds,
area_ranges[a],
&results_all
[c * num_area_ranges *
没有合适的资源?快使用搜索试试~ 我知道了~
基于多模态的信息理解与抽取的方法(python)
共647个文件
py:441个
pyc:141个
cu:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 75 浏览量
2024-03-29
09:27:05
上传
评论
收藏 2.99MB ZIP 举报
温馨提示
一、运行环境 (1)CUDA 10.1 + python3.7 (2)pip install -r requirements.txt 二、数据处理 1.运行Step1_box_order.py 解释说明:将官方给的oce_labels文件件,按照坐标进行排序整理,并处理points字段成模型需要的box格式,得到ocr_labels_order。 2.运行Step2_funsd_transfrom.py 解释说明:根据官方给的ie_labels文件夹将对第一步获取的ocr_labels_order进行标注,标注成funsd格式,得到funsd_V1。 3.运行Step3_funsd_data_deal.py 解释说明:对第二步的funsd_V1进行清洗,将funsd_V1误标的总价改成other,得到funsd_V2。 4.运行Step4_check_json.py 解释说明:对第三步的funsd_V2进行检查,查看标签是否出错,坐标是否越界。如有问题,根据提示进行人工纠正。 5.运行Step5_propossed_funsd_2_xfun.py
资源推荐
资源详情
资源评论
收起资源包目录
基于多模态的信息理解与抽取的方法(python) (647个子文件)
setup.cfg 477B
cocoeval.cpp 20KB
cocoeval.cpp 20KB
ROIAlignRotated_cpu.cpp 16KB
ROIAlignRotated_cpu.cpp 16KB
vision.cpp 3KB
vision.cpp 3KB
nms_rotated_cpu.cpp 2KB
nms_rotated_cpu.cpp 2KB
box_iou_rotated_cpu.cpp 1KB
box_iou_rotated_cpu.cpp 1KB
deform_conv_cuda_kernel.cu 43KB
deform_conv_cuda_kernel.cu 43KB
deform_conv_cuda.cu 31KB
deform_conv_cuda.cu 31KB
ROIAlignRotated_cuda.cu 14KB
ROIAlignRotated_cuda.cu 14KB
nms_rotated_cuda.cu 5KB
nms_rotated_cuda.cu 5KB
box_iou_rotated_cuda.cu 4KB
box_iou_rotated_cuda.cu 4KB
cuda_version.cu 622B
cuda_version.cu 622B
.gitignore 47B
box_iou_rotated_utils.h 11KB
box_iou_rotated_utils.h 11KB
deform_conv.h 8KB
deform_conv.h 8KB
cocoeval.h 3KB
cocoeval.h 3KB
ROIAlignRotated.h 3KB
ROIAlignRotated.h 3KB
nms_rotated.h 1KB
nms_rotated.h 1KB
box_iou_rotated.h 988B
box_iou_rotated.h 988B
code.iml 443B
config.json 3KB
README.md 3KB
README.md 772B
README.md 513B
README.md 513B
README.md 347B
README.md 347B
README.md 175B
README.md 175B
README.md 122B
README.md 122B
README.md 110B
README.md 110B
PKG-INFO 259B
cv小组.ppt 770KB
model.pth 0B
lvis_v0_5_categories.py 219KB
lvis_v0_5_categories.py 219KB
lvis_v1_categories.py 214KB
lvis_v1_categories.py 214KB
modeling_layoutlmv3.py 53KB
modeling_layoutlmv3-checkpoint.py 53KB
modeling_layoutlmv3.py 53KB
modeling_layoutlmv3.py 53KB
modeling_layoutlmv3-checkpoint.py 53KB
visualizer.py 50KB
visualizer.py 50KB
lvis_v1_category_image_count.py 38KB
lvis_v1_category_image_count.py 38KB
shared.py 37KB
shared.py 37KB
roi_heads.py 37KB
roi_heads.py 37KB
Step2_funsd_transform.py 35KB
mytrainer.py 30KB
beit.py 30KB
coco_evaluation.py 30KB
coco_evaluation.py 30KB
defaults.py 29KB
defaults.py 29KB
defaults.py 26KB
defaults.py 26KB
hooks.py 25KB
hooks.py 25KB
fast_rcnn.py 25KB
fast_rcnn.py 25KB
swin.py 25KB
swin.py 25KB
rpn.py 23KB
rpn.py 23KB
resnet.py 23KB
resnet.py 23KB
dealer3.py 23KB
coco.py 23KB
coco-checkpoint.py 23KB
coco.py 23KB
coco-checkpoint.py 23KB
dealer3_new.py 23KB
augmentation_impl.py 23KB
augmentation_impl.py 23KB
detection_utils.py 22KB
detection_utils-checkpoint.py 22KB
detection_utils.py 22KB
共 647 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
十小大
- 粉丝: 1w+
- 资源: 2556
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功