Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- Utils/JDC/__init__.py +1 -0
- Utils/JDC/bst.t7 +3 -0
- Utils/JDC/model.py +190 -0
.gitattributes
CHANGED
|
@@ -2331,3 +2331,4 @@ data/wavs/wavs/021_-_NonVerbal_Skills_For_Great_Leaders_3d5ba0fc_part031_02.wav
|
|
| 2331 |
data/wavs/wavs/021_-_NonVerbal_Skills_For_Great_Leaders_3d5ba0fc_part034_02.wav filter=lfs diff=lfs merge=lfs -text
|
| 2332 |
data/wavs/wavs/021_-_NonVerbal_Skills_For_Great_Leaders_3d5ba0fc_part032_02.wav filter=lfs diff=lfs merge=lfs -text
|
| 2333 |
data/wavs/wavs/021_-_NonVerbal_Skills_For_Great_Leaders_3d5ba0fc_part032_01.wav filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 2331 |
data/wavs/wavs/021_-_NonVerbal_Skills_For_Great_Leaders_3d5ba0fc_part034_02.wav filter=lfs diff=lfs merge=lfs -text
|
| 2332 |
data/wavs/wavs/021_-_NonVerbal_Skills_For_Great_Leaders_3d5ba0fc_part032_02.wav filter=lfs diff=lfs merge=lfs -text
|
| 2333 |
data/wavs/wavs/021_-_NonVerbal_Skills_For_Great_Leaders_3d5ba0fc_part032_01.wav filter=lfs diff=lfs merge=lfs -text
|
| 2334 |
+
Utils/JDC/bst.t7 filter=lfs diff=lfs merge=lfs -text
|
Utils/JDC/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
Utils/JDC/bst.t7
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:54dc94364b97e18ac1dfa6287714ed121248cfaac4cfd39d061c6e0a089ef169
|
| 3 |
+
size 21029926
|
Utils/JDC/model.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Implementation of model from:
|
| 3 |
+
Kum et al. - "Joint Detection and Classification of Singing Voice Melody Using
|
| 4 |
+
Convolutional Recurrent Neural Networks" (2019)
|
| 5 |
+
Link: https://www.semanticscholar.org/paper/Joint-Detection-and-Classification-of-Singing-Voice-Kum-Nam/60a2ad4c7db43bace75805054603747fcd062c0d
|
| 6 |
+
"""
|
| 7 |
+
import torch
|
| 8 |
+
from torch import nn
|
| 9 |
+
|
| 10 |
+
class JDCNet(nn.Module):
|
| 11 |
+
"""
|
| 12 |
+
Joint Detection and Classification Network model for singing voice melody.
|
| 13 |
+
"""
|
| 14 |
+
def __init__(self, num_class=722, seq_len=31, leaky_relu_slope=0.01):
|
| 15 |
+
super().__init__()
|
| 16 |
+
self.num_class = num_class
|
| 17 |
+
|
| 18 |
+
# input = (b, 1, 31, 513), b = batch size
|
| 19 |
+
self.conv_block = nn.Sequential(
|
| 20 |
+
nn.Conv2d(in_channels=1, out_channels=64, kernel_size=3, padding=1, bias=False), # out: (b, 64, 31, 513)
|
| 21 |
+
nn.BatchNorm2d(num_features=64),
|
| 22 |
+
nn.LeakyReLU(leaky_relu_slope, inplace=True),
|
| 23 |
+
nn.Conv2d(64, 64, 3, padding=1, bias=False), # (b, 64, 31, 513)
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# res blocks
|
| 27 |
+
self.res_block1 = ResBlock(in_channels=64, out_channels=128) # (b, 128, 31, 128)
|
| 28 |
+
self.res_block2 = ResBlock(in_channels=128, out_channels=192) # (b, 192, 31, 32)
|
| 29 |
+
self.res_block3 = ResBlock(in_channels=192, out_channels=256) # (b, 256, 31, 8)
|
| 30 |
+
|
| 31 |
+
# pool block
|
| 32 |
+
self.pool_block = nn.Sequential(
|
| 33 |
+
nn.BatchNorm2d(num_features=256),
|
| 34 |
+
nn.LeakyReLU(leaky_relu_slope, inplace=True),
|
| 35 |
+
nn.MaxPool2d(kernel_size=(1, 4)), # (b, 256, 31, 2)
|
| 36 |
+
nn.Dropout(p=0.2),
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# maxpool layers (for auxiliary network inputs)
|
| 40 |
+
# in = (b, 128, 31, 513) from conv_block, out = (b, 128, 31, 2)
|
| 41 |
+
self.maxpool1 = nn.MaxPool2d(kernel_size=(1, 40))
|
| 42 |
+
# in = (b, 128, 31, 128) from res_block1, out = (b, 128, 31, 2)
|
| 43 |
+
self.maxpool2 = nn.MaxPool2d(kernel_size=(1, 20))
|
| 44 |
+
# in = (b, 128, 31, 32) from res_block2, out = (b, 128, 31, 2)
|
| 45 |
+
self.maxpool3 = nn.MaxPool2d(kernel_size=(1, 10))
|
| 46 |
+
|
| 47 |
+
# in = (b, 640, 31, 2), out = (b, 256, 31, 2)
|
| 48 |
+
self.detector_conv = nn.Sequential(
|
| 49 |
+
nn.Conv2d(640, 256, 1, bias=False),
|
| 50 |
+
nn.BatchNorm2d(256),
|
| 51 |
+
nn.LeakyReLU(leaky_relu_slope, inplace=True),
|
| 52 |
+
nn.Dropout(p=0.2),
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# input: (b, 31, 512) - resized from (b, 256, 31, 2)
|
| 56 |
+
self.bilstm_classifier = nn.LSTM(
|
| 57 |
+
input_size=512, hidden_size=256,
|
| 58 |
+
batch_first=True, bidirectional=True) # (b, 31, 512)
|
| 59 |
+
|
| 60 |
+
# input: (b, 31, 512) - resized from (b, 256, 31, 2)
|
| 61 |
+
self.bilstm_detector = nn.LSTM(
|
| 62 |
+
input_size=512, hidden_size=256,
|
| 63 |
+
batch_first=True, bidirectional=True) # (b, 31, 512)
|
| 64 |
+
|
| 65 |
+
# input: (b * 31, 512)
|
| 66 |
+
self.classifier = nn.Linear(in_features=512, out_features=self.num_class) # (b * 31, num_class)
|
| 67 |
+
|
| 68 |
+
# input: (b * 31, 512)
|
| 69 |
+
self.detector = nn.Linear(in_features=512, out_features=2) # (b * 31, 2) - binary classifier
|
| 70 |
+
|
| 71 |
+
# initialize weights
|
| 72 |
+
self.apply(self.init_weights)
|
| 73 |
+
|
| 74 |
+
def get_feature_GAN(self, x):
|
| 75 |
+
seq_len = x.shape[-2]
|
| 76 |
+
x = x.float().transpose(-1, -2)
|
| 77 |
+
|
| 78 |
+
convblock_out = self.conv_block(x)
|
| 79 |
+
|
| 80 |
+
resblock1_out = self.res_block1(convblock_out)
|
| 81 |
+
resblock2_out = self.res_block2(resblock1_out)
|
| 82 |
+
resblock3_out = self.res_block3(resblock2_out)
|
| 83 |
+
poolblock_out = self.pool_block[0](resblock3_out)
|
| 84 |
+
poolblock_out = self.pool_block[1](poolblock_out)
|
| 85 |
+
|
| 86 |
+
return poolblock_out.transpose(-1, -2)
|
| 87 |
+
|
| 88 |
+
def get_feature(self, x):
|
| 89 |
+
seq_len = x.shape[-2]
|
| 90 |
+
x = x.float().transpose(-1, -2)
|
| 91 |
+
|
| 92 |
+
convblock_out = self.conv_block(x)
|
| 93 |
+
|
| 94 |
+
resblock1_out = self.res_block1(convblock_out)
|
| 95 |
+
resblock2_out = self.res_block2(resblock1_out)
|
| 96 |
+
resblock3_out = self.res_block3(resblock2_out)
|
| 97 |
+
poolblock_out = self.pool_block[0](resblock3_out)
|
| 98 |
+
poolblock_out = self.pool_block[1](poolblock_out)
|
| 99 |
+
|
| 100 |
+
return self.pool_block[2](poolblock_out)
|
| 101 |
+
|
| 102 |
+
def forward(self, x):
|
| 103 |
+
"""
|
| 104 |
+
Returns:
|
| 105 |
+
classification_prediction, detection_prediction
|
| 106 |
+
sizes: (b, 31, 722), (b, 31, 2)
|
| 107 |
+
"""
|
| 108 |
+
###############################
|
| 109 |
+
# forward pass for classifier #
|
| 110 |
+
###############################
|
| 111 |
+
seq_len = x.shape[-1]
|
| 112 |
+
x = x.float().transpose(-1, -2)
|
| 113 |
+
|
| 114 |
+
convblock_out = self.conv_block(x)
|
| 115 |
+
|
| 116 |
+
resblock1_out = self.res_block1(convblock_out)
|
| 117 |
+
resblock2_out = self.res_block2(resblock1_out)
|
| 118 |
+
resblock3_out = self.res_block3(resblock2_out)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
poolblock_out = self.pool_block[0](resblock3_out)
|
| 122 |
+
poolblock_out = self.pool_block[1](poolblock_out)
|
| 123 |
+
GAN_feature = poolblock_out.transpose(-1, -2)
|
| 124 |
+
poolblock_out = self.pool_block[2](poolblock_out)
|
| 125 |
+
|
| 126 |
+
# (b, 256, 31, 2) => (b, 31, 256, 2) => (b, 31, 512)
|
| 127 |
+
classifier_out = poolblock_out.permute(0, 2, 1, 3).contiguous().view((-1, seq_len, 512))
|
| 128 |
+
classifier_out, _ = self.bilstm_classifier(classifier_out) # ignore the hidden states
|
| 129 |
+
|
| 130 |
+
classifier_out = classifier_out.contiguous().view((-1, 512)) # (b * 31, 512)
|
| 131 |
+
classifier_out = self.classifier(classifier_out)
|
| 132 |
+
classifier_out = classifier_out.view((-1, seq_len, self.num_class)) # (b, 31, num_class)
|
| 133 |
+
|
| 134 |
+
# sizes: (b, 31, 722), (b, 31, 2)
|
| 135 |
+
# classifier output consists of predicted pitch classes per frame
|
| 136 |
+
# detector output consists of: (isvoice, notvoice) estimates per frame
|
| 137 |
+
return torch.abs(classifier_out.squeeze()), GAN_feature, poolblock_out
|
| 138 |
+
|
| 139 |
+
@staticmethod
|
| 140 |
+
def init_weights(m):
|
| 141 |
+
if isinstance(m, nn.Linear):
|
| 142 |
+
nn.init.kaiming_uniform_(m.weight)
|
| 143 |
+
if m.bias is not None:
|
| 144 |
+
nn.init.constant_(m.bias, 0)
|
| 145 |
+
elif isinstance(m, nn.Conv2d):
|
| 146 |
+
nn.init.xavier_normal_(m.weight)
|
| 147 |
+
elif isinstance(m, nn.LSTM) or isinstance(m, nn.LSTMCell):
|
| 148 |
+
for p in m.parameters():
|
| 149 |
+
if p.data is None:
|
| 150 |
+
continue
|
| 151 |
+
|
| 152 |
+
if len(p.shape) >= 2:
|
| 153 |
+
nn.init.orthogonal_(p.data)
|
| 154 |
+
else:
|
| 155 |
+
nn.init.normal_(p.data)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
class ResBlock(nn.Module):
|
| 159 |
+
def __init__(self, in_channels: int, out_channels: int, leaky_relu_slope=0.01):
|
| 160 |
+
super().__init__()
|
| 161 |
+
self.downsample = in_channels != out_channels
|
| 162 |
+
|
| 163 |
+
# BN / LReLU / MaxPool layer before the conv layer - see Figure 1b in the paper
|
| 164 |
+
self.pre_conv = nn.Sequential(
|
| 165 |
+
nn.BatchNorm2d(num_features=in_channels),
|
| 166 |
+
nn.LeakyReLU(leaky_relu_slope, inplace=True),
|
| 167 |
+
nn.MaxPool2d(kernel_size=(1, 2)), # apply downsampling on the y axis only
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
# conv layers
|
| 171 |
+
self.conv = nn.Sequential(
|
| 172 |
+
nn.Conv2d(in_channels=in_channels, out_channels=out_channels,
|
| 173 |
+
kernel_size=3, padding=1, bias=False),
|
| 174 |
+
nn.BatchNorm2d(out_channels),
|
| 175 |
+
nn.LeakyReLU(leaky_relu_slope, inplace=True),
|
| 176 |
+
nn.Conv2d(out_channels, out_channels, 3, padding=1, bias=False),
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
# 1 x 1 convolution layer to match the feature dimensions
|
| 180 |
+
self.conv1by1 = None
|
| 181 |
+
if self.downsample:
|
| 182 |
+
self.conv1by1 = nn.Conv2d(in_channels, out_channels, 1, bias=False)
|
| 183 |
+
|
| 184 |
+
def forward(self, x):
|
| 185 |
+
x = self.pre_conv(x)
|
| 186 |
+
if self.downsample:
|
| 187 |
+
x = self.conv(x) + self.conv1by1(x)
|
| 188 |
+
else:
|
| 189 |
+
x = self.conv(x) + x
|
| 190 |
+
return x
|