【发布时间】:2020-08-28 18:54:27
【问题描述】:
在下面的代码中,基于我使用py2store 找到的示例,我使用with_key_filt 制作了两个 dacc(一个带有训练数据,另一个带有测试数据)。我确实得到了一个过滤的annots 商店,但wfs 商店没有被过滤。
我做错了什么?
from py2store import cached_keys
class Dacc:
"""Waveform and annotation data access"""
def __init__(self, wfs, annots, annot_to_tag=lambda x: x['tag']):
self.wfs = wfs # waveform store (keys: filepaths, values: numpy arrays)
self.annots = annots # annotation store (keys: filepaths, values: dicts or pandas series)
self.annot_to_tag = annot_to_tag # function to compute a tag from an annotation item
@classmethod
def with_key_filt(cls, key_filt, wfs, annots, annot_to_tag, chunker):
"""
Make an instance of the dacc class where the data is filtered out.
You could also filter out externaly, but this can be convenient
"""
filtered_annots = cached_keys(annots, keys_cache=key_filt)
return cls(wfs, filtered_annots, annot_to_tag)
def wf_tag_gen(self):
"""Generator of (wf, tag) tuples"""
for k in self.annots:
try:
wf = self.wfs[k]
annot = self.annots[k]
yield wf, self.annot_to_tag(annot)
except KeyError:
pass
【问题讨论】: