col2im

  • columns์„ ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” ๊ฒƒ์„ ๋งํ•ฉ๋‹ˆ๋‹ค.

col2im_add_pixel

void col2im_add_pixel(float *im, int height, int width, int channels,
                        int row, int col, int channel, int pad, float val)
{
    row -= pad;
    col -= pad;

    if (row < 0 || col < 0 ||
        row >= height || col >= width) return;
    im[col + width*(row + height*channel)] += val;
}

ํ•จ์ˆ˜ ์ด๋ฆ„: col2im_add_pixel

์ž…๋ ฅ:

  • im: 1์ฐจ์› ๋ฐฐ์—ด ํ˜•ํƒœ์˜ ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ

  • height: ์ด๋ฏธ์ง€ ๋†’์ด

  • width: ์ด๋ฏธ์ง€ ๋„ˆ๋น„

  • channels: ์ด๋ฏธ์ง€ ์ฑ„๋„ ์ˆ˜

  • row: ์ ์šฉํ•  ํ”ฝ์…€์˜ y ์ขŒํ‘œ

  • col: ์ ์šฉํ•  ํ”ฝ์…€์˜ x ์ขŒํ‘œ

  • channel: ์ ์šฉํ•  ์ฑ„๋„ ๋ฒˆํ˜ธ

  • pad: ํŒจ๋”ฉ ํฌ๊ธฐ

  • val: ์ถ”๊ฐ€ํ•  ๊ฐ’

๋™์ž‘:

  • col2im ํ•จ์ˆ˜ ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉ๋˜๋ฉฐ, ์ด๋ฏธ์ง€์˜ ํŠน์ • ์œ„์น˜์— ๊ฐ’์„ ๋”ํ•ฉ๋‹ˆ๋‹ค.

  • ์ฃผ์–ด์ง„ row, col, channel ๊ฐ’์„ ์ด์šฉํ•ด ์ด๋ฏธ์ง€์˜ ํ•ด๋‹น ์œ„์น˜์— val ๊ฐ’์„ ๋”ํ•ฉ๋‹ˆ๋‹ค.

  • ํŒจ๋”ฉ์ด ์ ์šฉ๋œ ์ด๋ฏธ์ง€์—์„œ๋Š” row, col ๊ฐ’์— pad ๊ฐ’์„ ๋บ€ ์œ„์น˜์— ๊ฐ’์„ ๋”ํ•ฉ๋‹ˆ๋‹ค.

  • ์ด๋ฏธ์ง€๋ฅผ 1์ฐจ์› ๋ฐฐ์—ด๋กœ ์ €์žฅํ•œ ๊ฒฝ์šฐ, ํ•ด๋‹น ์œ„์น˜์— ์žˆ๋Š” ๊ฐ’์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

์„ค๋ช…:

  • ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ์—์„œ ํŠน์ • ์œ„์น˜์— ๊ฐ’์„ ๋”ํ•˜๋Š” ์—ฐ์‚ฐ์€ ๋‹ค์–‘ํ•œ ๊ณณ์—์„œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

  • ์ด ํ•จ์ˆ˜๋Š” col2im ํ•จ์ˆ˜ ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉ๋˜๋ฉฐ, ํŒจ๋”ฉ์ด ์ ์šฉ๋œ ์ด๋ฏธ์ง€์˜ ์ด๋ฏธ์ง€ ๊ฐ’์„ ๋ณต์›ํ•˜๋Š” ๊ณผ์ •์—์„œ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

  • ํŒจ๋”ฉ์ด ์ ์šฉ๋œ ์ด๋ฏธ์ง€๋Š” ์ถœ๋ ฅ ์ด๋ฏธ์ง€์˜ ํฌ๊ธฐ์™€ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์—, col2im ํ•จ์ˆ˜์—์„œ๋Š” ์ž…๋ ฅ ์ด๋ฏธ์ง€์˜ ๊ฐ’์„ ์ถœ๋ ฅ ์ด๋ฏธ์ง€์˜ ๊ฐ ์œ„์น˜์— ๋งคํ•‘ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • ์ด๋ฅผ ์œ„ํ•ด ์ถœ๋ ฅ ์ด๋ฏธ์ง€์˜ ์œ„์น˜์— ํ•ด๋‹นํ•˜๋Š” ์ž…๋ ฅ ์ด๋ฏธ์ง€์˜ ์œ„์น˜๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๊ณผ์ •์—์„œ, ํŒจ๋”ฉ์ด ์ ์šฉ๋œ ์ž…๋ ฅ ์ด๋ฏธ์ง€์˜ ํŠน์ • ์œ„์น˜์— ๊ฐ’์„ ๋”ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • ์ด ํ•จ์ˆ˜๋Š” ์ด๋ฏธ์ง€๋ฅผ 1์ฐจ์› ๋ฐฐ์—ด๋กœ ์ €์žฅํ•œ ๊ฒฝ์šฐ, ์ฃผ์–ด์ง„ row, col, channel ๊ฐ’์„ ์ด์šฉํ•ด ํ•ด๋‹น ์œ„์น˜์˜ ๊ฐ’์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

col2im_cpu

//This one might be too, can't remember.
void col2im_cpu(float* data_col,
         int channels,  int height,  int width,
         int ksize,  int stride, int pad, float* data_im)
{
    int c,h,w;
    int height_col = (height + 2*pad - ksize) / stride + 1;
    int width_col = (width + 2*pad - ksize) / stride + 1;

    int channels_col = channels * ksize * ksize;
    for (c = 0; c < channels_col; ++c) {
        int w_offset = c % ksize;
        int h_offset = (c / ksize) % ksize;
        int c_im = c / ksize / ksize;
        for (h = 0; h < height_col; ++h) {
            for (w = 0; w < width_col; ++w) {
                int im_row = h_offset + h * stride;
                int im_col = w_offset + w * stride;
                int col_index = (c * height_col + h) * width_col + w;
                double val = data_col[col_index];
                col2im_add_pixel(data_im, height, width, channels,
                        im_row, im_col, c_im, pad, val);
            }
        }
    }
}

ํ•จ์ˆ˜ ์ด๋ฆ„: col2im_cpu

์ž…๋ ฅ:

  • data_col: 1D ๋ฐฐ์—ด ํ˜•ํƒœ๋กœ ์ž…๋ ฅ๋œ ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ (channels_col x height_col x width_col)

  • channels: ์ด๋ฏธ์ง€์˜ ์ฑ„๋„ ์ˆ˜

  • height: ์ด๋ฏธ์ง€์˜ ๋†’์ด

  • width: ์ด๋ฏธ์ง€์˜ ๋„ˆ๋น„

  • ksize: ์ปค๋„์˜ ํฌ๊ธฐ

  • stride: ์ŠคํŠธ๋ผ์ด๋“œ์˜ ํฌ๊ธฐ

  • pad: ํŒจ๋”ฉ์˜ ํฌ๊ธฐ

  • data_im: 3D ๋ฐฐ์—ด ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜๋œ ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ (channels x height x width)

๋™์ž‘:

  • ์ฃผ์–ด์ง„ data_col์„ col2im ๋ณ€ํ™˜ํ•˜์—ฌ data_im์— ์ €์žฅํ•จ

  • col2im ๋ณ€ํ™˜์€ convolution ์—ฐ์‚ฐ ์‹œ ์ž…๋ ฅ ๋ฐ์ดํ„ฐ๋ฅผ ์ปค๋„์˜ ๋ชจ์–‘์— ๋งž๊ฒŒ ์žฌ๋ฐฐ์—ดํ•˜๋Š” ๊ณผ์ •์„ ๋งํ•จ

  • col2im ๋ณ€ํ™˜์„ ํ†ตํ•ด ์ปค๋„๊ณผ์˜ ํ–‰๋ ฌ ๊ณฑ์…ˆ ์—ฐ์‚ฐ์„ ๋Œ€์‹ ํ•  ์ˆ˜ ์žˆ์–ด ๊ณ„์‚ฐ ๋น„์šฉ์„ ์ค„์ผ ์ˆ˜ ์žˆ์Œ

์„ค๋ช…:

  • channels_col์€ ์ปค๋„์˜ ํฌ๊ธฐ์™€ ์ž…๋ ฅ ์ด๋ฏธ์ง€์˜ ์ฑ„๋„ ์ˆ˜๋ฅผ ๊ณฑํ•œ ๊ฐ’์ž„

  • height_col๊ณผ width_col์€ ์ปค๋„์˜ ํฌ๊ธฐ์™€ ์ŠคํŠธ๋ผ์ด๋“œ, ํŒจ๋”ฉ ์ •๋ณด๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ณ„์‚ฐ๋จ

  • for๋ฌธ์„ ์ด์šฉํ•˜์—ฌ channels_col, height_col, width_col์— ๋Œ€ํ•ด ๋ฐ˜๋ณตํ•˜๋ฉฐ col2im ๋ณ€ํ™˜ ์ˆ˜ํ–‰

  • channels_col์„ ๊ธฐ์ค€์œผ๋กœ w_offset๊ณผ h_offset์„ ๊ณ„์‚ฐํ•˜์—ฌ ์ปค๋„ ๋‚ด์—์„œ์˜ ์œ„์น˜ ์ •๋ณด๋ฅผ ํš๋“ํ•จ

  • c_im์„ ๊ณ„์‚ฐํ•˜์—ฌ ํ˜„์žฌ ์œ„์น˜๊ฐ€ ์ž…๋ ฅ ์ด๋ฏธ์ง€์˜ ์–ด๋Š ์ฑ„๋„์ธ์ง€ ํŒ๋‹จํ•จ

  • for๋ฌธ์„ ์ด์šฉํ•˜์—ฌ height_col๊ณผ width_col์— ๋Œ€ํ•ด ๋ฐ˜๋ณตํ•˜๋ฉฐ col2im_add_pixel ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ data_im์— ๊ฐ’์„ ์ €์žฅํ•จ

  • col2im_add_pixel ํ•จ์ˆ˜๋Š” ์ด๋ฏธ์ง€๋ฅผ col2im ๋ณ€ํ™˜ํ•œ ๊ฒฐ๊ณผ์ธ data_im์— ๊ฐ’์„ ์ €์žฅํ•˜๋Š” ํ•จ์ˆ˜์ž„

  • col2im_add_pixel ํ•จ์ˆ˜๋Š” ์ž…๋ ฅ ์ด๋ฏธ์ง€์˜ ์œ„์น˜ ์ •๋ณด์™€ ๊ฐ’์„ ์ด์šฉํ•˜์—ฌ data_im์— ๊ฐ’์„ ์ €์žฅํ•จ

Last updated