keras_utils.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:mimic3-benchmarks 作者: YerevaNN 项目源码 文件源码
def calc_metrics(self, data, history, dataset, logs):
        y_true = []
        predictions = []
        B = self.batch_size
        for i in range(0, len(data[0]), B):
            if self.verbose == 1:
                print "\r\tdone {}/{}".format(i, len(data[0])),
            (x,y) = (data[0][i:i+B], data[1][i:i+B])
            outputs = self.model.predict(x, batch_size=B)

            if isinstance(y[0], list): # target replication
                y_true += list(y[0].flatten())
                predictions += list(outputs[0].flatten())
            else:
                y_true += list(np.array(y).flatten())
                predictions += list(outputs.flatten())
        print "\n"
        predictions = np.array(predictions)
        predictions = np.stack([1-predictions, predictions], axis=1)
        ret = metrics.print_metrics_binary(y_true, predictions)
        for k, v in ret.iteritems():
            logs[dataset + '_' + k] = v
        history.append(ret)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号