用相同的键集过滤两个 py2store 商店。

问题描述 投票:0回答:1

在下面的代码中,基于我找到的一个例子,使用了 py2store,我用 with_key_filt 来制作两个daccs(一个是训练数据,另一个是测试数据)。我确实得到了一个过滤后的 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
python key store filtered
1个回答
0
投票

似乎 with_key_filt 似乎是为了过滤 annots的种子,而它本身也被用来做种子。wg_tag_gen 生成器(可能还有其他你没有发布的生成器)。因此,它确实可以过滤一切。

但是我同意你的期望,即 wfs 也应该被过滤。要实现这一点,您只需要添加一行来过滤 wfs.

class TheDaccYouWant(Dacc):
    @classmethod
    def with_key_filt(cls, key_filt, wfs, annots, annot_to_tag, chunker):
        filtered_annots = cached_keys(annots, keys_cache=key_filt)
        wfs = cached_keys(wfs, keys_cache=key_filt)  # here's what was added
        return cls(wfs, filtered_annots, annot_to_tag, chunker)
© www.soinside.com 2019 - 2024. All rights reserved.