Commit ac89587b authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Graph topology example broken somewhere. Need to debug

parent b1657c5b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -692,7 +692,7 @@ class TestOverfitAPI(test_util.TensorFlowTestCase):
    n_atoms = 50
    n_feat = 71
    batch_size = 10
    graph_model = SequentialGraphModel(n_atoms, n_feat, batch_size)
    graph_model = SequentialGraphModel(n_atoms, n_feat)
    graph_model.add(GraphConv(64, activation='relu'))
    graph_model.add(BatchNormalization(epsilon=1e-5, mode=1))
    graph_model.add(GraphPool())
+0 −3
Original line number Diff line number Diff line
@@ -33,9 +33,6 @@ class SequentialGraphModel(object):
    n_feat: int
      Number of features per atom.
    """
    
    #super(SequentialGraphModel, self).__init__()
    # Create graph topology and x
    self.graph_topology = GraphTopology(n_atoms, n_feat)
    self.output = self.graph_topology.get_atom_features_placeholder()
    # Keep track of the layers
+4 −24
Original line number Diff line number Diff line
@@ -55,12 +55,12 @@ class GraphTopology(object):
    self.min_deg = min_deg

    self.atom_features_placeholder = Input(
        #tensor=K.placeholder(
        #    shape=(None, self.n_feat), dtype='float32',
        #    name=self.name+'_atom_features'))
        tensor=K.placeholder(
            shape=(self.n_atoms, self.n_feat), dtype='float32',
            shape=(None, self.n_feat), dtype='float32',
            name=self.name+'_atom_features'))
        #tensor=K.placeholder(
        #    shape=(self.n_atoms, self.n_feat), dtype='float32',
        #    name=self.name+'_atom_features'))
    self.deg_adj_lists_placeholders = [
        Input(tensor=K.placeholder(
          shape=(None, deg), dtype='int32', name=self.name+'_deg_adj'+str(deg)))
@@ -136,23 +136,3 @@ class GraphTopology(object):
                  self.deg_slice_placeholder : batch.deg_slice,
                  self.membership_placeholder : batch.membership}
    return merge_dicts([atoms_dict, deg_adj_dict])

'''
def extract_topology(x):
  # Extracts the topology tensors from x
  topology = x[1::]

  # Extract parsed topology information
  deg_slice = topology[0]
  membership = topology[1]
  deg_adj_lists = topology[2::]

  return deg_slice, membership, deg_adj_lists

def extract_nodes(x):
  # Extracts the nodes from x (just the first tensor in the list of tensors)
  return x[0]

def extract_membership(x):
  return x[2]
'''
+8 −33
Original line number Diff line number Diff line
@@ -216,31 +216,20 @@ class SupportGraphClassifier(Model):
  def construct_feed_dict(self, test, support, training=True, add_phase=False):
    """Constructs tensorflow feed from test/support sets."""
    # Generate dictionary elements for support 
    support_labels_dict = {self.support_label_placeholder: np.squeeze(support.y)}
    support_topo_dict = (
    feed_dict = (
        self.model.support_graph_topology.batch_to_feed_dict(support.X))
    support_dict = merge_dicts([support_topo_dict, support_labels_dict])
  
    # Generate dictionary elements for test
    ########################################################### DEBUG
    print("test.y.shape, test.w.shape")
    print(test.y.shape, test.w.shape)
    ########################################################### DEBUG
    target_dict = {self.label_placeholder: np.squeeze(test.y),
                   self.weight_placeholder: np.squeeze(test.w)}
    # Get graph information for x
    feed_dict[self.support_label_placeholder] = np.squeeze(support.y)
    # Get graph information for test 
    batch_topo_dict = (
        self.model.test_graph_topology.batch_to_feed_dict(test.X))
    test_dict =  merge_dicts([batch_topo_dict, target_dict])

    test_support_dicts = merge_dicts([test_dict, support_dict])
    feed_dict = merge_dicts([batch_topo_dict, feed_dict_dict])
    # Generate dictionary elements for test
    feed_dict[self.label_placeholder] = np.squeeze(test.y)
    feed_dict[self.weight_placeholder] = np.squeeze(test.w)

    # Get information for keras 
    if add_phase:
      keras_dict = {K.learning_phase() : training}
      feed_dict = merge_dicts([test_support_dicts, keras_dict])
    else:
      feed_dict = test_support_dicts
      feed_dict[K.learning_phase()] = training
    return feed_dict

  def fit(self, dataset, n_trials_per_epoch=1000, nb_epoch=10, n_pos=1,
@@ -341,26 +330,12 @@ class SupportGraphClassifier(Model):
  def predict_on_batch(self, support, test_batch):
    """Make predictions on batch of data."""
    n_samples = len(test_batch)
    ################################################# DEBUG
    print("predict_on_batch()")
    print("test_batch.X.shape, test_batch.y.shape, test_batch.w.shape, test_batch.ids.shape")
    print(test_batch.X.shape, test_batch.y.shape, test_batch.w.shape, test_batch.ids.shape)
    ################################################# DEBUG
    padded_test_batch = NumpyDataset(*pad_batch(
        self.test_batch_size, test_batch.X, test_batch.y, test_batch.w,
        test_batch.ids))
    feed_dict = self.construct_feed_dict(padded_test_batch, support)
    # Get scores
    scores = self.sess.run(self.scores_op, feed_dict=feed_dict)
    ################################################# DEBUG
    print("predict_on_batch()")
    print("scores.shape")
    print(scores.shape)
    print("scores")
    print(scores)
    y_pred_batch = to_one_hot(np.round(scores))
    y_pred_batch = y_pred_batch[:n_samples]
    ################################################# DEBUG
    return y_pred_batch
    
  def evaluate(self, dataset, test_tasks, metrics, n_trials=1000):