<jupyter_start><jupyter_text>From the start<jupyter_code>def files2mask(files):
    tfms = [AudioMono.create, Resample(22050), Clip(5)]
    audios = [compose_tfms(f, tfms) for f in files]
    aud2mask = Maskify(MaskBinary)
    mixed_spec, masks = aud2mask(audios)
    return [mixed_spec, masks[0]]
class POIMesher:
    def __init__(self, poi):
        self.poi = poi

    def get_poi_files(self, path):
        return get_audio_files(path, folders=f"{self.poi}")

    def get_non_poi_files(self, path):
        files = get_audio_files(path)
        poi_path = path/str(self.poi)
        return [file for file in files if poi_path not in list(file.parents)]

    def __call__(self, path):
        rand_poi = []
        poi_files = self.get_poi_files(path)
        non_poi_files = self.get_non_poi_files(path)
        for x in range(len(non_poi_files)):
            rand_poi.append(random.choice(poi_files))
        return list(map(list,zip(rand_poi, non_poi_files)))
class SpecMaskDataset(torch.utils.data.Dataset):
    def __init__(self, files):
        self.files = files
        self.tensorify = ToTensor()
        self.trim = Unet_Trimmer(16)
        
    def __getitem__(self, i):
        spec, mask = files2mask(self.files[i])
        spec, mask = self.tensorify(spec), self.tensorify(mask)
        return self.trim(spec[:1]), self.trim(mask)
    
    def __len__(self): return len(self.files)
poi = "911"
fn = Path("/home/cerberus/Music/LibriSpeech/train-clean-100/")

files = POIMesher(poi)(fn)
train_ds = SpecMaskDataset(files)

dls = DataLoaders.from_dsets(train_ds, train_ds, bs=2).cuda()<jupyter_output><empty_output><jupyter_text>Train<jupyter_code>model = U_Net(img_ch=1, output_ch=1).cuda()
learn = Learner(dls, model, loss_func=MSELossFlat())
learn.load("TrainBinary4t")
def listen2spec(spec):
    zeros = torch.zeros_like(spec)
    spec = torch.cat((spec, zeros),0)
    cplx_spec = real2complex(spec)
    specbase = SpecBase(cplx_spec, 22050)
    
    return Spectify().decode(specbase)

def createMask(mask):
    return MaskBinary(mask.numpy(), 0.25)
i = 0
dls.dataset[i][0].shape
listen2spec(dls.dataset[i][0].cpu())
mask = learn.predict([dls.dataset[i][0]])[0].cpu()
mask = createMask(mask)
listen2spec(dls.dataset[i][0].cpu()*mask)
dls.files[i][0]
target = dls.dataset[i][1].T.cpu()
target = createMask(target[None,:,:])
listen2spec(dls.dataset[i][0].cpu()*target)
MaskBinary(target.data[0]).show()
MaskBinary(mask.data[0],0.22).show_binary()
MaskBinary(mask.data[0]).show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1493660855784469, 'fraction_numerical': 0.020998415213946117, 'mean_word_length': 4.216942148760331, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '76500', 'license': 'Apache-2.0', 'n_tokens_mistral': 980, 'n_tokens_neox': 965, 'n_words': 154, 'path': 'nbdev/13_Results.ipynb', 'repo_name': 'holyfiddlex/Speech-Separation', 'size': '2524'}