harbor run -t openthoughts/tasktrove-mix-h8-original-tests-v2-mix-h8-original-0470harbor download openthoughts/tasktrove-mix-h8-original-tests-v2-mix-h8-original-0470solution file
from vocsep.data import StrutturaDataset
from joblib import Parallel, delayed
from tqdm import tqdm
import partitura
import os
from vocsep.utils import hetero_graph_from_note_array, select_features, HeteroScoreGraph, load_score_hgraph
from vocsep.models.core import positional_encoding
import torch
import partitura as pt
import gc
import numpy as np
from numpy.lib.recfunctions import structured_to_unstructured
class GraphVoiceSeparationDataset(StrutturaDataset):
r"""Parent class for Graph Voice Sepration Datasets.
Parameters
-----------
dataset_base : StrutturaDataset
The Base Dataset.
raw_dir : str
Raw file directory to download/contains the input data directory.
Default: ~/.struttura/
force_reload : bool
Whether to reload the dataset. Default: False
verbose : bool
Whether to print out progress information. Default: True.
"""
def __init__(
self, dataset_base, is_pyg=False, raw_dir=None, force_reload=False, verbose=True, nprocs=4, pot_edges_dist=2, include_measures=False
):
self.dataset_base = dataset_base
self.dataset_base.process()
if verbose:
print("Loaded {} Successfully, now processing...".format(dataset_base.name))
self.graphs = list()
self.n_jobs = nprocs
self.dropped_notes = 0
self.pot_edges_max_dist = pot_edges_dist
self.is_pyg = is_pyg
self._force_reload = force_reload
self.include_measures = include_measures
if self.is_pyg:
name = self.dataset_base.name.split("Dataset")[0] + "PGGraphVoiceSeparationDataset"
else:
name = self.dataset_base.name.split("Dataset")[0] + "GraphVoiceSeparationDataset"
print("pot_edges_max_dist", self.pot_edges_max_dist)
super(GraphVoiceSeparationDataset, self).__init__(
name=name,
raw_dir=raw_dir,
force_reload=force_reload,
verbose=verbose,
)
def process(self):
if not os.path.exists(self.save_path):
os.makedirs(self.save_path)
Parallel(n_jobs=self.n_jobs)(
delayed(self._process_score)(score, collection)
for score, collection in tqdm(
zip(self.dataset_base.scores, self.dataset_base.collections)
)
)
self.load()
def _process_score(self, score_fn, collection):
if self._force_reload or \
not (os.path.exists(
os.path.join(
self.save_path, os.path.splitext(os.path.basename(score_fn))[0]
)) or \
os.path.exists(
os.path.join(
self.save_path, os.path.splitext(os.path.basename(score_fn))[0] + ".pt"
))):
try:
score = partitura.load_score(score_fn)
if len(score.parts) ==0:
print("Something is wrong with the score", score_fn)
return
except:
print("Something is wrong with the score", score_fn)
return
note_array = score.note_array(
include_time_signature=True,
include_grace_notes=True,
include_staff=True,
)
note_array, num_dropped = preprocess_na_to_monophonic(note_array, score_fn)
self.dropped_notes += num_dropped
# Compute the truth edges
truth_edges = get_mcma_truth_edges(note_array).numpy()
note_features = select_features(note_array, "voice")
nodes, edges, pot_edges = hetero_graph_from_note_array(note_array, pot_edge_dist=self.pot_edges_max_dist)
hg = HeteroScoreGraph(
note_features,
edges,
name=os.path.splitext(os.path.basename(score_fn))[0],
labels=truth_edges,
note_array=note_array,
)
if self.include_measures:
measures = score[0].measures
hg._add_beat_nodes()
hg.
Complete the code above, taking into account the cross-file context provided. Your solution must work correctly with the related files in the project.
Place your complete solution in /app/solution.py