Title
import pandas as pd
import pkg_resources
def placeholder(x):
raise pkg_resources.DistributionNotFound
pkg_resources.get_distribution = placeholder
import fastai
import fastaudio
from fastai.vision.all import *
from fastaudio.core.all import *
from fastaudio.augment.all import *
data = pd.read_csv("comma labels.csv", index_col='path')
data
data.loc['1すくい_一掬い.yomi000120BB_01C8.mp3']
data.loc['出し抜く.yomi0004BDF8_06F2.mp3']
data.loc['ある.yomi000142BB_0596.mp3']
from google.colab import drive
drive.mount('/content/drive')
path = Path('/content/drive/MyDrive')
path = path / '1000sample'
at = AudioTensor.create(path.ls()[0])
at.show()
cfg = AudioConfig.Voice()
aud2spec = AudioToSpec.from_cfg(cfg)
aud2spec(at).show()
crop2s = ResizeSignal(2000)
crop2s(at).show()
pipe = Pipeline([AudioTensor.create, crop2s, aud2spec])
for i in range(5):
pipe(path.ls()[i]).show()
data.loc['ある.yomi000142BB_0596.mp3']['pattern']
data.reset_index()[data.reset_index().duplicated(keep=False)].to_csv('duplicates.csv')
data[data.index.duplicated(keep=False)].to_csv('path_dup.csv')
data.duplicated().sum()
data.reset_index()
data = data.reset_index()
removing complete duplicates
data = data[-data.duplicated()]
data.to_csv('labels complete duplicates removed.csv')
duplicate labels
data.duplicated(subset=['path'], keep=False).sum()
data = data[-data.duplicated(subset=['path'], keep=False)]
data.to_csv('labels_no_duplicates.csv')
sr = data[data.path == '捜す.yomi00072507_0088.mp3']['pattern'].values[0]
sr.values[0]
item_tfms = [ResizeSignal(1000), aud2spec]
def get_label(fn):
return data[data.path == fn]['pattern'].values[0]
audpitch = DataBlock(blocks=(AudioBlock, CategoryBlock),
get_items=get_audio_files,
splitter=RandomSplitter(),
item_tfms = [crop2s, aud2spec],
get_y=using_attr(get_label, 'name'))
for fn in path.ls():
print(fn)
try:
get_label(fn.name)
except: fn.unlink()
for fn in path.ls():
print(fn)
print(get_label(fn.name))
learn = Learner(dls, xresnet18(), CrossEntropyLossFlat(), metrics=accuracy)
n_c = dls.one_batch()[0].shape[1]; n_c
def alter_learner(learn, n_channels=1):
"Adjust a `Learner`'s model to accept `1` channel"
layer = learn.model[0][0]
layer.in_channels=n_channels
layer.weight = nn.Parameter(layer.weight[:,1,:,:].unsqueeze(1))
learn.model[0][0] = layer
alter_learner(learn, n_c)
learn.lr_find()
learn.fit_one_cycle(5, 1e-3)
learn.fit_one_cycle(5, 1e-4)
train = dls.train
m = learn.model
y = dls[0]
names = [fn.name for fn in path.ls()]
datasample = data[data.path.isin(names)]
datasample.groupby('pattern').count()
data.groupby('pattern').count()