Closed jmren168 closed 10 months ago
Following a related issue Method 1 in stackoverflow (https://stackoverflow.com/questions/72766345/attributeerror-cant-pickle-local-object-in-multiprocessing), I modified audiodatasets.py as follows, and it works for me.
from torch.utils.data import Dataset
import torch
import numpy as np
# roll waveform (over time)
def roll_func(b):
shift_range=10000
axis=1
x = b[0]
others = b[1:]
x = torch.as_tensor(x)
sf = None
if sf is None:
sf = int(np.random.random_integers(-shift_range, shift_range))
return (x.roll(sf, axis), *others)
def get_roll_func(axis=1, shift=None, shift_range=10000):
return roll_func
class PreprocessDataset(Dataset):
"""A base preprocessing dataset representing a preprocessing step of a Dataset preprocessed on the fly.
supporting integer indexing in range from 0 to len(self) exclusive.
"""
def __init__(self, dataset, preprocessor):
self.dataset = dataset
if not callable(preprocessor):
print("preprocessor: ", preprocessor)
raise ValueError('preprocessor should be callable')
self.preprocessor = preprocessor
def __getitem__(self, index):
return self.preprocessor(self.dataset[index])
def __len__(self):
return len(self.dataset)
BTW, it could be better to add wandb.finish() at the end of training/test part such that wandb can upload the results to cloud server. Otherwise, you may need to upload by run the same code again.
Hi, I resolved the issue in audiodatasets.py similar to what you suggested. I used partial(roll_func, axis=axis, shift=shift, shift_range=shift_range)
to allow the arguments to be passed to roll_func
.
Hi,
I'm trying to use mn10_as as a pre-trained model, and want to fine-tune it to fit my collected dataset (3 classes, 50 10-second clips each class, sampling rate: 16KHz).
I prepraed my dataset and made a format like DCASE20, but only filename and scene_label are used. Then I modified ex_dcase20.py to ex_my_dataset.py. Follows point out where I modified, but errors occured, and hope you could give me some hits. Many thanks.
In ex_my_dataset.py,
In datasets/my_dataset.py
sr=16000 resample_rate=sr
Error messages: