Esempio n. 1
0
  def run(self, shape):
    init_sampler = self.make_sampler("bach", temperature=FLAGS.temperature)
    pianorolls, masks = self.blank_slate(shape)
    pianorolls = init_sampler(pianorolls, masks)

    masks = lib_sampling.HarmonizationMasker()(shape)

    gibbs = self.make_sampler(
        "gibbs",
        masker=lib_sampling.BernoulliMasker(),
        sampler=self.make_sampler("independent", temperature=FLAGS.temperature),
        schedule=lib_sampling.YaoSchedule())

    with self.logger.section("context"):
      context = np.array([
          lib_mask.apply_mask(pianoroll, mask)
          for pianoroll, mask in zip(pianorolls, masks)
      ])
      self.logger.log(pianorolls=context, masks=masks, predictions=context)
    pianorolls = gibbs(pianorolls, masks)
    with self.logger.section("result"):
      self.logger.log(
          pianorolls=pianorolls, masks=masks, predictions=pianorolls)

    return pianorolls
Esempio n. 2
0
    def run(self, tuple_in):
        shape, midi_in = tuple_in
        pianorolls = self.decoder.encode_midi_to_pianoroll(midi_in, shape)
        # fill in the silences
        masks = lib_sampling.CompletionMasker()(pianorolls)
        gibbs = self.make_sampler("gibbs",
                                  masker=lib_sampling.BernoulliMasker(),
                                  sampler=self.make_sampler(
                                      "independent",
                                      temperature=FLAGS.temperature),
                                  schedule=lib_sampling.YaoSchedule())

        with self.logger.section("context"):
            context = np.array([
                lib_mask.apply_mask(pianoroll, mask)
                for pianoroll, mask in zip(pianorolls, masks)
            ])
            self.logger.log(pianorolls=context,
                            masks=masks,
                            predictions=context)
        pianorolls = gibbs(pianorolls, masks)
        with self.logger.section("result"):
            self.logger.log(pianorolls=pianorolls,
                            masks=masks,
                            predictions=pianorolls)
        return pianorolls
Esempio n. 3
0
    def run(self, shape):
        init_sampler = self.make_sampler("bach", temperature=FLAGS.temperature)
        pianorolls, masks = self.blank_slate(shape)
        pianorolls = init_sampler(pianorolls, masks)

        masks = lib_sampling.HarmonizationMasker()(shape)

        gibbs = self.make_sampler("gibbs",
                                  masker=lib_sampling.BernoulliMasker(),
                                  sampler=self.make_sampler(
                                      "independent",
                                      temperature=FLAGS.temperature),
                                  schedule=lib_sampling.YaoSchedule())

        with self.logger.section("context"):
            context = np.array([
                lib_mask.apply_mask(pianoroll, mask)
                for pianoroll, mask in zip(pianorolls, masks)
            ])
            self.logger.log(pianorolls=context,
                            masks=masks,
                            predictions=context)
        pianorolls = gibbs(pianorolls, masks)
        with self.logger.section("result"):
            self.logger.log(pianorolls=pianorolls,
                            masks=masks,
                            predictions=pianorolls)

        return pianorolls
Esempio n. 4
0
    def run(self, shape):
        init_sampler = self.make_sampler("bach", temperature=FLAGS.temperature)
        pianorolls, masks = self.blank_slate(shape)
        pianorolls = init_sampler(pianorolls, masks)

        sampler = self.make_sampler("gibbs",
                                    masker=lib_sampling.BernoulliMasker(),
                                    sampler=self.make_sampler(
                                        "independent",
                                        temperature=FLAGS.temperature),
                                    schedule=lib_sampling.YaoSchedule())

        for i in range(shape[-1]):
            masks = lib_sampling.InstrumentMasker(instrument=i)(shape)
            with self.logger.section("context"):
                context = np.array([
                    lib_mask.apply_mask(pianoroll, mask)
                    for pianoroll, mask in zip(pianorolls, masks)
                ])
                self.logger.log(pianorolls=context,
                                masks=masks,
                                predictions=context)
            pianorolls = sampler(pianorolls, masks)

        return pianorolls
Esempio n. 5
0
    def run(self, tuple_in):
        try:
            shape, midi_in = tuple_in
            mroll = self.load_midi_melody(midi_in)
        except:
            shape = tuple_in
            mroll = self.load_midi_melody(None)
        pianorolls = self.make_pianoroll_from_melody_roll(mroll, shape)
        masks = lib_sampling.HarmonizationMasker()(pianorolls.shape)
        gibbs = self.make_sampler("gibbs",
                                  masker=lib_sampling.BernoulliMasker(),
                                  sampler=self.make_sampler(
                                      "independent",
                                      temperature=FLAGS.temperature),
                                  schedule=lib_sampling.YaoSchedule())

        with self.logger.section("context"):
            context = np.array([
                lib_mask.apply_mask(pianoroll, mask)
                for pianoroll, mask in zip(pianorolls, masks)
            ])
            self.logger.log(pianorolls=context,
                            masks=masks,
                            predictions=context)
        pianorolls = gibbs(pianorolls, masks)

        return pianorolls
Esempio n. 6
0
  def run(self, pianorolls):
    # fill in the silences
    masks = lib_sampling.CompletionMasker()(pianorolls)
    gibbs = self.make_sampler(
        "gibbs",
        masker=lib_sampling.BernoulliMasker(),
        sampler=self.make_sampler("independent", temperature=FLAGS.temperature),
        schedule=lib_sampling.YaoSchedule())

    with self.logger.section("context"):
      context = np.array([
          lib_mask.apply_mask(pianoroll, mask)
          for pianoroll, mask in zip(pianorolls, masks)
      ])
      self.logger.log(pianorolls=context, masks=masks, predictions=context)
    pianorolls = gibbs(pianorolls, masks)
    with self.logger.section("result"):
      self.logger.log(
          pianorolls=pianorolls, masks=masks, predictions=pianorolls)
    return pianorolls
Esempio n. 7
0
  def run(self, tuple_in):
    shape, midi_in = tuple_in
    mroll = self.load_midi_melody(midi_in)
    pianorolls = self.make_pianoroll_from_melody_roll(mroll, shape)
    masks = lib_sampling.HarmonizationMasker()(pianorolls.shape)
    gibbs = self.make_sampler(
        "gibbs",
        masker=lib_sampling.BernoulliMasker(),
        sampler=self.make_sampler("independent", temperature=FLAGS.temperature),
        schedule=lib_sampling.YaoSchedule())

    with self.logger.section("context"):
      context = np.array([
          lib_mask.apply_mask(pianoroll, mask)
          for pianoroll, mask in zip(pianorolls, masks)
      ])
      self.logger.log(pianorolls=context, masks=masks, predictions=context)
    pianorolls = gibbs(pianorolls, masks)

    return pianorolls
  def _run(self, pianorolls, masks=1.):
    if not np.all(masks):
      raise NotImplementedError()
    masks = np.ones_like(pianorolls)
    with self.logger.section("sequence"):
      while pianorolls.shape[1] < self.desired_length:
        # upsample by zero-order hold and mask out every second time step
        pianorolls = np.repeat(pianorolls, 2, axis=1)
        masks = np.repeat(masks, 2, axis=1)
        masks[:, 1::2] = 1

        with self.logger.section("context"):
          context = np.array([
              lib_mask.apply_mask(pianoroll, mask)
              for pianoroll, mask in zip(pianorolls, masks)
          ])
          self.logger.log(pianorolls=context, masks=masks, predictions=context)

        pianorolls = self.sampler(pianorolls, masks)
        masks = np.zeros_like(masks)
    return pianorolls
Esempio n. 9
0
  def _run(self, pianorolls, masks=1.):
    if not np.all(masks):
      raise NotImplementedError()
    masks = np.ones_like(pianorolls)
    with self.logger.section("sequence"):
      while pianorolls.shape[1] < self.desired_length:
        # upsample by zero-order hold and mask out every second time step
        pianorolls = np.repeat(pianorolls, 2, axis=1)
        masks = np.repeat(masks, 2, axis=1)
        masks[:, 1::2] = 1

        with self.logger.section("context"):
          context = np.array([
              lib_mask.apply_mask(pianoroll, mask)
              for pianoroll, mask in zip(pianorolls, masks)
          ])
          self.logger.log(pianorolls=context, masks=masks, predictions=context)

        pianorolls = self.sampler(pianorolls, masks)
        masks = np.zeros_like(masks)
    return pianorolls
Esempio n. 10
0
  def run(self, shape):
    init_sampler = self.make_sampler("bach", temperature=FLAGS.temperature)
    pianorolls, masks = self.blank_slate(shape)
    pianorolls = init_sampler(pianorolls, masks)

    sampler = self.make_sampler(
        "gibbs",
        masker=lib_sampling.BernoulliMasker(),
        sampler=self.make_sampler("independent", temperature=FLAGS.temperature),
        schedule=lib_sampling.YaoSchedule())

    for i in range(shape[-1]):
      masks = lib_sampling.InstrumentMasker(instrument=i)(shape)
      with self.logger.section("context"):
        context = np.array([
            lib_mask.apply_mask(pianoroll, mask)
            for pianoroll, mask in zip(pianorolls, masks)
        ])
        self.logger.log(pianorolls=context, masks=masks, predictions=context)
      pianorolls = sampler(pianorolls, masks)

    return pianorolls