code: def __init__(
      self,
      config,
      in_node_dim,
      num_relations,
      num_nodes,
      special_input_node=False,
      special_input_sz=None,
  ):
      super().__init__()
      # Get/set parameters
      self.num_relations = num_relations
      self.num_nodes = num_nodes
      # Passed in from GraphNetworkModule which constructs the input features
      self.in_node_dim = in_node_dim
      self.node_hid_dim = config.node_hid_dim
      self.num_gcn_conv = config.num_gcn_conv
      self.use_bn = config.use_batch_norm
      self.use_drop = config.use_dropout
      self.output_type = config.output_type
      self.gcn_type = config.gcn_type
      if self.use_drop:
          self.drop_p = config.dropout_p
      if "output_dim" in config:
          self.output_dim = config.output_dim
      else:
          self.output_dim = self.node_hid_dim
      self.special_input_node = special_input_node
      self.special_input_sz = special_input_sz
      self.output_special_node = config.output_special_node
  
      # Make GCN and batchnorm layers
      if self.num_gcn_conv >= 1:
          # Try to add CompGCN at some point
          if self.gcn_type == "RGCN":
              self.conv1 = RGCNConv(
                  self.in_node_dim,
                  self.node_hid_dim,
                  self.num_relations,
                  num_bases=None,
              )
          elif self.gcn_type == "GCN":
              self.conv1 = GCNConv(self.in_node_dim, self.node_hid_dim)
          elif self.gcn_type == "SAGE":
              self.conv1 = SAGEConv(self.in_node_dim, self.node_hid_dim)
          else:
              raise Exception(
                  "GCN type %s not implemented" % self.gcn_type
              )
      if self.num_gcn_conv >= 2:
          if self.use_bn:
              self.bn1 = BatchNorm(self.node_hid_dim)
          if self.gcn_type == "RGCN":
              self.conv2 = RGCNConv(
                  self.node_hid_dim,
                  self.node_hid_dim,
                  self.num_relations,
                  num_bases=None,
              )
          elif self.gcn_type == "GCN":
              self.conv2 = GCNConv(self.node_hid_dim, self.node_hid_dim)
          elif self.gcn_type == "SAGE":
              self.conv2 = SAGEConv(
                  self.node_hid_dim, self.node_hid_dim
              )
          else:
              raise Exception(
                  "GCN type %s not implemented" % self.gcn_type
              )
      if self.num_gcn_conv >= 3:
          if self.use_bn:
              self.bn2 = BatchNorm(self.node_hid_dim)
          if self.gcn_type == "RGCN":
              self.conv3 = RGCNConv(
                  self.node_hid_dim,
                  self.node_hid_dim,
                  self.num_relations,
                  num_bases=None,
              )
          elif self.gcn_type == "GCN":
              self.conv3 = GCNConv(self.node_hid_dim, self.node_hid_dim)
          elif self.gcn_type == "SAGE":
              self.conv3 = SAGEConv(
                  self.node_hid_dim, self.node_hid_dim
              )
          else:
              raise Exception(
                  "GCN type %s not implemented" % self.gcn_type
              )
      if self.num_gcn_conv >= 4:
          if self.use_bn:
              self.bn3 = BatchNorm(self.node_hid_dim)
          if self.gcn_type == "RGCN":
              self.conv4 = RGCNConv(
                  self.node_hid_dim,
                  self.node_hid_dim,
                  self.num_relations,
                  num_bases=None,
              )
          elif self.gcn_type == "GCN":
              self.conv4 = GCNConv(self.node_hid_dim, self.node_hid_dim)
          elif self.gcn_type == "SAGE":
              self.conv4 = SAGEConv(
                  self.node_hid_dim, self.node_hid_dim
              )
          else:
              raise Exception(
                  "GCN type %s not implemented" % self.gcn_type
              )
      if self.num_gcn_conv >= 5:
          if self.use_bn:
              self.bn4 = BatchNorm(self.node_hid_dim)
          if self.gcn_type == "RGCN":
              self.conv5 = RGCNConv(
                  self.node_hid_dim,
                  self.node_hid_dim,
                  self.num_relations,
                  num_bases=None,
              )
          elif self.gcn_type == "GCN":
              self.conv5 = GCNConv(self.node_hid_dim, self.node_hid_dim)
          elif self.gcn_type == "SAGE":
              self.conv5 = SAGEConv(
                  self.node_hid_dim, self.node_hid_dim
              )
          else:
              raise Exception(
                  "GCN type %s not implemented" % self.gcn_type
              )
      if self.num_gcn_conv >= 6:
          if self.use_bn:
              self.bn5 = BatchNorm(self.node_hid_dim)
          if self.gcn_type == "RGCN":
              self.conv6 = RGCNConv(
                  self.node_hid_dim,
                  self.node_hid_dim,
                  self.num_relations,
                  num_bases=None,
              )
          elif self.gcn_type == "GCN":
              self.conv6 = GCNConv(self.node_hid_dim, self.node_hid_dim)
          elif self.gcn_type == "SAGE":
              self.conv6 = SAGEConv(
                  self.node_hid_dim, self.node_hid_dim
              )
          else:
              raise Exception(
                  "GCN type %s not implemented" % self.gcn_type
              )
  
      if self.num_gcn_conv >= 7:
          raise Exception(
              "Did not implement %d gcn layers yet" % self.num_gcn_conv
          )
  
      # Add special node for input/output collection
      if self.output_special_node or self.special_input_node:
          # For special in (not mutally exclusive to special out)
          # Make an linear encoder to fit into node hid size
          if self.special_input_node:
              self.spec_input_fc = nn.Linear(
                  self.special_input_sz, self.node_hid_dim
              )
  
          # Make graph conv (and transfer layers)
          # Add one to num_rels since we have a special relation for this
          if self.use_bn:
              self.bn_spec = BatchNorm(self.node_hid_dim)
          if self.gcn_type == "RGCN":
              self.conv_spec = RGCNConv(
                  self.node_hid_dim,
                  self.node_hid_dim,
                  self.num_relations + 1,
                  num_bases=None,
              )
          elif self.gcn_type == "GCN":
              self.conv_spec = GCNConv(
                  self.node_hid_dim, self.node_hid_dim
              )
          elif self.gcn_type == "SAGE":
              self.conv_spec = SAGEConv(
                  self.node_hid_dim, self.node_hid_dim
              )
          else:
              raise Exception(
                  "GCN type %s not implemented" % self.gcn_type
              )
  
          # On first pass, populate this and convert to cuda
          # Connects all node indices to the special node via a "special" edge type
          self.edge_index_special = None
          self.edge_type_special = None
          self.special_bs = None
  
      # Set output network
      if self.output_type in [
          "hidden",
          "hidden_subindex",
          "hidden_ans",
      ]:
          # Don't really need anything here, either passing all of G,
          # or G for particular indices
          pass
      elif self.output_type in [
          "graph_level",
          "graph_level_ansonly",
          "graph_level_inputonly",
      ]:
          # Will first predict a logit for each node, then do
          # softmax addition of all graph features
          self.logit_pred = nn.Linear(
              self.node_hid_dim, 1
          )  # Predicts hid_dim -> 1, which then gets passed into softmax
          self.feat_layer = nn.Linear(
              self.node_hid_dim, self.output_dim
          )
      elif self.output_type in ["graph_prediction"]:
          # Need just a final logits prediction
          self.logit_pred = nn.Linear(self.node_hid_dim, 1)
      else:
          raise Exception(
              "Output type %s is not implemented right now"
              % self.output_type
          )
  
imports: import os
  import pickle
  import networkx
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from gensim.models import KeyedVectors
  from gensim.scripts.glove2word2vec import glove2word2vec
  from mmf.common.registry import registry
  from mmf.models.base_model import BaseModel
  from mmf.utils.text import VocabDict
  from networkx import convert_node_labels_to_integers
  from torch_geometric.nn import BatchNorm, GCNConv, RGCNConv, SAGEConv
  from tqdm import tqdm
label_desc: Use image node_id 1 to create a new GraphNetwork object from inherited base classes: nn with example: obj = GraphNetwork(config, in_node_dim, num_relations, num_nodes, special_input_node, special_input_sz)