Why am I getting error of “Expected 2 or more dimensions (got 1)” while running the below code:
import torch
import torch.nn as nn
import math
import numpy as np
import time 
import torch.nn.functional as F
import torch.optim as optim

class GraphConvolution(nn.Module):

    def __init__(self, in_features, out_features, bias=True):
        super(GraphConvolution, self).__init__()

        self.in_features = in_features
        self.out_features = out_features
        self.weight = nn.parameter.Parameter(torch.FloatTensor(in_features, out_features))
        if bias:
            self.bias = nn.parameter.Parameter(torch.FloatTensor(out_features))
        else:
            self.register_parameter('bias', None)
        self.reset_parameters()

    def reset_parameters(self):
        stdv = 1. / math.sqrt(self.weight.size(1))
        self.weight.data.uniform_(-stdv, stdv)
        if self.bias is not None:
            self.bias.data.uniform_(-stdv, stdv)

    def forward(self, x, adj):
        support = torch.mm(x, self.weight.long())
        output = torch.spmm(adj, support)
        return output

    def __repr__(self):
        return self.__class__.__name__ + ' (' \
               + str(self.in_features) + ' -> ' \
               + str(self.out_features) + ')'

class GCN(nn.Module):
    def __init__(self, nfeat, nhid, nclass):
        super(GCN, self).__init__()

        self.gc1 = GraphConvolution(nfeat, nhid)
        self.gc2 = GraphConvolution(nhid, nclass)
        self.dp = nn.Dropout(p=0.5)

    def forward(self, x, adj):
        x = F.relu(self.gc1(x, adj))
        x = self.dp(x.float()).long()
        x = self.gc2(x, adj).float()
        return torch.sum(F.log_softmax(x, dim=1), dim=1)

def train(epoch):
    t = time.time()
    model.train()
    optimizer.zero_grad()
    output = model(features, adj)
    
    loss_train = F.nll_loss(output[idx_train], labels[idx_train]) 
    loss_train.backward()
    optimizer.step()

    loss_val = F.nll_loss(output[idx_val], labels[idx_val])
    print('Epoch: {:04d}'.format(epoch+1),
          'loss_train: {:.4f}'.format(loss_train.item()),
          'loss_val: {:.4f}'.format(loss_val.item()),
          'time: {:.4f}s'.format(time.time() - t))
    

adj = torch.randint(high=10, size=(100,100)).long()
features = torch.sum(adj, dim=1).view(1,-1).long()
features = torch.transpose(features,0,1)

labels = torch.randint(high=10, size=(100,)).long()
print("labels = ",labels.size())

idx_train = torch.LongTensor(range(20))

model = GCN(nfeat=features.shape[1],
            nhid=9,
            nclass=8)

optimizer = optim.Adam(model.parameters(), lr=0.1, weight_decay= 5e-4)

for epoch in range(10):
    train(epoch)

Code: https://github.com/tkipf/pygcn/tree/master/pygcn
This code is taken from Graph Convolutional Network paper. One more doubt that I’ve regarding this is how are the weights trained when neither the adj or features matrix have been appended with requires_grad function?
Thanks in advance.