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
d22e6233
Commit
d22e6233
authored
Aug 04, 2025
by
前钰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
0b56dae0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
wavelet.py
4-模型改进/4.3-特征增强(下)/Conv/wavelet.py
+43
-0
No files found.
4-模型改进/4.3-特征增强(下)/Conv/wavelet.py
0 → 100644
View file @
d22e6233
import
pywt
import
pywt
import
pywt.data
import
torch
import
torch.nn.functional
as
F
def
create_wavelet_filter
(
wave
,
in_size
,
out_size
,
type
=
torch
.
float
):
w
=
pywt
.
Wavelet
(
wave
)
dec_hi
=
torch
.
tensor
(
w
.
dec_hi
[::
-
1
],
dtype
=
type
)
dec_lo
=
torch
.
tensor
(
w
.
dec_lo
[::
-
1
],
dtype
=
type
)
dec_filters
=
torch
.
stack
([
dec_lo
.
unsqueeze
(
0
)
*
dec_lo
.
unsqueeze
(
1
),
dec_lo
.
unsqueeze
(
0
)
*
dec_hi
.
unsqueeze
(
1
),
dec_hi
.
unsqueeze
(
0
)
*
dec_lo
.
unsqueeze
(
1
),
dec_hi
.
unsqueeze
(
0
)
*
dec_hi
.
unsqueeze
(
1
)],
dim
=
0
)
dec_filters
=
dec_filters
[:,
None
]
.
repeat
(
in_size
,
1
,
1
,
1
)
rec_hi
=
torch
.
tensor
(
w
.
rec_hi
[::
-
1
],
dtype
=
type
)
.
flip
(
dims
=
[
0
])
rec_lo
=
torch
.
tensor
(
w
.
rec_lo
[::
-
1
],
dtype
=
type
)
.
flip
(
dims
=
[
0
])
rec_filters
=
torch
.
stack
([
rec_lo
.
unsqueeze
(
0
)
*
rec_lo
.
unsqueeze
(
1
),
rec_lo
.
unsqueeze
(
0
)
*
rec_hi
.
unsqueeze
(
1
),
rec_hi
.
unsqueeze
(
0
)
*
rec_lo
.
unsqueeze
(
1
),
rec_hi
.
unsqueeze
(
0
)
*
rec_hi
.
unsqueeze
(
1
)],
dim
=
0
)
rec_filters
=
rec_filters
[:,
None
]
.
repeat
(
out_size
,
1
,
1
,
1
)
return
dec_filters
,
rec_filters
def
wavelet_transform
(
x
,
filters
):
b
,
c
,
h
,
w
=
x
.
shape
pad
=
(
filters
.
shape
[
2
]
//
2
-
1
,
filters
.
shape
[
3
]
//
2
-
1
)
x
=
F
.
conv2d
(
x
,
filters
,
stride
=
2
,
groups
=
c
,
padding
=
pad
)
x
=
x
.
reshape
(
b
,
c
,
4
,
h
//
2
,
w
//
2
)
return
x
def
inverse_wavelet_transform
(
x
,
filters
):
b
,
c
,
_
,
h_half
,
w_half
=
x
.
shape
pad
=
(
filters
.
shape
[
2
]
//
2
-
1
,
filters
.
shape
[
3
]
//
2
-
1
)
x
=
x
.
reshape
(
b
,
c
*
4
,
h_half
,
w_half
)
x
=
F
.
conv_transpose2d
(
x
,
filters
,
stride
=
2
,
groups
=
c
,
padding
=
pad
)
return
x
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