def buildRecurrence(cliques, times): logger.debug(f"build recurrence") cliques = deepcopy(cliques) size = len(times) - 1 mergedCliquesList = [ smoothCliques( mergeAdjacentCliques(cliques, dis=dis, dblock=dblock), size, kernel_size=kernelSize, ) for dis in DELTA_DIS_RANGE for kernelSize in SMOOTH_KERNEL_SIZE_RANGE for dblock in [0, 1, 2] ] # mclen = len(mergedCliquesList) # for i in range(1): # mergedCliquesList.extend( # [ # smoothCliques(mergeAdjacentCliques(cs), size) # for cs in mergedCliquesList[-mclen:] # ] # ) errors = [error(cliques, ncs, size, times) for ncs in mergedCliquesList] indices = np.argsort(errors) for i in indices: newCliques = mergedCliquesList[i] predicate = all( [ len(newCliques) >= MIN_STRUCTURE_COUNT, ] ) if predicate: return newCliques logger.warn(f"seqrecur failed, cliqueLengths={[len(x) for x in mergedCliquesList]}") return mergedCliquesList[0]
def load(self, dirname): dumpFile = os.path.join(dirname, f"{self.datasetName}.pkl") try: with open(dumpFile, "rb") as f: dname, self.algoNames, self.metricsList, self.titlesList = pickle.load( f) if dname != self.datasetName: logger.warn( f"old name:<{dname}> != new name:<{self.datasetName}>") logger.info(f"saver object loaded from '{dumpFile}'") except FileNotFoundError: logger.warn( f"saver object file '{dumpFile}' not found, set to empty") return self
def __init__(self, accompDir=DATASET_BASE_DIRS["RWC_accomp"], transform=None): super(RWC_Popular_Dataset_accomp, self).__init__(transform=transform) convertFileName(accompDir) self.accompDir = accompDir newPathPairs = [] for pair in self.pathPairs: title = pair.title gt = pair.GT accomp = os.path.join(accompDir, title, "accompaniment.wav") wav = os.path.join(accompDir, title, f"{title}.wav") if os.path.exists(accomp): os.rename(accomp, wav) logger.warn(f"rename {accomp} -> {wav}") newPathPairs.append(StructDataPathPair(title, wav, gt)) self.pathPairs = newPathPairs
def __init__(self, baseDir=DATASET_BASE_DIRS["CCM"], transform=None): super(CCM_Dataset, self).__init__(baseDir, transform) # chorus/<title>.txt # audio/<title>.mp3 for filename in sorted(os.listdir(os.path.join(baseDir, "audio"))): title = os.path.splitext(filename)[0] assert os.path.splitext(filename)[1] in [ ".mp3", ".flac", ], f"{filename}: wrong extension" wavPath = os.path.join(baseDir, "audio", filename) GTPath = os.path.join(baseDir, "chorus", title + ".txt") NFDTitle = unicodedata.normalize("NFD", title) if NFDTitle != title: logger.warn( f"filename={wavPath} is not in unicode NFD form, expected={NFDTitle}" ) self.pathPairs.append(StructDataPathPair(title, wavPath, GTPath))
def __init__(self, baseDir=DATASET_BASE_DIRS["Huawei"], transform=None): super(Huawei_Dataset, self).__init__(baseDir, transform) # struct/<title>.txt # audio/<title>.mp3 for filename in sorted(os.listdir(os.path.join(baseDir, "audio"))): title = os.path.splitext(filename)[0] assert (os.path.splitext(filename)[1] == ".mp3" ), f"{filename}: wrong extension" wavPath = os.path.join(baseDir, "audio", filename) GTPath = os.path.join(baseDir, "struct", title + ".txt") NFDTitle = unicodedata.normalize("NFD", title) if NFDTitle != title: logger.warn( f"filename={wavPath} is not in unicode NFD form, expected={NFDTitle}" ) _, labels = self.loadGT(GTPath) if "chorus" in labels: self.pathPairs.append( StructDataPathPair(title, wavPath, GTPath)) else: logger.warn(f"no chorus section, file={GTPath}")
def _addPairFromPaths(self, discPaths, X): def listDisc(discPath): # ensure the wav files are well-ordered, or GTfile will mismatch names = sorted(os.listdir(discPath)) return [os.path.join(discPath, n) for n in names] for num, wavPath in enumerate(chain(*map(listDisc, discPaths))): _, tail = os.path.split(wavPath) assert tail[ -4:] == ".wav", "has non-wave file in the RWC disc folder" title = tail[:-4] GTPath = os.path.join( self.baseDir, f"RWC-MDB-{X}-2001", f"AIST.RWC-MDB-{X}-2001.CHORUS", f"RM-{X}{num+1:03d}.CHORUS.TXT", ) if unicodedata.normalize("NFD", title) != title: logger.warn( f"file={wavPath} titile={title} is not in unicode NFD form" ) self.pathPairs.append(StructDataPathPair(title, wavPath, GTPath))