我试图读取MIDI
文件,并将注释添加到具有多处理pool.map()
的列表中,因为有数千个MIDI
文件。我用python类开发这个项目,如下所示。在
class NoteProcessor:
def __init__(self):
self.note_sequences = list()
self.notes = set()
.....
def process_midi(self, df):
PATH_ROOT = 'clean_midi/'
for row in tqdm(df.itertuples(), total=df.shape[0]):
notes = set()
path = PATH_ROOT + row.path + '/' + row.song + '.mid'
try:
midi = converter.parse(path)
elements = instrument.partitionByInstrument(midi)
encoded_notes = self.arrange_notes(elements)
if len(encoded_notes) != 0:
#self.note_sequences should be shared array
self.note_sequences.append(encoded_notes)
else:
self.df = self.df.drop(row[0])
except Exception as e:
self.df = self.df.drop(row[0])
logging.error("MIDI Error " + str(e))
主脚本:
^{pr2}$由于note_sequences
不是共享数组,所以它没有用。我研究了python多处理数组,找到了一些答案answer1answer2。但是我把共享数组作为类属性混淆了,当我将self.note_sequences = list()
替换为self.note_sequences = multiprocessing.Array(c_char_p,df.shape[0])
时,会出现{
目前没有回答
相关问题 更多 >
编程相关推荐