Hi,
I am working on a times series classification. I want to do this classification using CNN.
My data has 25 features. The input size that I made is: [batch_size, time_stamp, number_of_features]–> [10, 1, 25].
-
my first question is: Do I make a correct input? I would like to extract features using CNN, however, I am not sure that I need to transpose my input to [batch_size, number_of_features, time_stamp]?
-
Assuming the input with dimension [batch_size, time_stamp, number_of_features]
I made the CNN as follows:
class CNN(nn.Module):
def __init__(self):
super(CNN, self).__init__()
self.conv1 = nn.Conv1d(in_channels =1, out_channels = 32, kernel_size =3, stride=1, padding =1 )
self.relu = nn.ReLU()
self.maxpool = nn.MaxPool1d(2) #output 25/2 = 12
self.dropout = nn.Dropout(0.25)
self.conv2 = nn.Conv1d(in_channels =32, out_channels = 12, kernel_size =3, stride=1, padding =1 )
self.batchnormal = nn.BatchNorm1d(12)
self.relu = nn.ReLU()
self.maxpool = nn.MaxPool1d(2) #output 25/2 = 5
# 5*12
# self.flat = nn.Flatten()
self.fc1 = nn.Linear(72, 32)
self.dropout = nn.Dropout(0.1)
self.fc2 = nn.Linear(32, 1)
self.sigmoid =nn.Sigmoid()
def forward(self, x):
print(x.shape)
out = self.conv1(x)
out = self.relu(out)
out = self.maxpool(out)
out = self.dropout(out)
out =self.conv2(out)
out = self.batchnormal(out)
out = self.relu(out)
out = self.maxpool(out)
out = out.view(-1,72)
print(out.shape)
out = self.fc1(out)
out = self.dropout(out)
out = self.fc2 (out)
print(out.shape)
out = self.sigmoid(out)
return out
do I apply my Conv1d correctly?
As I explained in (1) I wan to use CNN to extract features.
P.S.
for testing the CNN you can use this code:
a= torch.rand(10,1,25)
print(a.shape)
traget = torch.empty(10, 1).uniform_(0, 1)
target = torch.bernoulli(target)
print(target.shape)
model = CNN()
out = model(a)
print(ou.shape)
I really appreciate any help!!