12 #include <Eigen/CXX11/Tensor> 28 single_pixel_patch = tensor.extract_image_patches(1, 1);
29 VERIFY_IS_EQUAL(single_pixel_patch.dimension(0), 2);
30 VERIFY_IS_EQUAL(single_pixel_patch.dimension(1), 1);
31 VERIFY_IS_EQUAL(single_pixel_patch.dimension(2), 1);
32 VERIFY_IS_EQUAL(single_pixel_patch.dimension(3), 3*5);
33 VERIFY_IS_EQUAL(single_pixel_patch.dimension(4), 7);
37 single_pixel_patch_row_major = tensor_row_major.extract_image_patches(1, 1);
38 VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(0), 7);
39 VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(1), 3*5);
40 VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(2), 1);
41 VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(3), 1);
42 VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(4), 2);
44 for (
int i = 0; i < tensor.
size(); ++i) {
46 if (tensor.
data()[i] != single_pixel_patch.data()[i]) {
47 std::cout <<
"Mismatch detected at index " << i <<
" : " 48 << tensor.
data()[i] <<
" vs " << single_pixel_patch.data()[i]
51 VERIFY_IS_EQUAL(single_pixel_patch.data()[i], tensor.
data()[i]);
53 if (tensor_row_major.
data()[i] != single_pixel_patch_row_major.data()[i]) {
54 std::cout <<
"Mismatch detected at index " << i <<
" : " 55 << tensor.
data()[i] <<
" vs " 56 << single_pixel_patch_row_major.data()[i] << std::endl;
58 VERIFY_IS_EQUAL(single_pixel_patch_row_major.data()[i],
59 tensor_row_major.
data()[i]);
60 VERIFY_IS_EQUAL(tensor.
data()[i], tensor_row_major.
data()[i]);
61 VERIFY_IS_EQUAL(single_pixel_patch.data()[i],
62 single_pixel_patch_row_major.data()[i]);
67 entire_image_patch = tensor.extract_image_patches(3, 5);
68 VERIFY_IS_EQUAL(entire_image_patch.dimension(0), 2);
69 VERIFY_IS_EQUAL(entire_image_patch.dimension(1), 3);
70 VERIFY_IS_EQUAL(entire_image_patch.dimension(2), 5);
71 VERIFY_IS_EQUAL(entire_image_patch.dimension(3), 3*5);
72 VERIFY_IS_EQUAL(entire_image_patch.dimension(4), 7);
76 entire_image_patch_row_major = tensor_row_major.extract_image_patches(3, 5);
77 VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(0), 7);
78 VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(1), 3*5);
79 VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(2), 5);
80 VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(3), 3);
81 VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(4), 2);
83 for (
int i = 0; i < 3; ++i) {
84 for (
int j = 0; j < 5; ++j) {
86 for (
int r = 0; r < 3; ++r) {
87 for (
int c = 0; c < 5; ++c) {
88 for (
int d = 0;
d < 2; ++
d) {
89 for (
int b = 0;
b < 7; ++
b) {
90 float expected = 0.0f;
91 float expected_row_major = 0.0f;
92 if (r-1+i >= 0 && c-2+j >= 0 && r-1+i < 3 && c-2+j < 5) {
93 expected = tensor(
d, r-1+i, c-2+j,
b);
94 expected_row_major = tensor_row_major(
b, c-2+j, r-1+i,
d);
97 if (entire_image_patch(
d, r, c, patchId,
b) != expected) {
98 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
100 VERIFY_IS_EQUAL(entire_image_patch(
d, r, c, patchId,
b), expected);
102 if (entire_image_patch_row_major(
b, patchId, c, r,
d) !=
103 expected_row_major) {
104 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j
105 <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b 108 VERIFY_IS_EQUAL(entire_image_patch_row_major(
b, patchId, c, r,
d),
111 VERIFY_IS_EQUAL(expected, expected_row_major);
121 twod_patch = tensor.extract_image_patches(2, 2);
122 VERIFY_IS_EQUAL(twod_patch.
dimension(0), 2);
123 VERIFY_IS_EQUAL(twod_patch.
dimension(1), 2);
124 VERIFY_IS_EQUAL(twod_patch.
dimension(2), 2);
125 VERIFY_IS_EQUAL(twod_patch.
dimension(3), 3*5);
126 VERIFY_IS_EQUAL(twod_patch.
dimension(4), 7);
130 twod_patch_row_major = tensor_row_major.extract_image_patches(2, 2);
131 VERIFY_IS_EQUAL(twod_patch_row_major.dimension(0), 7);
132 VERIFY_IS_EQUAL(twod_patch_row_major.dimension(1), 3*5);
133 VERIFY_IS_EQUAL(twod_patch_row_major.dimension(2), 2);
134 VERIFY_IS_EQUAL(twod_patch_row_major.dimension(3), 2);
135 VERIFY_IS_EQUAL(twod_patch_row_major.dimension(4), 2);
143 for (
int i = 0; i < 3; ++i) {
144 for (
int j = 0; j < 5; ++j) {
146 for (
int r = 0; r < 2; ++r) {
147 for (
int c = 0; c < 2; ++c) {
148 for (
int d = 0;
d < 2; ++
d) {
149 for (
int b = 0;
b < 7; ++
b) {
150 float expected = 0.0f;
151 float expected_row_major = 0.0f;
152 int row_offset = r*stride + i - row_padding;
153 int col_offset = c*stride + j - col_padding;
155 if (row_offset >= 0 && col_offset >= 0 && row_offset < tensor.
dimension(1) && col_offset < tensor.
dimension(2)) {
156 expected = tensor(
d, row_offset, col_offset,
b);
158 if (twod_patch(
d, r, c, patchId,
b) != expected) {
159 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
161 VERIFY_IS_EQUAL(twod_patch(
d, r, c, patchId,
b), expected);
164 if (row_offset >= 0 && col_offset >= 0 && row_offset < tensor_row_major.
dimension(2) && col_offset < tensor_row_major.
dimension(1)) {
165 expected_row_major = tensor_row_major(
b, col_offset, row_offset,
d);
168 if (twod_patch_row_major(
b, patchId, c, r,
d) != expected_row_major) {
169 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
171 VERIFY_IS_EQUAL(twod_patch_row_major(
b, patchId, c, r,
d), expected_row_major);
173 VERIFY_IS_EQUAL(expected, expected_row_major);
188 int input_batches = 1;
191 Tensor<float, 4> tensor(input_depth, input_rows, input_cols, input_batches);
193 for (
int i = 0; i < tensor.
size(); ++i) {
194 tensor.
data()[i] = i + 1;
199 VERIFY_IS_EQUAL(result.
dimension(0), input_depth);
200 VERIFY_IS_EQUAL(result.
dimension(1), ksize);
201 VERIFY_IS_EQUAL(result.
dimension(2), ksize);
203 VERIFY_IS_EQUAL(result.
dimension(4), input_batches);
207 VERIFY_IS_EQUAL(tensor.
dimension(0), tensor_row_major.dimension(3));
208 VERIFY_IS_EQUAL(tensor.
dimension(1), tensor_row_major.dimension(2));
209 VERIFY_IS_EQUAL(tensor.
dimension(2), tensor_row_major.dimension(1));
210 VERIFY_IS_EQUAL(tensor.
dimension(3), tensor_row_major.dimension(0));
213 VERIFY_IS_EQUAL(result.
dimension(0), result_row_major.dimension(4));
214 VERIFY_IS_EQUAL(result.
dimension(1), result_row_major.dimension(3));
215 VERIFY_IS_EQUAL(result.
dimension(2), result_row_major.dimension(2));
216 VERIFY_IS_EQUAL(result.
dimension(3), result_row_major.dimension(1));
217 VERIFY_IS_EQUAL(result.
dimension(4), result_row_major.dimension(0));
223 for (
int i = 0; (i+stride+ksize-1) < input_rows; i += stride) {
224 for (
int j = 0; (j+stride+ksize-1) < input_cols; j += stride) {
225 int patchId = i+input_rows*j;
226 for (
int r = 0; r < ksize; ++r) {
227 for (
int c = 0; c < ksize; ++c) {
228 for (
int d = 0;
d < input_depth; ++
d) {
229 for (
int b = 0;
b < input_batches; ++
b) {
230 float expected = 0.0f;
231 float expected_row_major = 0.0f;
232 int row_offset = r + i - row_padding;
233 int col_offset = c + j - col_padding;
234 if (row_offset >= 0 && col_offset >= 0 && row_offset < input_rows && col_offset < input_cols) {
235 expected = tensor(
d, row_offset, col_offset,
b);
236 expected_row_major = tensor_row_major(
b, col_offset, row_offset,
d);
239 if (result(
d, r, c, patchId,
b) != expected) {
240 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
242 VERIFY_IS_EQUAL(result(
d, r, c, patchId,
b), expected);
244 if (result_row_major(
b, patchId, c, r,
d) != expected_row_major) {
245 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
247 VERIFY_IS_EQUAL(result_row_major(
b, patchId, c, r,
d), expected_row_major);
249 VERIFY_IS_EQUAL(expected, expected_row_major);
264 int input_batches = 2;
268 Tensor<float, 4> tensor(input_depth, input_rows, input_cols, input_batches);
269 tensor = tensor.constant(11.0
f);
272 VERIFY_IS_EQUAL(result.
dimension(0), input_depth);
273 VERIFY_IS_EQUAL(result.
dimension(1), ksize);
274 VERIFY_IS_EQUAL(result.
dimension(2), ksize);
276 VERIFY_IS_EQUAL(result.
dimension(4), input_batches);
280 VERIFY_IS_EQUAL(tensor.
dimension(0), tensor_row_major.dimension(3));
281 VERIFY_IS_EQUAL(tensor.
dimension(1), tensor_row_major.dimension(2));
282 VERIFY_IS_EQUAL(tensor.
dimension(2), tensor_row_major.dimension(1));
283 VERIFY_IS_EQUAL(tensor.
dimension(3), tensor_row_major.dimension(0));
286 VERIFY_IS_EQUAL(result.
dimension(0), result_row_major.dimension(4));
287 VERIFY_IS_EQUAL(result.
dimension(1), result_row_major.dimension(3));
288 VERIFY_IS_EQUAL(result.
dimension(2), result_row_major.dimension(2));
289 VERIFY_IS_EQUAL(result.
dimension(3), result_row_major.dimension(1));
290 VERIFY_IS_EQUAL(result.
dimension(4), result_row_major.dimension(0));
296 for (
int i = 0; (i+stride+ksize-1) <= input_rows; i += stride) {
297 for (
int j = 0; (j+stride+ksize-1) <= input_cols; j += stride) {
298 int patchId = i+input_rows*j;
299 for (
int r = 0; r < ksize; ++r) {
300 for (
int c = 0; c < ksize; ++c) {
301 for (
int d = 0;
d < input_depth; ++
d) {
302 for (
int b = 0;
b < input_batches; ++
b) {
303 float expected = 0.0f;
304 float expected_row_major = 0.0f;
305 int row_offset = r + i - row_padding;
306 int col_offset = c + j - col_padding;
307 if (row_offset >= 0 && col_offset >= 0 && row_offset < input_rows && col_offset < input_cols) {
308 expected = tensor(
d, row_offset, col_offset,
b);
309 expected_row_major = tensor_row_major(
b, col_offset, row_offset,
d);
312 if (result(
d, r, c, patchId,
b) != expected) {
313 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
315 VERIFY_IS_EQUAL(result(
d, r, c, patchId,
b), expected);
317 if (result_row_major(
b, patchId, c, r,
d) != expected_row_major) {
318 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
320 VERIFY_IS_EQUAL(result_row_major(
b, patchId, c, r,
d), expected_row_major);
322 VERIFY_IS_EQUAL(expected, expected_row_major);
337 int input_batches = 1;
341 Tensor<float, 4> tensor(input_depth, input_rows, input_cols, input_batches);
343 for (
int i = 0; i < tensor.
size(); ++i) {
344 tensor.
data()[i] = i + 1;
348 VERIFY_IS_EQUAL(result.
dimension(0), input_depth);
349 VERIFY_IS_EQUAL(result.
dimension(1), ksize);
350 VERIFY_IS_EQUAL(result.
dimension(2), ksize);
352 VERIFY_IS_EQUAL(result.
dimension(4), input_batches);
356 VERIFY_IS_EQUAL(tensor.
dimension(0), tensor_row_major.dimension(3));
357 VERIFY_IS_EQUAL(tensor.
dimension(1), tensor_row_major.dimension(2));
358 VERIFY_IS_EQUAL(tensor.
dimension(2), tensor_row_major.dimension(1));
359 VERIFY_IS_EQUAL(tensor.
dimension(3), tensor_row_major.dimension(0));
362 VERIFY_IS_EQUAL(result.
dimension(0), result_row_major.dimension(4));
363 VERIFY_IS_EQUAL(result.
dimension(1), result_row_major.dimension(3));
364 VERIFY_IS_EQUAL(result.
dimension(2), result_row_major.dimension(2));
365 VERIFY_IS_EQUAL(result.
dimension(3), result_row_major.dimension(1));
366 VERIFY_IS_EQUAL(result.
dimension(4), result_row_major.dimension(0));
373 for (
int i = 0; (i+stride+ksize-1) <= input_rows; i += stride) {
374 for (
int j = 0; (j+stride+ksize-1) <= input_cols; j += stride) {
375 int patchId = i+input_rows*j;
376 for (
int r = 0; r < ksize; ++r) {
377 for (
int c = 0; c < ksize; ++c) {
378 for (
int d = 0;
d < input_depth; ++
d) {
379 for (
int b = 0;
b < input_batches; ++
b) {
380 float expected = 0.0f;
381 float expected_row_major = 0.0f;
382 int row_offset = r*stride + i - row_padding;
383 int col_offset = c*stride + j - col_padding;
384 if (row_offset >= 0 && col_offset >= 0 && row_offset < input_rows && col_offset < input_cols) {
385 expected = tensor(
d, row_offset, col_offset,
b);
386 expected_row_major = tensor_row_major(
b, col_offset, row_offset,
d);
389 if (result(
d, r, c, patchId,
b) != expected) {
390 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
392 VERIFY_IS_EQUAL(result(
d, r, c, patchId,
b), expected);
394 if (result_row_major(
b, patchId, c, r,
d) != expected_row_major) {
395 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
397 VERIFY_IS_EQUAL(result_row_major(
b, patchId, c, r,
d), expected_row_major);
399 VERIFY_IS_EQUAL(expected, expected_row_major);
419 single_pixel_patch = tensor.extract_image_patches(1, 1);
420 VERIFY_IS_EQUAL(single_pixel_patch.dimension(0), 2);
421 VERIFY_IS_EQUAL(single_pixel_patch.dimension(1), 1);
422 VERIFY_IS_EQUAL(single_pixel_patch.dimension(2), 1);
423 VERIFY_IS_EQUAL(single_pixel_patch.dimension(3), 3*5);
427 single_pixel_patch_row_major = tensor_row_major.extract_image_patches(1, 1);
428 VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(0), 3*5);
429 VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(1), 1);
430 VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(2), 1);
431 VERIFY_IS_EQUAL(single_pixel_patch_row_major.dimension(3), 2);
433 for (
int i = 0; i < tensor.
size(); ++i) {
435 if (tensor.
data()[i] != single_pixel_patch.data()[i]) {
436 std::cout <<
"Mismatch detected at index " << i <<
" : " << tensor.
data()[i] <<
" vs " << single_pixel_patch.data()[i] << std::endl;
438 VERIFY_IS_EQUAL(single_pixel_patch.data()[i], tensor.
data()[i]);
440 if (tensor_row_major.
data()[i] != single_pixel_patch_row_major.data()[i]) {
441 std::cout <<
"Mismatch detected at index " << i <<
" : " 442 << tensor.
data()[i] <<
" vs " 443 << single_pixel_patch_row_major.data()[i] << std::endl;
445 VERIFY_IS_EQUAL(single_pixel_patch_row_major.data()[i],
446 tensor_row_major.
data()[i]);
447 VERIFY_IS_EQUAL(tensor.
data()[i], tensor_row_major.
data()[i]);
448 VERIFY_IS_EQUAL(single_pixel_patch.data()[i],
449 single_pixel_patch_row_major.data()[i]);
454 entire_image_patch = tensor.extract_image_patches(3, 5);
455 VERIFY_IS_EQUAL(entire_image_patch.dimension(0), 2);
456 VERIFY_IS_EQUAL(entire_image_patch.dimension(1), 3);
457 VERIFY_IS_EQUAL(entire_image_patch.dimension(2), 5);
458 VERIFY_IS_EQUAL(entire_image_patch.dimension(3), 3*5);
462 entire_image_patch_row_major = tensor_row_major.extract_image_patches(3, 5);
463 VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(0), 3*5);
464 VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(1), 5);
465 VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(2), 3);
466 VERIFY_IS_EQUAL(entire_image_patch_row_major.dimension(3), 2);
468 for (
int i = 0; i < 3; ++i) {
469 for (
int j = 0; j < 5; ++j) {
471 for (
int r = 0; r < 3; ++r) {
472 for (
int c = 0; c < 5; ++c) {
473 for (
int d = 0;
d < 2; ++
d) {
474 float expected = 0.0f;
475 float expected_row_major = 0.0f;
476 if (r-1+i >= 0 && c-2+j >= 0 && r-1+i < 3 && c-2+j < 5) {
477 expected = tensor(
d, r-1+i, c-2+j);
478 expected_row_major = tensor_row_major(c-2+j, r-1+i,
d);
481 if (entire_image_patch(
d, r, c, patchId) != expected) {
482 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d << std::endl;
484 VERIFY_IS_EQUAL(entire_image_patch(
d, r, c, patchId), expected);
486 if (entire_image_patch_row_major(patchId, c, r,
d) !=
487 expected_row_major) {
488 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d << std::endl;
490 VERIFY_IS_EQUAL(entire_image_patch_row_major(patchId, c, r,
d),
493 VERIFY_IS_EQUAL(expected, expected_row_major);
502 twod_patch = tensor.extract_image_patches(2, 2);
503 VERIFY_IS_EQUAL(twod_patch.
dimension(0), 2);
504 VERIFY_IS_EQUAL(twod_patch.
dimension(1), 2);
505 VERIFY_IS_EQUAL(twod_patch.
dimension(2), 2);
506 VERIFY_IS_EQUAL(twod_patch.
dimension(3), 3*5);
510 twod_patch_row_major = tensor_row_major.extract_image_patches(2, 2);
511 VERIFY_IS_EQUAL(twod_patch_row_major.dimension(0), 3*5);
512 VERIFY_IS_EQUAL(twod_patch_row_major.dimension(1), 2);
513 VERIFY_IS_EQUAL(twod_patch_row_major.dimension(2), 2);
514 VERIFY_IS_EQUAL(twod_patch_row_major.dimension(3), 2);
521 for (
int i = 0; i < 3; ++i) {
522 for (
int j = 0; j < 5; ++j) {
524 for (
int r = 0; r < 2; ++r) {
525 for (
int c = 0; c < 2; ++c) {
526 for (
int d = 0;
d < 2; ++
d) {
527 float expected = 0.0f;
528 float expected_row_major = 0.0f;
529 int row_offset = r*stride + i - row_padding;
530 int col_offset = c*stride + j - col_padding;
532 if (row_offset >= 0 && col_offset >= 0 && row_offset < tensor.
dimension(1) && col_offset < tensor.
dimension(2)) {
533 expected = tensor(
d, row_offset, col_offset);
535 if (twod_patch(
d, r, c, patchId) != expected) {
536 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d << std::endl;
538 VERIFY_IS_EQUAL(twod_patch(
d, r, c, patchId), expected);
540 if (row_offset >= 0 && col_offset >= 0 && row_offset < tensor_row_major.
dimension(1) && col_offset < tensor_row_major.
dimension(0)) {
541 expected_row_major = tensor_row_major(col_offset, row_offset,
d);
543 if (twod_patch_row_major(patchId, c, r,
d) != expected_row_major) {
544 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d << std::endl;
546 VERIFY_IS_EQUAL(twod_patch_row_major(patchId, c, r,
d), expected_row_major);
548 VERIFY_IS_EQUAL(expected, expected_row_major);
567 VERIFY_IS_EQUAL(l_out.
dimension(3), 128*128);
572 VERIFY_IS_EQUAL(l_out_row_major.dimension(0), 16);
573 VERIFY_IS_EQUAL(l_out_row_major.dimension(1), 128*128);
574 VERIFY_IS_EQUAL(l_out_row_major.dimension(2), 11);
575 VERIFY_IS_EQUAL(l_out_row_major.dimension(3), 11);
576 VERIFY_IS_EQUAL(l_out_row_major.dimension(4), 3);
578 for (
int b = 0;
b < 16; ++
b) {
579 for (
int i = 0; i < 128; ++i) {
580 for (
int j = 0; j < 128; ++j) {
581 int patchId = i+128*j;
582 for (
int c = 0; c < 11; ++c) {
583 for (
int r = 0; r < 11; ++r) {
584 for (
int d = 0;
d < 3; ++
d) {
585 float expected = 0.0f;
586 if (r-5+i >= 0 && c-5+j >= 0 && r-5+i < 128 && c-5+j < 128) {
587 expected = l_in(
d, r-5+i, c-5+j,
b);
590 if (l_out(
d, r, c, patchId,
b) != expected) {
591 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
593 VERIFY_IS_EQUAL(l_out(
d, r, c, patchId,
b), expected);
595 if (l_out_row_major(
b, patchId, c, r,
d) !=
597 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j
598 <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b 601 VERIFY_IS_EQUAL(l_out_row_major(
b, patchId, c, r,
d),
611 l_in.
resize(16, 64, 64, 32);
613 l_out = l_in.extract_image_patches(9, 9);
617 VERIFY_IS_EQUAL(l_out.
dimension(3), 64*64);
621 l_out_row_major = l_in.
swap_layout().extract_image_patches(9, 9);
622 VERIFY_IS_EQUAL(l_out_row_major.dimension(0), 32);
623 VERIFY_IS_EQUAL(l_out_row_major.dimension(1), 64*64);
624 VERIFY_IS_EQUAL(l_out_row_major.dimension(2), 9);
625 VERIFY_IS_EQUAL(l_out_row_major.dimension(3), 9);
626 VERIFY_IS_EQUAL(l_out_row_major.dimension(4), 16);
628 for (
int b = 0;
b < 32; ++
b) {
629 for (
int i = 0; i < 64; ++i) {
630 for (
int j = 0; j < 64; ++j) {
631 int patchId = i+64*j;
632 for (
int c = 0; c < 9; ++c) {
633 for (
int r = 0; r < 9; ++r) {
634 for (
int d = 0;
d < 16; ++
d) {
635 float expected = 0.0f;
636 if (r-4+i >= 0 && c-4+j >= 0 && r-4+i < 64 && c-4+j < 64) {
637 expected = l_in(
d, r-4+i, c-4+j,
b);
640 if (l_out(
d, r, c, patchId,
b) != expected) {
641 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
643 VERIFY_IS_EQUAL(l_out(
d, r, c, patchId,
b), expected);
645 if (l_out_row_major(
b, patchId, c, r,
d) != expected) {
646 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
648 VERIFY_IS_EQUAL(l_out_row_major(
b, patchId, c, r,
d), expected);
657 l_in.
resize(32, 16, 16, 32);
659 l_out = l_in.extract_image_patches(7, 7);
663 VERIFY_IS_EQUAL(l_out.
dimension(3), 16*16);
667 l_out_row_major = l_in.
swap_layout().extract_image_patches(7, 7);
668 VERIFY_IS_EQUAL(l_out_row_major.dimension(0), 32);
669 VERIFY_IS_EQUAL(l_out_row_major.dimension(1), 16*16);
670 VERIFY_IS_EQUAL(l_out_row_major.dimension(2), 7);
671 VERIFY_IS_EQUAL(l_out_row_major.dimension(3), 7);
672 VERIFY_IS_EQUAL(l_out_row_major.dimension(4), 32);
674 for (
int b = 0;
b < 32; ++
b) {
675 for (
int i = 0; i < 16; ++i) {
676 for (
int j = 0; j < 16; ++j) {
677 int patchId = i+16*j;
678 for (
int c = 0; c < 7; ++c) {
679 for (
int r = 0; r < 7; ++r) {
680 for (
int d = 0;
d < 32; ++
d) {
681 float expected = 0.0f;
682 if (r-3+i >= 0 && c-3+j >= 0 && r-3+i < 16 && c-3+j < 16) {
683 expected = l_in(
d, r-3+i, c-3+j,
b);
686 if (l_out(
d, r, c, patchId,
b) != expected) {
687 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
689 VERIFY_IS_EQUAL(l_out(
d, r, c, patchId,
b), expected);
691 if (l_out_row_major(
b, patchId, c, r,
d) != expected) {
692 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
694 VERIFY_IS_EQUAL(l_out_row_major(
b, patchId, c, r,
d), expected);
703 l_in.
resize(64, 13, 13, 32);
705 l_out = l_in.extract_image_patches(3, 3);
709 VERIFY_IS_EQUAL(l_out.
dimension(3), 13*13);
713 l_out_row_major = l_in.
swap_layout().extract_image_patches(3, 3);
714 VERIFY_IS_EQUAL(l_out_row_major.dimension(0), 32);
715 VERIFY_IS_EQUAL(l_out_row_major.dimension(1), 13*13);
716 VERIFY_IS_EQUAL(l_out_row_major.dimension(2), 3);
717 VERIFY_IS_EQUAL(l_out_row_major.dimension(3), 3);
718 VERIFY_IS_EQUAL(l_out_row_major.dimension(4), 64);
720 for (
int b = 0;
b < 32; ++
b) {
721 for (
int i = 0; i < 13; ++i) {
722 for (
int j = 0; j < 13; ++j) {
723 int patchId = i+13*j;
724 for (
int c = 0; c < 3; ++c) {
725 for (
int r = 0; r < 3; ++r) {
726 for (
int d = 0;
d < 64; ++
d) {
727 float expected = 0.0f;
728 if (r-1+i >= 0 && c-1+j >= 0 && r-1+i < 13 && c-1+j < 13) {
729 expected = l_in(
d, r-1+i, c-1+j,
b);
732 if (l_out(
d, r, c, patchId,
b) != expected) {
733 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
735 VERIFY_IS_EQUAL(l_out(
d, r, c, patchId,
b), expected);
737 if (l_out_row_major(
b, patchId, c, r,
d) != expected) {
738 std::cout <<
"Mismatch detected at index i=" << i <<
" j=" << j <<
" r=" << r <<
" c=" << c <<
" d=" <<
d <<
" b=" <<
b << std::endl;
740 VERIFY_IS_EQUAL(l_out_row_major(
b, patchId, c, r,
d), expected);
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
void test_patch_no_extra_dim()
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorLayoutSwapOp< const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > swap_layout() const
void test_cxx11_tensor_image_patch()
void test_patch_padding_valid_same_value()
void test_patch_padding_valid()
EIGEN_DEVICE_FUNC void resize(const array< Index, NumIndices > &dimensions)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
void test_patch_padding_same()
void test_imagenet_patches()
EIGEN_DEVICE_FUNC const Scalar & b
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const