Str0keOOOO's picture
v1:第一版打包完成
1a4590c
import torch
from torch import nn
# ----------------------------inputsize >=28-------------------------------------------------------------------------
class CNN(nn.Module):
def __init__(self):
super(CNN, self).__init__()
self.__in_features = 256
self.layer1 = nn.Sequential(
nn.Conv1d(1, 16, kernel_size=15), # 16, 26 ,26
nn.BatchNorm1d(16),
nn.ReLU(inplace=True),
)
self.layer2 = nn.Sequential(
nn.Conv1d(16, 32, kernel_size=3), # 32, 24, 24
nn.BatchNorm1d(32),
nn.ReLU(inplace=True),
nn.MaxPool1d(kernel_size=2, stride=2),
) # 32, 12,12 (24-2) /2 +1
self.layer3 = nn.Sequential(
nn.Conv1d(32, 64, kernel_size=3), # 64,10,10
nn.BatchNorm1d(64),
nn.ReLU(inplace=True),
)
self.layer4 = nn.Sequential(
nn.Conv1d(64, 128, kernel_size=3), # 128,8,8
nn.BatchNorm1d(128),
nn.ReLU(inplace=True),
nn.AdaptiveMaxPool1d(4),
) # 128, 4,4
self.layer5 = nn.Sequential(nn.Linear(128 * 4, self.__in_features), nn.ReLU(inplace=True), nn.Dropout())
def forward(self, x):
x = self.layer1(x)
x = self.layer2(x)
x = self.layer3(x)
x = self.layer4(x)
x = x.view(x.size(0), -1)
x = self.layer5(x)
return x
def output_num(self):
return self.__in_features
if __name__ == "__main__":
model = CNN()
input = torch.randn(1, 1, 1024)
out = model(input)
print(out.shape)