bird_cloud_gnn.gnn_model

Module for creating GCN class

Module Contents

Classes

GCN

Graph Convolutional Network construction module

class bird_cloud_gnn.gnn_model.GCN(in_feats: int, layers_data: list)[source]

Bases: torch.nn.Module

Graph Convolutional Network construction module

A n-layer GCN is constructed from input features and list of layers Each layer computes new node representations by aggregating neighbour information.

Parameters:
  • in_feats (int) – the number of input features

  • layers_data (list) – is a list of tuples of size of hidden layer and activation function

in_feats

the number of input features

Type:

int

layers

list of layers

Type:

nn.ModuleList

name

name of the model

Type:

str

num_classes

the last size should correspond to the number of classes were predicting

Type:

int

oneline_description()[source]

Description of the model to uniquely identify it in logs

forward(g, in_feats)[source]

Computes the output of the model.

fit(train_dataloader, learning_rate=0.01, num_epochs=20)[source]

Train the model.

evaluate(test_dataloader)[source]

Evaluate model.

fit_and_evaluate(train_dataloader, test_dataloader, callback=None, learning_rate=0.01,
num_epochs=20, sch_explr_gamma=0.99, sch_multisteplr_milestones=None,
sch_multisteplr_gamma=0.1)

Fit the model while evaluating every iteraction.

oneline_description()[source]

Description of the model to uniquely identify it in logs

forward(g, in_feats)[source]

The forward function computes the output of the model.

Parameters:
  • self – Access the attributes of the class

  • g – Access the graph structure and send messages between nodes

  • in_feat – Pass the input feature of the node

Returns:

The output of the second convolutional layer

fit(train_dataloader, learning_rate=0.01, num_epochs=20)[source]

Train the model.

Parameters:
  • train_dataloader – Data loader, such as SubsetRandomSampler

  • learning_rate (float, optional) – Learning rate passed to the optimization. Defaults to 0.01.

  • num_epochs (int, optional) – Number of epochs of training. Defaults to 20.

evaluate(test_dataloader)[source]

Evaluate model.

Parameters:

test_dataloader – Data loader, such as SubsetRandomSampler.

Returns:

Accuracy

Return type:

accuracy

fit_and_evaluate(train_dataloader, test_dataloader, callback=None, learning_rate=0.01, num_epochs=20, sch_explr_gamma=0.99, sch_multisteplr_milestones=None, sch_multisteplr_gamma=0.1)[source]

Fit the model while evaluating every iteraction.

Parameters:
  • train_dataloader (RandomWSubsetSampler) – Data loader to train set.

  • test_dataloader (RandomWSubsetSampler) – Data loader to test set.

  • callback (callable, optional) – Callback function. If defined, should receive a dict that stores “Loss/train”, “Accuracy/train”, “Loss/test”, “Accuracy/test”, and “epoch” of a single epoch. To send a stop signal, return True. Defaults to None.

  • learning_rate (float, optional) – Learning rate. Defaults to 0.01.

  • num_epochs (int, optional) – Number of training epochs. Defaults to 20.

  • sch_explr_gamma (float) – The exponential decay rate of the learning rate.

  • sch_multisteplr_milestones (list) – epoch numbers where the learning rate is decreased by a factor of sch_multisteplr_gamma. If None this is done at epoch 100

  • sch_multisteplr_gamma (float) – If a stepped decay of the learning rate is taken, the multiplication factor

infer(dataset, batch_size=1024)[source]

Using the model do inference on a dataset.

Parameters:

dataset – A RadarDataSet where for each graph inference needs to be done.

Returns:

A numpy array with infered labels for each graph

Return type:

labels