爆改YOLOv8|利用yolov10的SCDown改进yolov8-下采样

1, 本文介绍

YOLOv10 的 SCDown 方法来优化 YOLOv8 的下采样过程。SCDown 通过点卷积调整通道维度,再通过深度卷积进行空间下采样,从而减少了计算成本和参数数量。这种方法不仅降低了延迟,还在保持下采样过程信息的同时提供了竞争性的性能。

关于SCDown 的详细介绍可以看论文:https://arxiv.org/pdf/2405.14458

本文将讲解如何将SCDown 融合进yolov8

话不多说,上代码!

2, 将SCDown 融合进yolov8

2.1 步骤一

找到如下的目录'ultralytics/nn/modules',然后在这个目录下创建一个SCDown.py文件,文件名字可以根据你自己的习惯起,然后将SCDown的核心代码复制进去


import torch
import torch.nn as nn
 
 
__all__ = ['SCDown']
 
def autopad(k, p=None, d=1):  # kernel, padding, dilation
    """Pad to 'same' shape outputs."""
    if d > 1:
        k = d * (k - 1) + 1 if
### YOLOv8 下采样模块改进方法 #### 使用YOLOv9下采样机制增强感受野 为了提升YOLOv8的目标分割性能,可以采用YOLOv9的下采样机制。这种改进能够显著扩大模型的感受野,从而更好地捕捉图像中的细节信息[^1]。 ```python def yolov9_downsample(input_tensor, filters): x = tf.keras.layers.Conv2D(filters=filters, kernel_size=3, strides=(2, 2), padding='same')(input_tensor) x = tf.keras.layers.BatchNormalization()(x) output = tf.keras.layers.LeakyReLU(alpha=0.1)(x) return output ``` #### 应用Context Guided Block (CG block) 另一种有效的改进方式是引入Context Guided Block (CG block),该模块源自CGNet论文,旨在模仿人类视觉系统的特性——即通过结合局部特征、周边环境及整体场景的信息来增强识别精度。具体实现时需调整原有的卷积层配置[^2]。 ```python class ContextGuidedBlock(tf.keras.Model): def __init__(self, channels): super(ContextGuidedBlock, self).__init__() # 定义局部分支 self.local_branch = tf.keras.Sequential([ tf.keras.layers.Conv2D(channels//4, 3, 1, 'same'), tf.keras.layers.BatchNorm(), tf.keras.layers.ReLU() ]) # 定义上下文分支 self.context_branch = tf.keras.Sequential([ tf.keras.layers.AvgPool2D(pool_size=(3, 3), strides=1, padding='same'), tf.keras.layers.Conv2D(channels//4, 1, 1), tf.keras.layers.BatchNorm(), tf.keras.layers.ReLU() ]) def call(self, inputs): local_features = self.local_branch(inputs) context_features = self.context_branch(inputs) fused_feature = tf.concat([local_features, context_features], axis=-1) return fused_feature ``` #### 利用空间通道解耦下采样(SCDown)技术 来自YOLOv10的空间通道解耦下采样方案同样适用于优化YOLOv8架构下的下采样过程。此方法通过对输入张量执行特定操作,在保持计算效率的同时提高了表达能力[^3]。 ```python def scdown_module(x_in, out_channels): branch_1 = tf.keras.layers.DepthwiseConv2D(kernel_size=3, strides=2, padding="same")(x_in) branch_1 = tf.keras.layers.Conv2D(out_channels // 2, kernel_size=1, strides=1, padding="valid")(branch_1) branch_2 = tf.keras.layers.MaxPooling2D((2, 2))(x_in) branch_2 = tf.keras.layers.Conv2D(out_channels // 2, kernel_size=1, strides=1, padding="valid")(branch_2) concat = tf.keras.layers.Concatenate()([branch_1, branch_2]) result = tf.keras.layers.Conv2D(out_channels, kernel_size=1, strides=1, padding="valid")(concat) return result ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值