Conversion of Conv LSTM to CNN model
sgilani2020 opened this issue · 0 comments
sgilani2020 commented
Hi,
I want to convert your code to CNN model. I modified the model as:
class HARModel(nn.Module):
def __init__(self, n_hidden=128, n_layers=1, n_filters=64,
n_classes=18, filter_size=3, drop_prob=0.6):
super(HARModel, self).__init__()
self.drop_prob = drop_prob
self.n_layers = n_layers
self.n_hidden = n_hidden
self.n_filters = n_filters
self.n_classes = n_classes
self.filter_size = filter_size
self.conv1 = nn.Conv1d(NB_SENSOR_CHANNELS, n_filters, filter_size)
self.conv2 = nn.Conv1d(n_filters, n_filters, filter_size)
self.conv3 = nn.Conv1d(n_filters, n_filters, filter_size)
self.fc1 = nn.Linear(n_filters*filter_size,n_hidden)
self.fc2 = nn.Linear(n_hidden, n_classes)
self.dropout = nn.Dropout(drop_prob)
def forward(self, x, hidden, batch_size):
x = x.view(-1, NB_SENSOR_CHANNELS, SLIDING_WINDOW_LENGTH)
x = F.relu(F.max_pool1d(self.conv1(x),2))
x = F.relu(F.max_pool1d(self.conv2(x),2))
x = F.relu(F.max_pool1d(self.conv3(x),2))
x = x.contiguous().view(-1, self.n_hidden)
x = self.dropout(x)
x = self.fc1(x)
x = self.fc2(x)
out = x.view(batch_size, -1, self.n_classes)[:,-1,:]
return out, hidden
It gives me the following error after running the code:
size mismatch, m1: [50 x 128], m2: [192 x 128] at C:\w\1\s\tmp_conda_3.7_105232\conda\conda-bld\pytorch_1579085620499\work\aten\src\TH/generic/THTensorMath.cpp:136
Please suggest how I can modify your code for developing CNN model.