NikitaSrivatsan commited on
Commit
7b39cbc
1 Parent(s): 8971856

Removed pickling of input files

Browse files
Files changed (1) hide show
  1. data_module.py +24 -31
data_module.py CHANGED
@@ -223,38 +223,31 @@ class AudiostockDataset(Dataset):
223
  return tokens, mask, tweet_text_len
224
 
225
  def read_wav(self, filename):
226
- stem = PurePosixPath(filename).stem
227
- picklefile = f'wt-{self.whole_track}-t-{self.train}-{stem}.pt'
228
- picklepath = f'/trunk/datasets/nsrivats/audiostock_proc/{picklefile}'
229
- if os.path.exists(picklepath):
230
- y = torch.load(picklepath)
231
- else:
232
- # chunk
233
- try:
234
- num_frames = torchaudio.info(filename).num_frames
235
- except:
236
- return None
237
- # make sure it wasn't empty, if so die
238
- if num_frames == 0:
239
- return None
240
- sta = 0
241
- if not self.whole_track:
242
- if self.train:
243
- sta = random.randint(0, num_frames - 441001)
244
- else:
245
- sta = (num_frames - 441001) // 2
246
- num_frames = 441000
247
 
248
- y, sr = torchaudio.load(filename, frame_offset=sta, num_frames=num_frames)
249
- # resample
250
- y = torchaudio.functional.resample(y, sr, 48000)
251
- y = y[:, :441000]
252
- # mono
253
- y = y.mean(dim=0)
254
- # normalize
255
- y = int16_to_float32(float32_to_int16(y))
256
- # save
257
- torch.save(y, picklepath)
258
  return y
259
 
260
  def __getitem__(self, index):
 
223
  return tokens, mask, tweet_text_len
224
 
225
  def read_wav(self, filename):
226
+ # pickling functionality removed since it shouldn't be necessary
227
+ # chunk
228
+ try:
229
+ num_frames = torchaudio.info(filename).num_frames
230
+ except:
231
+ return None
232
+ # make sure it wasn't empty, if so die
233
+ if num_frames == 0:
234
+ return None
235
+ sta = 0
236
+ if not self.whole_track:
237
+ if self.train:
238
+ sta = random.randint(0, num_frames - 441001)
239
+ else:
240
+ sta = (num_frames - 441001) // 2
241
+ num_frames = 441000
 
 
 
 
 
242
 
243
+ y, sr = torchaudio.load(filename, frame_offset=sta, num_frames=num_frames)
244
+ # resample
245
+ y = torchaudio.functional.resample(y, sr, 48000)
246
+ y = y[:, :441000]
247
+ # mono
248
+ y = y.mean(dim=0)
249
+ # normalize
250
+ y = int16_to_float32(float32_to_int16(y))
 
 
251
  return y
252
 
253
  def __getitem__(self, index):