Skip to content

Commit

Permalink
Merge pull request #199 from wanghaoshuang/fix_ds2_reader
Browse files Browse the repository at this point in the history
Fix  local data variable in DS2 data generator.
  • Loading branch information
wanghaoshuang authored Aug 14, 2017
2 parents 65fdaca + 7b05cad commit 9538238
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions deep_speech_2/data_utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
from data_utils.speech import SpeechSegment
from data_utils.normalizer import FeatureNormalizer

# for caching tar files info
local_data = local()
local_data.tar2info = {}
local_data.tar2object = {}


class DataGenerator(object):
"""
Expand Down Expand Up @@ -89,6 +84,10 @@ def __init__(self,
self._num_threads = num_threads
self._rng = random.Random(random_seed)
self._epoch = 0
# for caching tar files info
self.local_data = local()
self.local_data.tar2info = {}
self.local_data.tar2object = {}

def process_utterance(self, filename, transcript):
"""Load, augment, featurize and normalize for speech data.
Expand Down Expand Up @@ -241,16 +240,16 @@ def _get_file_object(self, file):
"""
if file.startswith('tar:'):
tarpath, filename = file.split(':', 1)[1].split('#', 1)
if 'tar2info' not in local_data.__dict__:
local_data.tar2info = {}
if 'tar2object' not in local_data.__dict__:
local_data.tar2object = {}
if tarpath not in local_data.tar2info:
if 'tar2info' not in self.local_data.__dict__:
self.local_data.tar2info = {}
if 'tar2object' not in self.local_data.__dict__:
self.local_data.tar2object = {}
if tarpath not in self.local_data.tar2info:
object, infoes = self._parse_tar(tarpath)
local_data.tar2info[tarpath] = infoes
local_data.tar2object[tarpath] = object
return local_data.tar2object[tarpath].extractfile(
local_data.tar2info[tarpath][filename])
self.local_data.tar2info[tarpath] = infoes
self.local_data.tar2object[tarpath] = object
return self.local_data.tar2object[tarpath].extractfile(
self.local_data.tar2info[tarpath][filename])
else:
return open(file, 'r')

Expand Down

0 comments on commit 9538238

Please sign in to comment.