↓ Skip to main content
  1. Tags/

Caffe

2022

2020

caffe 源码学习笔记(11) argmax layer

·1300 words·3 mins
背景 # 似乎没什么背景,继续看 caffe 代码。 argmax 的作用是返回一个 blob 某个维度(或者 batch_size 之后的维度)的 top_k 的 index(或者 pair(index, value))。 proto # 还是先看 proto。

caffe 源码学习笔记(10) eltwise layer

·988 words·2 mins
背景 # 这个 layer 和 reduce layer 有一些相似,就干脆一起看了。 作用是输入至少两个 blob,然后对每个 blob 中的元素做一些运算,最后得到一个 blob。 caffe 支持的运算有 “PROD”、“SUM”、“MAX” 三种。

caffe 源码学习笔记(9) reduce layer

·1251 words·3 mins
背景 # 其实没什么背景,继续啃 caffe 代码而已 2333。 reduce layer 其实就是做 reduce 操作,把一个任意 shape 的 blob 通过某种运算变成一个 scalar。 caffe 目前支持求和(SUM)、绝对值的和(ASUM)、平方和(SUMSQ),以及对得到的 scalar 的总数求平均的求和(MEAN)。

caffe 源码学习笔记(8) loss function

·1095 words·3 mins
背景 # 虽然不太care 训练的过程,但是由于容易看懂的layer都看得差不多了 所以打算看一下这些loss function. Euclidean Loss (L2 loss) # 一般用于 “real-valued regression tasks”。比如之前项目里用的人脸年龄模型,就是用了这个 Loss。

caffe 源码学习笔记(7) slice layer

·1121 words·3 mins
背景 # OCR 组那边有个 shufflenet 的网络,里面有个 pytorch op 叫 chunk,转成的 onnx 对应的 op 是 split。 作用是: Split a tensor into a list of tensors, along the specified ‘axis’. Lengths of the parts can be specified using argument ‘split’. Otherwise, the tensor is split to equal sized parts.

caffe 源码学习笔记(6) reshape layer

·1851 words·4 mins
背景 # 最近在魔改 TensorRT 的 caffe parser。 之前 caffe 模型转到 trt 模型时,有一个修改需要将 reshape layer 的 param 末尾补 1,比较繁琐,于是看了下 caffe 的 reshape layer 的实现。

caffe 源码学习笔记(5) 卷积

·2756 words·6 mins
caffe中卷积运算的实现 # 暴力实现的卷积大概是这样子的 1 2for w in 1..W 3 for h in 1..H 4 for x in 1..K 5 for y in 1..K 6 for m in 1..M 7 for d in 1..D 8 output(w, h, m) += input(w+x, h+y, d) * filter(m, x, y, d) 9 end 10 end 11 end 12 end 13 end 14end 这种方式的效率显然很低,不意外地,caffe中并不是这样实现的.

caffe 源码学习笔记(4) 激活函数

·2604 words·6 mins
在看过 caffe 代码的三个核心部分 blob、layer、net 之后,陷入了不知道以什么顺序继续看的困境。 blob、layer、net 只是三个最基本的概念,关键还是在于各个 layer。但是 layer 这么多,要怎么看呢?想了一下,决定把相同作用的 layer 放在一起分析。今天先分析一下激活函数。

caffe 源码学习笔记(3) Net

·1790 words·4 mins
Net 基本介绍 # 网络通过组合与自动微分,共同定义一个函数及其梯度。 网络是由一些 Layer 组成的 DAG,也就是有向无环图,在 caffe 中通常由 prototxt 定义。 比如 1name: "LogReg" 2layer { 3 name: "mnist" 4 type: "Data" 5 top: "data" 6 top: "label" 7 data_param { 8 source: "input_leveldb" 9 batch_size: 64 10 } 11} 12layer { 13 name: "ip" 14 type: "InnerProduct" 15 bottom: "data" 16 top: "ip" 17 inner_product_param { 18 num_output: 2 19 } 20} 21layer { 22 name: "loss" 23 type: "SoftmaxWithLoss" 24 bottom: "ip" 25 bottom: "label" 26 top: "loss" 27} 定义了

caffe 源码学习笔记(2) Layer

·2896 words·6 mins
layer 整体介绍 # layer 是模型计算的基本单元, 类似于 pytorch 或者其他深度学习框架的 op。 layer 中的数据流向为:输入若干个 blob,称之为 “bottom blob”,经过 layer 的计算后,输出若干个 blob,称之为 “top blob”。

caffe 源码学习笔记(1) Blob

·1189 words·3 mins
迫于生计,开始看 caffe 代码。 会侧重于分析 inference 部分。 整体的依赖关系是:Net 由 Layer 组成,Layer 之间通过 Blob 传递数据。后面几篇会分别展开这三者。 blob 整体介绍 # blob 的含义及目的 # blob 在逻辑上表示的就是所谓的 tensor,blob 是 tensor 在 caffe 中的叫法。 在框架层面上,blob 的意义在于对数据进行封装,提供统一的接口。 这里的数据包含训练/inference 时用的数据,也包含模型参数、导数等数据。 深度学习离不开在 GPU 上的计算,blob 对数据的封装使得用户不必关心和 cuda 有关的数据传输细节。

2018

Eigen: C++开源矩阵学习笔记

·736 words·2 mins
接触 Eigen 的原因是最近在看 caffe/caffe2 源码,caffe2 中使用了 Eigen 库。Eigen 是一个基于 C++ 模板的线性代数库,直接将库下载后放在项目目录下,然后包含头文件就能使用,非常方便。对于 Linux 用户,只需要把头文件放到 /usr/include 下即可。此外,Eigen 的接口清晰,稳定高效。