Skip to content

Instantly share code, notes, and snippets.

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)
healthy = [
'healthy engine sound',
'Sound of a Healthy Engine',
]
noise = [
'weird engine sound',
'engine buzzing/farting sound',
'car engine noise',
'Engine knocking',
'Engine bad sound',
'Engine Whining Noise',
'engine blown sounds',
'engine tick sound',
'engine Clicking Noise',
@baker.command
def run(batch_size=8, epochs=5, device='cuda'):
train_loader, val_loader = get_data_loaders(batch_size)
model = NoiseClassifier()
model = model.to(device)
model.eval()
optimizer = Adam(model.parameters())
criterion = nn.BCELoss()
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 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),
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')
import os
import numpy as np
import pandas as pd
from sklearn.model_selection import StratifiedKFold
prod_to_cat = pd.read_csv('levchik_folds/prod_to_category.csv')
skf = StratifiedKFold(n_splits=5, shuffle=True, random_state=4242)
split = skf.split(prod_to_cat.drop('category_id', axis=1), prod_to_cat['category_id'])
#include <functional>
#include <boost/mpl/inherit_linearly.hpp>
#include <boost/mpl/inherit.hpp>
#include <boost/mpl/vector.hpp>
template<typename TargetsVector, typename SignatureVector>
struct visit_method;
template<typename TargetType, typename ReturnType, typename ... ArgsTypes>
struct visit_method<TargetType, std::tuple<ReturnType, ArgsTypes ...>> {
#include <iostream>
#include <memory>
#include <vector>
#include "visitor.hpp"
struct foo;
struct bar;
using visitor_t = basic_visitor<std::tuple<foo, bar>, void(int)>;