Created
October 11, 2020 03:44
-
-
Save y-kamiya/4f50185acd040dea4dda655cb24df372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import torch | |
import torch.nn as nn | |
class Model(nn.Module): | |
def __init__(self): | |
super(Model, self).__init__() | |
self.conv1 = nn.Sequential( | |
nn.Conv1d(1, 40, kernel_size=8, stride=1, padding=4), | |
nn.BatchNorm1d(40) | |
) | |
self.conv2 = nn.Sequential( | |
nn.Conv1d(40, 40, kernel_size=8, stride=1, padding=4), | |
nn.BatchNorm1d(40) | |
) | |
self.pool2 = nn.MaxPool1d(kernel_size=160) | |
self.conv3 = nn.Sequential( | |
nn.Conv2d(1, 50, kernel_size=(8, 13), stride=(1, 1)), | |
nn.BatchNorm2d(50) | |
) | |
self.pool3 = nn.MaxPool2d(kernel_size=(3, 3)) | |
self.conv4 = nn.Sequential( | |
nn.Conv2d(50, 50, kernel_size=(1, 5), stride=(1, 1)), | |
nn.BatchNorm2d(50) | |
) | |
self.pool4 = nn.MaxPool2d(kernel_size=(1, 3)) | |
self.fc5 = nn.Sequential( | |
nn.Linear(50 * 11 * 14, 4096), | |
nn.Dropout(0.5) | |
) | |
self.fc6 = nn.Sequential( | |
nn.Linear(4096, 4096), | |
nn.Dropout(0.5) | |
) | |
self.output = nn.Linear(4096, 50) | |
def forward(self, x): | |
x = self.conv1(x) | |
x = self.conv2(x) | |
x = self.pool2(x) | |
x = x.unsqueeze(1) | |
x = self.conv3(x) | |
x = self.pool3(x) | |
x = self.conv4(x) | |
x = self.pool4(x) | |
x = x.view(x.shape[0], -1) | |
x = self.fc5(x) | |
x = self.fc6(x) | |
return self.output(x) | |
def main(): | |
with torch.no_grad(): | |
model = Model() | |
sums = torch.zeros(1, 50) | |
for _ in range(100): | |
time.sleep(0.5) | |
data = torch.rand(1, 1, 24000) | |
output = model(data) | |
print(output.requires_grad) | |
sums += output | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment