Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
点
点头人工智能课程-v6.0-影像
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
靓靓
点头人工智能课程-v6.0-影像
Commits
74e84cec
Commit
74e84cec
authored
Aug 04, 2025
by
前钰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
a6270e6d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
DSConv.py
4-模型改进/4.3-特征增强(下)/Conv/DSConv.py
+31
-0
No files found.
4-模型改进/4.3-特征增强(下)/Conv/DSConv.py
0 → 100644
View file @
74e84cec
import
torch
import
torch
import
torch.nn
as
nn
import
torch.nn.functional
as
F
class
DepthwiseSeparableConv
(
nn
.
Module
):
def
__init__
(
self
,
in_channels
,
out_channels
,
kernel_size
=
3
,
stride
=
1
,
padding
=
1
):
super
(
DepthwiseSeparableConv
,
self
)
.
__init__
()
# Step 1: Depthwise convolution(每个输入通道单独卷积)
self
.
depthwise
=
nn
.
Conv2d
(
in_channels
,
in_channels
,
kernel_size
=
kernel_size
,
stride
=
stride
,
padding
=
padding
,
groups
=
in_channels
,
bias
=
False
)
# Step 2: Pointwise convolution(1x1卷积,用于通道之间的信息融合)
self
.
pointwise
=
nn
.
Conv2d
(
in_channels
,
out_channels
,
kernel_size
=
1
,
stride
=
1
,
padding
=
0
,
bias
=
False
)
self
.
bn
=
nn
.
BatchNorm2d
(
out_channels
)
self
.
relu
=
nn
.
ReLU
(
inplace
=
True
)
def
forward
(
self
,
x
):
out
=
self
.
depthwise
(
x
)
# [B, C, H, W]
out
=
self
.
pointwise
(
out
)
# [B, C_out, H, W]
out
=
self
.
bn
(
out
)
out
=
self
.
relu
(
out
)
return
out
model
=
DepthwiseSeparableConv
(
in_channels
=
32
,
out_channels
=
32
)
input_tensor
=
torch
.
randn
(
1
,
32
,
128
,
128
)
# batch size 1, 32通道,128x128图像
output
=
model
(
input_tensor
)
print
(
output
.
shape
)
# 输出: torch.Size([1, 64, 128, 128])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment