Skip to content

Instantly share code, notes, and snippets.

def squeeze_collate(batch):
batch_x, batch_y = list(zip(*batch))
batch_y = np.array(batch_y, dtype=np.float32)
batch_y = torch.from_numpy(batch_y)
batch_x = torch.cat(batch_x, dim=0)
return batch_x, batch_y
class NoiseDataSet(Dataset):
def __init__(self, X, y):
super().__init__()
assert(len(X) == len(y))
self.X = X
self.y = y
def __len__(self):
return len(self.X)
import pandas as pd
from pathlib import Path
def get_ytid(x):
name = Path(x).name
ytid = name[: name.rfind('_')]
return ytid
maybe_noise = pd.read_csv('Engine+noises_2020-08-24T19_34_31.csv')
maybe_healthy = pd.read_csv('Engine+healthy_2_2020-08-24T22_17_40.csv')
class NoiseClassifier(nn.Module):
def __init__(self):
super().__init__()
self.vgg = vggish(preprocess=False, postprocess=False)
self.vgg.embeddings = nn.Sequential(
nn.Linear(512 * 4 * 6 * WINDOW_MULTIPLIER, 256),
nn.ReLU(True),
nn.Linear(256, 256),
nn.ReLU(True),
nn.Linear(256, 256),
from itertools import imap, ifilter
class map:
def __init__(self, callable):
self.callable = callable
def __ror__(self, *iterable):
return imap(self.callable, *iterable)
class filter: