def train_sequence(self, index): # if the graph is changed? labels = self.labels_onehot[index] sequence = FullBatchNodeSequence( [self.feature_inputs, self.structure_inputs, index], labels, device=self.device) return sequence
def train_sequence(self, index): labels = self.graph.labels[index] sequence = FullBatchNodeSequence( [self.feature_inputs, self.structure_inputs, index], labels, device=self.device) return sequence
def train_sequence(self, index): labels = self.graph.node_label[index] sequence = FullBatchNodeSequence( [self.feature_inputs, self.structure_inputs, index], labels, device=self.device, escape=type(self.structure_inputs)) return sequence
def train_sequence(self, index): index = gf.astensor(index) labels = self.graph.node_label[index] feature_inputs = tf.gather(self.feature_inputs, index) sequence = FullBatchNodeSequence(feature_inputs, labels, device=self.device) return sequence
def train_sequence(self, index): index = T.astensor(index) labels = self.graph.labels[index] if self.kind == "T": feature_inputs = tf.gather(self.feature_inputs, index) else: feature_inputs = self.feature_inputs[index] sequence = FullBatchNodeSequence(feature_inputs, labels, device=self.device) return sequence
def train_sequence(self, index, batch_size=np.inf): mask = T.indices2mask(index, self.graph.n_nodes) index = get_indice_graph(self.structure_inputs, index, batch_size) while index.size < self.K: index = get_indice_graph(self.structure_inputs, index) structure_inputs = self.structure_inputs[index][:, index] feature_inputs = self.feature_inputs[index] mask = mask[index] labels = self.graph.labels[index[mask]] sequence = FullBatchNodeSequence( [feature_inputs, structure_inputs, mask], labels, device=self.device) return sequence
def train(self, idx_train, idx_val=None, pre_train_epochs=100, epochs=100, early_stopping=None, verbose=None, save_best=True, weight_path=None, as_model=False, monitor='val_acc', early_stop_metric='val_loss'): histories = [] index_all = tf.range(self.graph.n_nodes, dtype=self.intx) # pre train model_q self.model = self.model_q history = super().train(idx_train, idx_val, epochs=pre_train_epochs, early_stopping=early_stopping, verbose=verbose, save_best=save_best, weight_path=weight_path, as_model=True, monitor=monitor, early_stop_metric=early_stop_metric) histories.append(history) label_predict = self.predict(index_all).argmax(1) label_predict[idx_train] = self.graph.labels[idx_train] label_predict = tf.one_hot(label_predict, depth=self.graph.n_classes) # train model_p fitst train_sequence = FullBatchNodeSequence( [label_predict, self.structure_inputs, index_all], label_predict, device=self.device) if idx_val is not None: val_sequence = FullBatchNodeSequence( [label_predict, self.structure_inputs, idx_val], self.labels_onehot[idx_val], device=self.device) else: val_sequence = None self.model = self.model_p history = super().train(train_sequence, val_sequence, epochs=epochs, early_stopping=early_stopping, verbose=verbose, save_best=save_best, weight_path=weight_path, as_model=as_model, monitor=monitor, early_stop_metric=early_stop_metric) histories.append(history) # then train model_q again label_predict = self.model.predict_on_batch( T.astensors(label_predict, self.structure_inputs, index_all, device=self.device)) label_predict = softmax(label_predict) if tf.is_tensor(label_predict): label_predict = label_predict.numpy() label_predict[idx_train] = self.labels_onehot[idx_train] self.model = self.model_q train_sequence = FullBatchNodeSequence( [self.feature_inputs, self.structure_inputs, index_all], label_predict, device=self.device) history = super().train(train_sequence, idx_val, epochs=epochs, early_stopping=early_stopping, verbose=verbose, save_best=save_best, weight_path=weight_path, as_model=as_model, monitor=monitor, early_stop_metric=early_stop_metric) histories.append(history) return histories
def train_sequence(self, index): labels = self.graph.node_label[index] with tf.device(self.device): sequence = FullBatchNodeSequence( [self.feature_inputs, self.structure_inputs, index], labels) return sequence