1 #include "caffe2/operators/rmac_regions_op.h" 8 bool RMACRegionsOp<CPUContext>::RunOnDevice() {
9 const auto& X = Input(0);
11 auto* output = Output(
20 int batch_size = X.dim32(0);
23 int minW = std::min(H, W);
30 float cur_min = FLT_MAX;
31 for (
int idx = min_step; idx <= max_step; ++idx) {
32 float b = (std::max(H, W) - minW) / (1.0 * idx);
33 float val = std::abs((minW * minW - minW * b) / (minW * minW) - overlap_);
42 int Wd = (W > H) ? step : 0;
43 int Hd = (H > W) ? step : 0;
46 for (
int l = 1; l <= scales_; ++l) {
47 int region_size = 2 * minW / (l + 1);
48 if (region_size == 0) {
56 (l + Wd - 1 > 0) ? ((W - region_size) / (1.0 * (l + Wd - 1))) : 0;
58 (l + Hd - 1 > 0) ? ((H - region_size) / (1.0 * (l + Hd - 1))) : 0;
60 int cur_rows = output->dim32(0);
61 output->Extend((l + Wd) * (l + Hd), 50);
62 auto* outputData = output->template mutable_data<float>() + cur_rows * 5;
64 for (
int i = 0; i < l + Wd; ++i) {
65 for (
int j = 0; j < l + Hd; ++j) {
69 if (x1 + region_size > W) {
70 x1 -= (x1 + region_size - W);
72 if (y1 + region_size > H) {
73 y1 -= (y1 + region_size - H);
75 int x2 = x1 + region_size - 1;
76 int y2 = y1 + region_size - 1;
89 int num_rois = output->dim32(0);
90 output->Extend((batch_size - 1) * num_rois, 50);
91 auto* outputData = output->template mutable_data<float>();
92 for (
int b = 1; b < batch_size; ++b) {
94 std::copy_n(outputData, num_rois * 5, outputData + b * num_rois * 5);
96 for (
int r = 0; r < num_rois; ++r) {
97 outputData[(b * num_rois + r) * 5] = b;
104 REGISTER_CPU_OPERATOR(RMACRegions, RMACRegionsOp<CPUContext>);
106 OPERATOR_SCHEMA(RMACRegions)
110 Computes a fixed-grid of RMAC region coordinates at various levels 111 as described in https://arxiv.org/abs/1511.05879. 113 .Arg("scales",
"Number of scales to sample regions at.")
114 .Arg(
"overlap",
"Overlap between consecutive regions.")
115 .Input(0,
"X",
"The input 4D tensor of shape NCHW.")
119 "The output RMAC regions for all items in the batch. Tensor of shape " 120 "(N x 5) following the ROIPoolOp format - each row is of the format " 121 "(batch_index x1 y1 x2 y2) where x1, y1, x2, y2 are the region " 122 "co-ordinates. Each region is repeated N times corresponding to each " 123 "item in the batch.");
125 SHOULD_NOT_DO_GRADIENT(RMACRegions);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...