Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -2,10 +2,12 @@ import numpy as np
|
|
| 2 |
from scipy.io.wavfile import read
|
| 3 |
import torch
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def get_mask_from_lengths(lengths):
|
| 7 |
max_len = torch.max(lengths).item()
|
| 8 |
-
ids = torch.arange(0, max_len, out=torch.cuda.LongTensor(max_len))
|
| 9 |
mask = (ids < lengths.unsqueeze(1)).bool()
|
| 10 |
return mask
|
| 11 |
|
|
|
|
| 2 |
from scipy.io.wavfile import read
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
use_cuda = torch.cuda.is_available()
|
| 6 |
+
device = torch.device('cuda' if use_cuda else 'cpu')
|
| 7 |
|
| 8 |
def get_mask_from_lengths(lengths):
|
| 9 |
max_len = torch.max(lengths).item()
|
| 10 |
+
ids = torch.arange(0, max_len, out=torch.cuda.LongTensor(max_len) if use_cuda else torch.LongTensor(max_len))
|
| 11 |
mask = (ids < lengths.unsqueeze(1)).bool()
|
| 12 |
return mask
|
| 13 |
|