大话设计模式-简单工厂模式
直觉地用计算机的方式去思考是初学者常见的问题 活字印刷 可维护:只更改需要更改的字 可复用:在后来的印刷中重复使用 可扩展:另外加字 高灵活:排版方式不同 使用封装、继承、多态,降低程序耦合。 业务封装 将业务和界面分离:Web、Windows、Linux平台下的计算机均可使用Operation类。只需重写界面即可。 松耦合 构建一个基类Operation,其他运算继承此基类,并重写其虚方法。如此可更容易地添加新运算。 简单工厂模式 用一个单独的类来进行创造实例的活动。 1234oper = OperationFactory.create_pperate('+')oper.num1 = 1oper.num2 = 1result = oper.get_result() 如果需要修改加法,只需修正class OperationAdd,增加其他运算只需添加对应的子类并修改工厂。 UML简介 接口实现:棒棒糖表示法 关联:一个类"知晓"另一个类,可用实线箭头表示 聚合:一种"弱拥有",A可包含B对象,但B对象不是A对象...
MMSegmentation实战
课程 课程的代码教学非常详细。本文的主要代码均来源于代码教学。 检查安装成功 12345import mmcvfrom mmcv.ops import get_compiling_cuda_version, get_compiler_versionprint('MMCV版本', mmcv.__version__)print('CUDA版本', get_compiling_cuda_version())print('编译器版本', get_compiler_version()) 实战 进行推理 12python demo/image_demo.py img.jpg config.py \ checkpoint.pth --out-file fname.jpg --device cuda:0 --opacity 0.5 运行语义分割预测 12345678from mmseg.apis import inference_modelfrom mmengine.model.utils import revert_sync...
语义分割小综述
课程 应用 人像分割 自动驾驶 医疗影像 智能遥感:河流、田地等 思路 先验知识:颜色相近,物体交界颜色变化 先验知识不完全准确 逐像素分类:滑窗,逐个滑动预测类别 需重复计算卷积 复用卷积:直接在feature map上预测 需要全连接层的卷积化:每个全连接层神经元用一个卷积核替换(Fully Convolutional Network) 预测图上采样:双线性插值或转置卷积 双线性插值可以用对应卷积核代替:先进行零插值,再使用设计好的卷积核卷积 转置卷积 也称升卷积Upconvolution或反卷积Deconvolution,但不建议使用反卷积,其在数学上与卷积不互逆。转置卷积Transposed Convolution名称来源于卷积对应的矩阵运算。 对于卷积运算 O=I∗h=CIO = I * h = CI O=I∗h=CI 其中hhh为卷积核,OOO为输出(小图),III为输入(大图),CCC为卷积运算的等价矩阵乘法项。可以发现其转置卷积有 I′=O′∗h′=CTO′I' = O'*h' = C^TO&...
mmDetection实战
课程 YOLOv3模型 主干网络:Darknet53 颈部:FPN 检测头 技巧 搜索模型: 1mim search mmdet --model "mask r-cnn" 推理 12345from mmdet.apis import init_detector, inference_detector, show_result_pyplotmodel = init_detector('config_path', 'checkpoint_path')result = inference_detector(model, 'img_path')show_result_pyplot(model, 'img_path', result) 推理 简单的推理 1234from mmdet.apis import init_detector, inference_detetor, show_result_pyplotmodel = init_detector(cfg, checkpo...
目标检测小综述
课程 这节课讲得有点划,硬核的部分都略去了orz 思路 滑窗:不可接受的效率成本 R-CNN、Fast R-CNN:Selective Search提议,比较复杂 Regional Proposal:使用一些特征减少框数 Selective Search:贪心算法将相邻而相似的图像块合并 消除滑窗重复计算:一次卷积计算所有特征,裁切特征图分类 密集预测 两阶段方法 区域提议+区域识别,逐步被单阶段取代 Fast R-CNN Faster R-CNN Mask R-CNN 锚框:原图上设置不同尺寸的基准框,基于特征独立预测其中是否包含物体(区域提议) 级联方法 Cascade R-CNN HTC 单阶段方法 YOLO Series SSD:在多个特征图上使用密集预测方法,产生所有位置、不同尺度、所有锚框的预测结果 锚框与真值匹配原则:一个真值框可匹配多个IoU > 0.5的锚框 8732个锚框分类 + 回归预测计算损失,每个锚框都有其分类、回归真值 Retina Net:FPN多尺度特征融合+Focal loss FCOS:直接...
mmClassification实战
笔记 训练注意事项 对Evaluation部分 123456evaluation = dict( interval=1, metric='accuracy', save_best='accuracy_top-1', metric_options={'topk':(1,)} # 由于总类为4,这里必须指明metric_options) 启用标签平滑: 12# 在head中修改lossloss=dict(type='LabelSmoothLoss', label_smooth_val=0.2, mode='original') load_from用于加载模型,resume_from用于重启训练,两者不同。 想要启用Wandb,可以用 1234567log_config = dict( interval=10, hooks=[ dict(type='TextLoggerHook'), dict(type='...
mmClassification学习
课程 mim很好用,感觉需要更多地研究一下 流程 下载配置文件和模型 1mim download mmcls --config mobilenetblablabla --dest . 使用API 123456from mmcls.apis import init_model, inference_modelmodel = init_model('config.py', 'model.pth', device='cuda:0')result = inference_model(model, 'pic.jpg')from mmcls.apis import show_result_pyplotshow_result_pyplot(model, 'pic.jpg', result) 修改配置文件 12345678num_classes = 10load_from = 'model_path.pth'type = 'CustomDataset&...
CV小综述
课程 设计图像特征 可以看这篇文章和这篇文章: 方向梯度直方图Histogram of Oriented Gradients/HOG,局部统计像素梯度的方向分布,将物体映射为低维特征向量,简化数据表达。 Dense grid descriptor (HOG, LBP) => Coding: local coordinate, super-vector => Pooling, SPM => Linear SVM 深度学习 用于解决此前难以进行的特征提取 卷积 多头注意力:实现一步特征提取 ResNet 有效性猜想 等同于多模型集成:路径之间的复杂组合,每种组合都视为一个新模型 Loss Surface更加平滑,图很好玩(Visualizing the Loss Landscape of Neural Nets) 改良 ResNet B/C/D:残差模块基部改进 ResNeXt:分组卷积(将通道拆解成两部分,分别进行卷积,再将结果堆叠),降低参数量 SEResNet:通道维度引入注意力机制 某些情况下分组卷积效果更好,可能是由于增强了通...
Mechanism: Address Translation
Mechanism: Address Translation CPU: limited direct execution (LDE) In virtualizing memory, we will pursue efficiency and control. CRUX: How to efficiently and flexibly virtualize memory? Technique: hardware-based address translation / address translation, changing the virtual address provided by the instruction to a physical address. Interposition is powerful: On of the usual benefits of such an approach is transparency. Dynamic (Hardware-based) Relocation base and bounds / dynamic relocation...
Interlude: Memory API
Interlude: Memory API CRUX: How to allocate and manage memory in UNIX/C programs? Types of Memory stack memory: allocations and deallocations are managed implicitly by the compiler. For this reason it is sometimes called automatic memory. Declaring memory on the stack in C is easy. For example, let’s say you need some space in function func() for an integer, called x. To declare such a piece of memory, you just do something like this: 123void func() { int x;} The compiler does the ...







