Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pesto
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Paul Best
pesto
Commits
153c6751
Commit
153c6751
authored
1 year ago
by
Alain Riou
Browse files
Options
Downloads
Patches
Plain Diff
lazy device initialization
parent
8201e4f7
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
pesto/data.py
+10
-10
10 additions, 10 deletions
pesto/data.py
with
11 additions
and
10 deletions
CHANGELOG.md
+
1
−
0
View file @
153c6751
...
...
@@ -3,6 +3,7 @@
## v0.1.1
-
solve issue when exporting in PNG
-
solve device issue when changing sampling rate (#17)
## v0.1.0 - 2023-10-17
...
...
This diff is collapsed.
Click to expand it.
pesto/data.py
+
10
−
10
View file @
153c6751
...
...
@@ -17,9 +17,10 @@ class DataProcessor(nn.Module):
def
__init__
(
self
,
step_size
:
float
,
bins_per_semitone
:
int
=
3
,
sampling_rate
:
int
=
44100
,
sampling_rate
:
Optional
[
int
]
=
None
,
**
cqt_kwargs
):
super
(
DataProcessor
,
self
).
__init__
()
self
.
step_size
=
step_size
self
.
bins_per_semitone
=
bins_per_semitone
# CQT-related stuff
...
...
@@ -34,10 +35,13 @@ class DataProcessor(nn.Module):
self
.
lowest_bin
=
int
(
11
*
self
.
bins_per_semitone
/
2
+
0.5
)
self
.
highest_bin
=
self
.
lowest_bin
+
88
*
self
.
bins_per_semitone
#
hand
ling
different sampling rates
self
.
step_size
=
step_size
#
samp
ling
rate is lazily initialized
if
sampling_rate
is
not
None
:
self
.
sampling_rate
=
sampling_rate
# register a dummy tensor to get implicit access to the module's device
self
.
register_buffer
(
"
_device
"
,
torch
.
zeros
(()),
persistent
=
False
)
def
forward
(
self
,
x
:
torch
.
Tensor
):
r
"""
...
...
@@ -61,18 +65,14 @@ class DataProcessor(nn.Module):
return
log_cqt
def
_init_cqt_layer
(
self
,
sr
:
int
,
hop_length
:
int
):
if
self
.
cqt
is
not
None
:
device
=
self
.
cqt
.
cqt_kernels_real
.
device
else
:
device
=
None
self
.
cqt
=
CQT
(
sr
=
sr
,
hop_length
=
hop_length
,
**
self
.
cqt_kwargs
).
to
(
device
)
self
.
cqt
=
CQT
(
sr
=
sr
,
hop_length
=
hop_length
,
**
self
.
cqt_kwargs
).
to
(
self
.
_device
.
device
)
@property
def
sampling_rate
(
self
)
->
int
:
return
self
.
_sampling_rate
@sampling_rate.setter
def
sampling_rate
(
self
,
sr
:
int
):
def
sampling_rate
(
self
,
sr
:
int
)
->
None
:
if
sr
==
self
.
_sampling_rate
:
return
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment