class MODEL(nn.Module):
def __init__(self, attention_heads=4, attention_size=32, out_size=4):
super(MODEL, self).__init__()
self.conv1a = nn.Conv2d(kernel_size=(10, 2), in_channels=1, out_channels=16, padding=(4, 0))
self.conv1b = nn.Conv2d(kernel_size=(2,8), in_channels=1, out_channels=16, padding=(0, 3))
self.conv2 = nn.Conv2d(kernel_size=(3,3), in_channels=32, out_channels=32, padding=(1,1))
self.conv3 = nn.Conv2d(kernel_size=(3,3), in_channels=32, out_channels=48, padding=(1,1))
self.conv4 = nn.Conv2d(kernel_size=(3,3), in_channels=48, out_channels=64, padding=(1,1))
self.conv5 = nn.Conv2d(kernel_size=(3,3), in_channels=64, out_channels=80, padding=(1,1))
self.maxp = nn.MaxPool2d((2, 2))
self.bn1a = nn.BatchNorm2d(3)
self.bn1b = nn.BatchNorm2d(3)
self.bn2 = nn.BatchNorm2d(3)
self.bn3 = nn.BatchNorm2d(3)
self.bn4 = nn.BatchNorm2d(3)
self.bn5 = nn.BatchNorm2d(3)
self.gap = nn.AdaptiveAvgPool2d(1)#(data_format='channels_last')
self.flatten = nn.Flatten()
self.fc = nn.Linear(10000,out_size)
self.attention_query = []
self.attention_key = []
self.attention_value = []
self.attention_heads = attention_heads
self.attention_size = attention_size
for i in range(self.attention_heads):
self.attention_query.append(nn.Conv2d(in_channels=80,out_channels=self.attention_size,kernel_size=1))
self.attention_key.append(nn.Conv2d(in_channels=80,out_channels=self.attention_size,kernel_size=1))
self.attention_value.append(nn.Conv2d(in_channels=80,out_channels=self.attention_size,kernel_size=1))
def call(self, *input):
x = input[0]
xa = self.conv1a(x)
xa = self.bn1a(xa)
xa=nn.relu(xa)
xb = self.conv1b(x)
xb = self.bn1b(xb)
xb = nn.relu(xb)
x = nn.concat([xa, xb], 1)
x = self.conv2(x)
x = self.bn2(x)
x=nn.relu(x)
x = self.maxp(x)
x = self.conv3(x)
x = self.bn3(x)
x = nn.relu(x)
x = self.maxp(x)
x = self.conv4(x)
x = self.bn4(x)
x = nn.relu(x)
x = self.conv5(x)
x = self.bn5(x)
x = nn.relu(x)
attn = None
for i in range(self.attention_heads):
# Q = self.attention_query[i](x)
# Q = tf.transpose(Q, perm=[0, 3, 1, 2])
# K = self.attention_key[i](x)
# K = tf.transpose(K, perm=[0, 3, 2, 1])
# V = self.attention_value[i](x)
# V = tf.transpose(V, perm=[0, 3, 1, 2])
# attention = tf.nn.softmax(tf.matmul(Q, K))
# attention = tf.matmul(attention, V)
Q = self.attention_query[i](x)
K = self.attention_key[i](x)
V = self.attention_value[i](x)
attention = nn.Softmax(torch.matmul(Q, K),dim=1)
attention = torch.matmul(attention, V)
if (attn is None):
attn = attention
else:
attn = nn.concat([attn, attention], 2)
x = torch. transpose(attn, perm=[0, 2, 3, 1])
x = nn.relu(x)
x = self.gap(x)
x = self.flatten(x)
x = self.fc(x)
return x
raise NotImplementedError
I am not getting this error , my input is a 2d structure of size (23,63)