MCPcopy Create free account
hub / github.com/davisking/dlib / img2col

Function img2col

dlib/cuda/cpu_dlib.cpp:2835–2886  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2833 // ------------------------------------------------------------------------------------
2834
2835 void img2col(
2836 matrix<float>& output,
2837 const tensor& data,
2838 long n,
2839 long filter_nr,
2840 long filter_nc,
2841 long stride_y,
2842 long stride_x,
2843 long padding_y,
2844 long padding_x
2845 )
2846 {
2847 const auto d = data.host() + data.k()*data.nr()*data.nc()*n;
2848 const rectangle boundary = get_rect(data);
2849
2850 const long out_nr = 1+(data.nr()+2*padding_y-filter_nr)/stride_y;
2851 const long out_nc = 1+(data.nc()+2*padding_x-filter_nc)/stride_x;
2852
2853 output.set_size(out_nr*out_nc,
2854 data.k()*filter_nr*filter_nc);
2855 DLIB_CASSERT(output.size() != 0);
2856 float* t = &output(0,0);
2857
2858 // now fill in the Toeplitz output matrix for the n-th sample in data.
2859 long cnt = 0;
2860 const long max_r = data.nr() + padding_y-(filter_nr-1);
2861 const long max_c = data.nc() + padding_x-(filter_nc-1);
2862 for (long r = -padding_y; r < max_r; r+=stride_y)
2863 {
2864 for (long c = -padding_x; c < max_c; c+=stride_x)
2865 {
2866 for (long k = 0; k < data.k(); ++k)
2867 {
2868 for (long y = 0; y < filter_nr; ++y)
2869 {
2870 for (long x = 0; x < filter_nc; ++x)
2871 {
2872 DLIB_ASSERT(cnt < output.size());
2873 long xx = c+x;
2874 long yy = r+y;
2875 if (boundary.contains(xx,yy))
2876 *t = d[(k*data.nr() + yy)*data.nc() + xx];
2877 else
2878 *t = 0;
2879 ++t;
2880 ++cnt;
2881 }
2882 }
2883 }
2884 }
2885 }
2886 }
2887
2888 void col2img(
2889 const matrix<float>& output,

Callers 2

operator()Method · 0.85

Calls 9

get_rectFunction · 0.85
outputFunction · 0.85
hostMethod · 0.45
kMethod · 0.45
nrMethod · 0.45
ncMethod · 0.45
set_sizeMethod · 0.45
sizeMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected