def __init__(self, basepath, hparams, fold): """Initialize a `Dataset` instance. Args: basepath: path to directory containing dataset npz files. hparams: Hyperparameters object. fold: data subset, one of {train,valid,test}. Raises: ValueError: if requested a temporal resolution shorter then that available in the dataset. """ self.basepath = basepath self.hparams = hparams self.fold = fold if self.shortest_duration != self.hparams.quantization_level: raise ValueError("The data has a temporal resolution of shortest " "duration=%r, requested=%r" % (self.shortest_duration, self.hparams.quantization_level)) # Update the default pitch ranges in hparams to reflect that of dataset. hparams.pitch_ranges = [self.min_pitch, self.max_pitch] hparams.shortest_duration = self.shortest_duration self.encoder = lib_pianoroll.get_pianoroll_encoder_decoder(hparams) data_path = os.path.join(tf.resource_loader.get_data_files_path(), self.basepath, "%s.npz" % self.name) print("Loading data from", data_path) with tf.gfile.Open(data_path, "r") as p: self.data = np.load(p)[fold]
def __init__(self, basepath, hparams, fold): """Initialize a `Dataset` instance. Args: basepath: path to directory containing dataset npz files. hparams: Hyperparameters object. fold: data subset, one of {train,valid,test}. Raises: ValueError: if requested a temporal resolution shorter then that available in the dataset. """ self.basepath = basepath self.hparams = hparams self.fold = fold if self.shortest_duration != self.hparams.quantization_level: raise ValueError( "The data has a temporal resolution of shortest " "duration=%r, requested=%r" % (self.shortest_duration, self.hparams.quantization_level)) # Update the default pitch ranges in hparams to reflect that of dataset. hparams.pitch_ranges = [self.min_pitch, self.max_pitch] hparams.shortest_duration = self.shortest_duration self.encoder = lib_pianoroll.get_pianoroll_encoder_decoder(hparams) data_path = os.path.join(tf.resource_loader.get_data_files_path(), self.basepath, "%s.npz" % self.name) print("Loading data from", data_path) with tf.gfile.Open(data_path, "rb") as p: self.data = np.load(p, allow_pickle=True, encoding="latin1")[fold]
def __init__(self, wmodel, strategy_name="complete_midi"): self.wmodel = wmodel self.hparams = self.wmodel.hparams self.decoder = lib_pianoroll.get_pianoroll_encoder_decoder(self.hparams) self.logger = lib_logging.Logger() # Instantiates generation strategy. self.strategy_name = strategy_name self.strategy = BaseStrategy.make(self.strategy_name, self.wmodel, self.logger, self.decoder) self._pianorolls = None self._time_taken = None
def __init__(self, checkpoint_path): """Initializes Generator with a wrapped model and strategy name. Args: checkpoint_path: A string that gives the full path to the folder that holds the checkpoint. """ self.sampler = lib_tfsampling.CoconetSampleGraph(checkpoint_path) self.hparams = self.sampler.hparams self.endecoder = lib_pianoroll.get_pianoroll_encoder_decoder(self.hparams) self._time_taken = None self._pianorolls = None
def __init__(self, wmodel, strategy_name="complete_midi"): """Initializes Generator with a wrapped model and strategy name. Args: wmodel: A lib_tfutil.WrappedModel loaded from a model checkpoint. strategy_name: A string specifying the key of the default strategy. """ self.wmodel = wmodel self.hparams = self.wmodel.hparams self.decoder = lib_pianoroll.get_pianoroll_encoder_decoder(self.hparams) self.logger = lib_logging.Logger() # Instantiates generation strategy. self.strategy_name = strategy_name self.strategy = BaseStrategy.make(self.strategy_name, self.wmodel, self.logger, self.decoder) self._pianorolls = None self._time_taken = None