YOLO 卷积层代码学习

卷积层的初始化

void im2col_cpu(float* data_im,
     int channels,  int height,  int width,
     int ksize,  int stride, int pad, float* data_col) 
{
    int c,h,w;
    int height_col = (height - ksize) / stride + 1;
    int width_col = (width - ksize) / stride + 1;
    if (pad){
        height_col = 1 + (height-1) / stride;
        width_col = 1 + (width-1) / stride;
        pad = ksize/2;
    }
    int channels_col = channels * ksize * ksize;
    for (c = 0; c < channels_col; ++c) {
        //下面的三个坐标表示在卷积核里面的位置。存储是一个通道,一行一行的存储。
        //因此wide_offset是ksize的取余,h_offset是ksize(核的宽)的倍数然后对ksize(每个核的高)的取余。
        //c_im,每个核的通道为ksize*ksize。
        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;
                data_col[col_index] = im2col_get_pixel(data_im, height, width, channels,
                        im_row, im_col, c_im, pad);
            }
        }
    }
}

convolutional_layer make_convolutional_layer(int batch, int h, int w, int c, int n, int size, int stride, int pad, ACTIVATION activation, int batch_normalize, int binary)
{
    int i;
    convolutional_layer l = {
  0};
    l.type = CONVOLUTIONAL;//层的类别

    l.h = h;//输入的featuremap的高
    l.w = w;//输入的featuremap的宽
    l.c = c;//输入的featuremap的通道数
    l.n = n;//卷积核的个数
    l.binary = binary;
    l.batch = batch;//每次输入的样本的个数
    l.stride = stride;//卷积运算的跳跃
    l.size = size;//卷积核的大小
    l.pad = pad;//是在featuremap上下左右扩展,pad等于0,就不增加,等于1,增加一个l.size的大小
    /*这小段代码是yolo计算输出featuremap高度的过程
        if (!l.pad) h -= l.size;
        else h -= 1;
        return h/l.stride + 1;
    */
    l.batch_normalize = batch_normalize;

    l.filters = calloc(c*n*size*size, sizeof(
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值