提交 34f77d61 编写于 作者: L liuyibing01

Merge branch 'master' into 'master'

update doc and use os.path instead of pathlib

See merge request !33
...@@ -44,13 +44,13 @@ Note that filter is applied to all the examples in the base dataset when initial ...@@ -44,13 +44,13 @@ Note that filter is applied to all the examples in the base dataset when initial
### CacheDataset ### CacheDataset
By default, we preprocess dataset lazily in `DatasetMixin.get_example`. An example is preprocessed only only requested. But `CacheDataset` caches a base dataset (preprocesses all examples and cache s them eagerly beforehand). When preprocessing the dataset is slow, you can use Cachedataset to speed it up, but caching may consume a lot of RAM if the dataset is large. By default, we preprocess dataset lazily in `DatasetMixin.get_example`. An example is preprocessed only only requested. But `CacheDataset` caches the base dataset lazily, so each example is processed only once when it is first requested. When preprocessing the dataset is slow, you can use Cachedataset to speed it up, but caching may consume a lot of RAM if the dataset is large.
Finally, if preprocessing the dataset is slow and the processed dataset is too large to cache, you can write your own code to save them into files or databases and defines a Dataset to load them. Dataset is flexible, so you can create your own dataset painlessly. Finally, if preprocessing the dataset is slow and the processed dataset is too large to cache, you can write your own code to save them into files or databases, and then define a Dataset to load them. `Dataset` is flexible, so you can create your own dataset painlessly.
## DataCargo ## DataCargo
`DataCargo`, like `Dataset`, is an iterable of batches. We need datacargo because in deep learning, batching examples into batches exploits the computational resources of modern hardwares. You can iterate over it by `iter(datacargo)` or `for batch in datacargo`. It is an iterable but not an iterator, in that in can be iterated more than once. `DataCargo`, like `Dataset`, is an iterable of batches. We need datacargo because in deep learning, batching examples into batches exploits the computational resources of modern hardwares. You can iterate it by `iter(datacargo)` or `for batch in datacargo`. `DataCargo` is an iterable but not an iterator, in that in can be iterated more than once.
### batch function ### batch function
...@@ -104,7 +104,7 @@ Dataset --> Iterable[Example] | iter(Dataset) -> Iterator[Example] ...@@ -104,7 +104,7 @@ Dataset --> Iterable[Example] | iter(Dataset) -> Iterator[Example]
DataCargo --> Iterable[Batch] | iter(DataCargo) -> Iterator[Batch] DataCargo --> Iterable[Batch] | iter(DataCargo) -> Iterator[Batch]
``` ```
In order to construct an iterator of batches from an iterator of examples, we construct a DataCargo from a Dataset. In order to construct an iterator of batches from an iterator of examples, we construct a DataCargo from a Dataset.
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from pathlib import Path import os
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import librosa import librosa
...@@ -27,13 +27,11 @@ from ..data.batch import TextIDBatcher, SpecBatcher ...@@ -27,13 +27,11 @@ from ..data.batch import TextIDBatcher, SpecBatcher
class LJSpeech(DatasetMixin): class LJSpeech(DatasetMixin):
def __init__(self, root): def __init__(self, root):
super(LJSpeech, self).__init__() super(LJSpeech, self).__init__()
assert isinstance(root, ( self.root = root
str, Path)), "root should be a string or Path object"
self.root = root if isinstance(root, Path) else Path(root)
self.metadata = self._prepare_metadata() self.metadata = self._prepare_metadata()
def _prepare_metadata(self): def _prepare_metadata(self):
csv_path = self.root.joinpath("metadata.csv") csv_path = os.path.join(self.root, "metadata.csv")
metadata = pd.read_csv( metadata = pd.read_csv(
csv_path, csv_path,
sep="|", sep="|",
...@@ -51,7 +49,7 @@ class LJSpeech(DatasetMixin): ...@@ -51,7 +49,7 @@ class LJSpeech(DatasetMixin):
""" """
fname, raw_text, normalized_text = metadatum fname, raw_text, normalized_text = metadatum
wav_path = self.root.joinpath("wavs", fname + ".wav") wav_path = os.path.join(self.root, "wavs", fname + ".wav")
# load -> trim -> preemphasis -> stft -> magnitude -> mel_scale -> logscale -> normalize # load -> trim -> preemphasis -> stft -> magnitude -> mel_scale -> logscale -> normalize
wav, sample_rate = librosa.load( wav, sample_rate = librosa.load(
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os
import random import random
import librosa import librosa
...@@ -32,7 +33,7 @@ class Dataset(ljspeech.LJSpeech): ...@@ -32,7 +33,7 @@ class Dataset(ljspeech.LJSpeech):
def _get_example(self, metadatum): def _get_example(self, metadatum):
fname, _, _ = metadatum fname, _, _ = metadatum
wav_path = self.root.joinpath("wavs", fname + ".wav") wav_path = os.path.join(self.root, "wavs", fname + ".wav")
loaded_sr, audio = read(wav_path) loaded_sr, audio = read(wav_path)
assert loaded_sr == self.config.sample_rate assert loaded_sr == self.config.sample_rate
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册