def evaluate(self, seq_data, head_i=0, loss='poisson'): """ Evaluate model on SeqDataset. """ # choose model if self.ensemble is None: model = self.models[head_i] else: model = self.ensemble # compile with dense metrics num_targets = self.model.output_shape[-1] if loss == 'bce': model.compile(optimizer=tf.keras.optimizers.SGD(), loss=loss, metrics=[ metrics.SeqAUC(curve='ROC', summarize=False), metrics.SeqAUC(curve='PR', summarize=False) ]) else: model.compile(optimizer=tf.keras.optimizers.SGD(), loss=loss, metrics=[ metrics.PearsonR(num_targets, summarize=False), metrics.R2(num_targets, summarize=False) ]) # evaluate return model.evaluate(seq_data.dataset)
def compile(self, seqnn_model): for model in seqnn_model.models: if self.loss == 'bce': model_metrics = [metrics.SeqAUC(curve='ROC'), metrics.SeqAUC(curve='PR')] else: num_targets = model.output_shape[-1] model_metrics = [metrics.PearsonR(num_targets), metrics.R2(num_targets)] model.compile(loss=self.loss_fn, optimizer=self.optimizer, metrics=model_metrics) self.compiled = True