本文整理汇总了Python中torch.utils.data.keys方法的典型用法代码示例。如果您正苦于以下问题:Python data.keys方法的具体用法?Python data.keys怎么用?Python data.keys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torch.utils.data
的用法示例。
在下文中一共展示了data.keys方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from torch.utils import data [as 别名]
# 或者: from torch.utils.data import keys [as 别名]
def __init__(self, data, set_type, config):
super().__init__()
self.audio_files = list(data.keys())
self.set_type = set_type
self.audio_labels = list(data.values())
config["bg_noise_files"] = list(filter(lambda x: x.endswith("wav"), config.get("bg_noise_files", [])))
self.bg_noise_audio = [librosa.core.load(file, sr=16000)[0] for file in config["bg_noise_files"]]
self.unknown_prob = config["unknown_prob"]
self.silence_prob = config["silence_prob"]
self.noise_prob = config["noise_prob"]
self.input_length = config["input_length"]
self.timeshift_ms = config["timeshift_ms"]
self._audio_cache = SimpleCache(config["cache_size"])
self._file_cache = SimpleCache(config["cache_size"])
n_unk = len(list(filter(lambda x: x == 1, self.audio_labels)))
self.n_silence = int(self.silence_prob * (len(self.audio_labels) - n_unk))
self.audio_processor = AudioPreprocessor(n_mels=config["n_mels"], n_dct_filters=config["n_dct_filters"], hop_ms=10)
self.audio_preprocess_type = config["audio_preprocess_type"]
示例2: __getitem__
# 需要导入模块: from torch.utils import data [as 别名]
# 或者: from torch.utils.data import keys [as 别名]
def __getitem__(self, key):
data = self.db[key]
for k in data.keys():
data[k] = torch.from_numpy(data[k])
return data
示例3: __setitem__
# 需要导入模块: from torch.utils import data [as 别名]
# 或者: from torch.utils.data import keys [as 别名]
def __setitem__(self, key, value):
if key in self.keys():
super().__setitem__(key, value)
elif self.n_keys < self.limit:
self.n_keys += 1
super().__setitem__(key, value)
return value