Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
1efba850
"vscode:/vscode.git/clone" did not exist on "16cd550c8554796d2b20b39162dbab7db8355476"
Unverified
Commit
1efba850
authored
Oct 05, 2021
by
moto
Committed by
GitHub
Oct 05, 2021
Browse files
Remove deprecated dataset utils (#1826)
parent
fc4f481b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
125 deletions
+0
-125
test/torchaudio_unittest/datasets/utils_test.py
test/torchaudio_unittest/datasets/utils_test.py
+0
-37
torchaudio/datasets/__init__.py
torchaudio/datasets/__init__.py
+0
-3
torchaudio/datasets/utils.py
torchaudio/datasets/utils.py
+0
-85
No files found.
test/torchaudio_unittest/datasets/utils_test.py
deleted
100644 → 0
View file @
fc4f481b
import
torch
from
torchaudio_unittest.common_utils
import
(
TorchaudioTestCase
,
TempDirMixin
)
from
torchaudio.datasets
import
utils
as
dataset_utils
class
Dataset
(
torch
.
utils
.
data
.
Dataset
):
def
__getitem__
(
self
,
n
):
sample_rate
=
8000
waveform
=
n
*
torch
.
ones
(
2
,
256
)
return
waveform
,
sample_rate
def
__len__
(
self
)
->
int
:
return
2
def
__iter__
(
self
):
for
i
in
range
(
len
(
self
)):
yield
self
[
i
]
class
TestIterator
(
TorchaudioTestCase
,
TempDirMixin
):
backend
=
'default'
def
test_disckcache_iterator
(
self
):
data
=
dataset_utils
.
diskcache_iterator
(
Dataset
(),
self
.
get_base_temp_dir
())
# Save
data
[
0
]
# Load
data
[
0
]
def
test_bg_iterator
(
self
):
data
=
dataset_utils
.
bg_iterator
(
Dataset
(),
5
)
for
_
in
data
:
pass
torchaudio/datasets/__init__.py
View file @
1efba850
from
.commonvoice
import
COMMONVOICE
from
.librispeech
import
LIBRISPEECH
from
.speechcommands
import
SPEECHCOMMANDS
from
.utils
import
bg_iterator
,
diskcache_iterator
from
.vctk
import
VCTK_092
from
.gtzan
import
GTZAN
from
.yesno
import
YESNO
...
...
@@ -23,7 +22,5 @@ __all__ = [
"CMUARCTIC"
,
"CMUDict"
,
"LIBRITTS"
,
"diskcache_iterator"
,
"bg_iterator"
,
"TEDLIUM"
,
]
torchaudio/datasets/utils.py
View file @
1efba850
...
...
@@ -2,19 +2,13 @@ import hashlib
import
logging
import
os
import
tarfile
import
threading
import
urllib
import
urllib.request
import
zipfile
from
queue
import
Queue
from
typing
import
Any
,
Iterable
,
List
,
Optional
import
torch
from
torch.utils.data
import
Dataset
from
torch.utils.model_zoo
import
tqdm
from
torchaudio._internal.module_utils
import
deprecated
def
stream_url
(
url
:
str
,
start_byte
:
Optional
[
int
]
=
None
,
...
...
@@ -203,82 +197,3 @@ def extract_archive(from_path: str, to_path: Optional[str] = None, overwrite: bo
pass
raise
NotImplementedError
(
"We currently only support tar.gz, tgz, and zip achives."
)
class
_DiskCache
(
Dataset
):
"""
Wrap a dataset so that, whenever a new item is returned, it is saved to disk.
"""
def
__init__
(
self
,
dataset
:
Dataset
,
location
:
str
=
".cached"
)
->
None
:
self
.
dataset
=
dataset
self
.
location
=
location
self
.
_id
=
id
(
self
)
self
.
_cache
:
List
=
[
None
]
*
len
(
dataset
)
def
__getitem__
(
self
,
n
:
int
)
->
Any
:
if
self
.
_cache
[
n
]:
f
=
self
.
_cache
[
n
]
return
torch
.
load
(
f
)
f
=
str
(
self
.
_id
)
+
"-"
+
str
(
n
)
f
=
os
.
path
.
join
(
self
.
location
,
f
)
item
=
self
.
dataset
[
n
]
self
.
_cache
[
n
]
=
f
os
.
makedirs
(
self
.
location
,
exist_ok
=
True
)
torch
.
save
(
item
,
f
)
return
item
def
__len__
(
self
)
->
int
:
return
len
(
self
.
dataset
)
@
deprecated
(
''
,
version
=
'0.11'
)
def
diskcache_iterator
(
dataset
:
Dataset
,
location
:
str
=
".cached"
)
->
Dataset
:
return
_DiskCache
(
dataset
,
location
)
class
_ThreadedIterator
(
threading
.
Thread
):
"""
Prefetch the next queue_length items from iterator in a background thread.
Example:
>> for i in bg_iterator(range(10)):
>> print(i)
"""
class
_End
:
pass
def
__init__
(
self
,
generator
:
Iterable
,
maxsize
:
int
)
->
None
:
threading
.
Thread
.
__init__
(
self
)
self
.
queue
:
Queue
=
Queue
(
maxsize
)
self
.
generator
=
generator
self
.
daemon
=
True
self
.
start
()
def
run
(
self
)
->
None
:
for
item
in
self
.
generator
:
self
.
queue
.
put
(
item
)
self
.
queue
.
put
(
self
.
_End
)
def
__iter__
(
self
)
->
Any
:
return
self
def
__next__
(
self
)
->
Any
:
next_item
=
self
.
queue
.
get
()
if
next_item
==
self
.
_End
:
raise
StopIteration
return
next_item
# Required for Python 2.7 compatibility
def
next
(
self
)
->
Any
:
return
self
.
__next__
()
@
deprecated
(
''
,
version
=
'0.11'
)
def
bg_iterator
(
iterable
:
Iterable
,
maxsize
:
int
)
->
Any
:
return
_ThreadedIterator
(
iterable
,
maxsize
=
maxsize
)
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