def transposition(events, controls, offset=0): # events [steps, batch_size, event_dim] # return events, controls events = np.array(events, dtype=np.int64) controls = np.array(controls, dtype=np.float32) event_feat_ranges = EventSeq.feat_ranges() on = event_feat_ranges['note_on'] off = event_feat_ranges['note_off'] if offset > 0: indeces0 = (((on.start <= events) & (events < on.stop - offset)) | ((off.start <= events) & (events < off.stop - offset))) indeces1 = (((on.stop - offset <= events) & (events < on.stop)) | ((off.stop - offset <= events) & (events < off.stop))) events[indeces0] += offset events[indeces1] += offset - 12 elif offset < 0: indeces0 = (((on.start - offset <= events) & (events < on.stop)) | ((off.start - offset <= events) & (events < off.stop))) indeces1 = (((on.start <= events) & (events < on.start - offset)) | ((off.start <= events) & (events < off.start - offset))) events[indeces0] += offset events[indeces1] += offset + 12 assert ((0 <= events) & (events < EventSeq.dim())).all() histr = ControlSeq.feat_ranges()['pitch_histogram'] controls[:, :, histr.start:histr.stop] = np.roll( controls[:, :, histr.start:histr.stop], offset, -1) return events, controls
cnt_dict['index-' + str(index)] = 1 return cnt_arr print(par.vocab_size) data = Data('dataset/processed') # ds = DataSequence('dataset/processed', 10, 2048) sample = data.seq2seq_batch(1000, 100)[0] pprint.pprint(list(sample)) arr = count_dict(par.vocab_size + 3, sample) pprint.pprint(arr) from sequence import EventSeq, Event event_cnt = {'note_on': 0, 'note_off': 0, 'velocity': 0, 'time_shift': 0} for event_index in range(len(arr)): for event_type, feat_range in EventSeq.feat_ranges().items(): if feat_range.start <= event_index < feat_range.stop: print(event_type + ':' + str(arr[event_index]) + ' event cnt: ' + str(event_cnt)) event_cnt[event_type] += arr[event_index] # event_value = event_index - feat_range.start # events.append(Event(event_type, time, event_value)) # if event_type == 'time_shift': # time += EventSeq.time_shift_bins[event_value] # break print(event_cnt) # print(np.max(sample), np.min(sample)) # print([data._get_seq(file).shape for file in data.files])