def __init__(self, model_args): super(GPNN_VCOCO_v2, self).__init__() self.model_args = model_args.copy() if model_args['resize_feature_to_message_size']: # Resize large features self.edge_feature_resize = torch.nn.Linear( model_args['edge_feature_size'], model_args['message_size']) self.node_feature_resize = torch.nn.Linear( model_args['node_feature_size'], model_args['message_size']) torch.nn.init.xavier_normal(self.edge_feature_resize.weight) torch.nn.init.xavier_normal(self.node_feature_resize.weight) model_args['edge_feature_size'] = model_args['message_size'] model_args['node_feature_size'] = model_args['message_size'] self.link_fun = units.LinkFunction('GraphConv', model_args) self.sigmoid = torch.nn.Sigmoid() self.message_fun = units.MessageFunction('linear_concat_relu', model_args) self.update_fun = units.UpdateFunction('gru', model_args) self.readout_fun = units.ReadoutFunction( 'fc', { 'readout_input_size': model_args['node_feature_size'], 'output_classes': model_args['hoi_classes'] }) self.readout_fun2 = units.ReadoutFunction( 'fc', { 'readout_input_size': model_args['node_feature_size'], 'output_classes': model_args['roles_num'] }) self.propagate_layers = model_args['propagate_layers'] self._load_link_fun(model_args)
def __init__(self, model_args): super(GPNN_CAD, self).__init__() self.link_fun = units.LinkFunction('GraphConvLSTM', model_args) self.message_fun = units.MessageFunction('linear_concat', model_args) self.update_funs = torch.nn.ModuleList([]) self.update_funs.append(units.UpdateFunction('gru', model_args)) self.update_funs.append(units.UpdateFunction('gru', model_args)) self.subactivity_classes = model_args['subactivity_classes'] self.affordance_classes = model_args['affordance_classes'] self.readout_funs = torch.nn.ModuleList([]) self.readout_funs.append( units.ReadoutFunction( 'fc_soft_max', { 'readout_input_size': model_args['node_feature_size'], 'output_classes': self.subactivity_classes })) self.readout_funs.append( units.ReadoutFunction( 'fc_soft_max', { 'readout_input_size': model_args['node_feature_size'], 'output_classes': self.affordance_classes })) self.propagate_layers = model_args['propagate_layers'] self._load_link_fun(model_args)
def __init__(self, model_args, args): super(AttMat_msg_lstm, self).__init__() self.model_args = model_args.copy() # TODO: I don't think resnet34 is sufficient for this task, # TODO: you'd better adopt resnet50 for feature extraction at least. self.resnet = units.Resnet34(model_args['roi_feature_size']) # TODO: The init of the ConvLSTM is important, double check the init procedure. self.link_fun = units.LinkFunction('GraphConv', model_args) self.base_model = torch.nn.ModuleList([]) self.load_base_model = args.load_base_model self.base_model_weight = args.base_model_weight self.freeze_base_model = args.freeze_base_model self.message_fun = units.MessageFunction('linear_concat_relu', model_args) self.update_fun = units.UpdateFunction('gru', model_args) self.readout_fun = units.ReadoutFunction( 'fc', { 'readout_input_size': model_args['node_feature_size'], 'output_classes': model_args['big_attr_classes'] }) self.base_model.append(self.resnet) self.base_model.append(self.link_fun) self.base_model.append(self.message_fun) self.base_model.append(self.update_fun) self.lstm = torch.nn.LSTM(model_args['roi_feature_size'], self.model_args['lstm_hidden_size']) self.lstm_readout = units.ReadoutFunction( 'fc', { 'readout_input_size': model_args['lstm_hidden_size'], 'output_classes': model_args['big_attr_classes'] }) self.propagate_layers = model_args['propagate_layers'] self.softmax = torch.nn.Softmax() self.relu = torch.nn.ReLU() self.sigmoid = torch.nn.Sigmoid() self.maxpool = torch.nn.MaxPool2d((2, 2)) if self.load_base_model: self._load_base_model_weight(self.base_model_weight) if self.freeze_base_model: for i, param in self.base_model[0].named_parameters(): param.requires_grad = False
def __init__(self, model_args): super(HGNN_lstm, self).__init__() self.model_args = model_args.copy() self.resnet = units.Resnet.ResNet50(3) self.link_fun = units.LinkFunction('GraphConv', model_args) self.message_fun = units.MessageFunction('linear_concat_relu', model_args) self.update_fun = units.UpdateFunction('gru', model_args) self.readout_fun = units.ReadoutFunction( 'fc', { 'readout_input_size': model_args['node_feature_size'], 'output_classes': model_args['big_attr_classes'] }) self.lstm = torch.nn.LSTM(model_args['roi_feature_size'], self.model_args['lstm_hidden_size']) self.lstm_readout = torch.nn.Linear( self.model_args['lstm_hidden_size'], self.model_args['big_attr_classes']) self.propagate_layers = model_args['propagate_layers'] self.softmax = torch.nn.Softmax() self.relu = torch.nn.ReLU() self.sigmoid = torch.nn.Sigmoid() self.maxpool = torch.nn.MaxPool2d((2, 2))
def __init__(self, model_args, args): super(Atomic_HGNN, self).__init__() self.model_args = model_args.copy() self.resnet = units.Resnet.ResNet50(6) self._load_pretrained_weight( os.path.join(args.tmp_root, 'checkpoints', 'attmat', 'model_best.pth')) self.freeze_res_layer(layer_num=9) num_ftrs = self.resnet.resnet.fc.in_features self.resnet.resnet.fc = torch.nn.Linear(num_ftrs, 64 * 3) self.conv3d1 = torch.nn.Conv3d( in_channels=64 * 3, out_channels=6, kernel_size=(5, 6, 1), stride=1, padding=0 ) #Conv3d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True) self.conv3d2 = torch.nn.Conv3d(in_channels=6, out_channels=6, kernel_size=(1, 1, 1), stride=1, padding=0) self.link_fun = units.LinkFunction('GraphConv', model_args) self.message_fun = units.MessageFunction('linear_concat_relu', model_args) self.update_fun = units.UpdateFunction('gru', model_args) self.readout_fun = units.ReadoutFunction( 'fc', { 'readout_input_size': model_args['node_feature_size'], 'output_classes': model_args['big_attr_classes'] }) self.lstm = torch.nn.LSTM(model_args['roi_feature_size'], self.model_args['lstm_hidden_size']) self.lstm_readout = torch.nn.Linear( self.model_args['lstm_hidden_size'], self.model_args['big_attr_classes']) self.propagate_layers = model_args['propagate_layers'] self.softmax = torch.nn.Softmax() self.relu = torch.nn.ReLU() self.sigmoid = torch.nn.Sigmoid() self.maxpool = torch.nn.MaxPool2d((2, 2))
def __init__(self, model_args): super(GPNN_HICO, self).__init__() self.model_args = model_args.copy() if model_args['resize_feature_to_message_size']: # Resize large features into message size with Linear functions and xavier normalization self.edge_feature_resize = torch.nn.Linear(model_args['edge_feature_size'], model_args['message_size']) self.node_feature_resize = torch.nn.Linear(model_args['node_feature_size'], model_args['message_size']) torch.nn.init.xavier_normal(self.edge_feature_resize.weight) torch.nn.init.xavier_normal(self.node_feature_resize.weight) model_args['edge_feature_size'] = model_args['message_size'] model_args['node_feature_size'] = model_args['message_size'] self.link_fun = units.LinkFunction('GraphConv', model_args) # if needs temporal operation, then 'GraphConvLSTM' self.sigmoid = torch.nn.Sigmoid() self.message_fun = units.MessageFunction('linear_concat_relu', model_args) # concatenate messages from all neghbor nodes self.update_fun = units.UpdateFunction('gru', model_args) self.readout_fun = units.ReadoutFunction('fc', {'readout_input_size': model_args['node_feature_size'], 'output_classes': model_args['hoi_classes']}) self.propagate_layers = model_args['propagate_layers'] self._load_link_fun(model_args)