Issue
I was following this tutorial
However, when I ran the code under "Training", it gave me the following error.
RuntimeError: Error loading audio file: failed to open file /Users/leonardchoo/Desktop/dev_m1/audio_cnn/UrbanSound8K/fold10/30344-3-0-1.wav
The problem is, each time I run this, the error occurs at a different file.
error at...
# 1st run
fold2/106015-5-0-7.wav
# 2nd run
fold2/76086-4-0-22.wav
# 3rd run
fold9/14111-4-0-6.wav
I couldn't find anything like this on the web. I am genuinely confused by this.
My entire code can be found in this COLAB Notebook The dataset is from here
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-14-2d83571e984b> in <module>
59
60 num_epochs = 2 # Just for demo, adjust this higher.
---> 61 training(myModel, train_dl, num_epochs)
<ipython-input-14-2d83571e984b> in training(model, train_dl, num_epochs)
19
20 # Repeat for each batch in the training set
---> 21 for i, data in enumerate(train_dl):
22 # Get the input features and target labels, and put them on the GPU
23 inputs, labels = data[0].to(device), data[1].to(device)
/usr/local/lib/python3.9/site-packages/torch/utils/data/dataloader.py in __next__(self)
519 if self._sampler_iter is None:
520 self._reset()
--> 521 data = self._next_data()
522 self._num_yielded += 1
523 if self._dataset_kind == _DatasetKind.Iterable and \
/usr/local/lib/python3.9/site-packages/torch/utils/data/dataloader.py in _next_data(self)
559 def _next_data(self):
560 index = self._next_index() # may raise StopIteration
--> 561 data = self._dataset_fetcher.fetch(index) # may raise StopIteration
562 if self._pin_memory:
563 data = _utils.pin_memory.pin_memory(data)
/usr/local/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py in fetch(self, possibly_batched_index)
42 def fetch(self, possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]
/usr/local/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py in <listcomp>(.0)
42 def fetch(self, possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]
/usr/local/lib/python3.9/site-packages/torch/utils/data/dataset.py in __getitem__(self, idx)
309
310 def __getitem__(self, idx):
--> 311 return self.dataset[self.indices[idx]]
312
313 def __len__(self):
<ipython-input-8-8743d21efeae> in __getitem__(self, idx)
32 class_id = self.df.loc[idx, 'classID']
33
---> 34 aud = AudioUtil.open(audio_file)
35 # Some sounds have a higher sample rate, or fewer channels compared to the
36 # majority. So make all sounds have the same number of channels and same
<ipython-input-7-f64618dd0374> in open(audio_file)
13 @staticmethod
14 def open(audio_file):
---> 15 sig, sr = torchaudio.load(audio_file)
16 return (sig, sr)
17
/usr/local/lib/python3.9/site-packages/torchaudio/backend/sox_io_backend.py in load(filepath, frame_offset, num_frames, normalize, channels_first, format)
150 filepath, frame_offset, num_frames, normalize, channels_first, format)
151 filepath = os.fspath(filepath)
--> 152 return torch.ops.torchaudio.sox_io_load_audio_file(
153 filepath, frame_offset, num_frames, normalize, channels_first, format)
154
RuntimeError: Error loading audio file: failed to open file /Users/leonardchoo/Desktop/dev_m1/audio_cnn/UrbanSound8K/fold10/30344-3-0-1.wav
Solution
It was a silly trouble... i was missing /audio
in the path...
I did not realize this was the case because the file it gave me error at always changed.
Answered By - Leonard
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.