Demo entry 6733266

First example

   

Submitted by anonymous on Apr 17, 2018 at 13:00
Language: Python. Code size: 994 Bytes.

import tensorflow as tf
import numpy as np


def intersection_over_union(prediction, labels):
    pred = tf.argmax(prediction, axis=3)
    labl = tf.constant(labels)
    iou, conf_mat = tf.metrics.mean_iou(labl, pred, num_classes=2)
    return iou

y_pred0 = np.array([   [ [[0.9,0.1],[0.9,0.1],[0.9,0.1],[0.9,0.1]], [[0.2,0.8],[0.2,0.8],[0.2,0.8],[0.9,0.1]], [[0.9,0.1],[0.9,0.1],[0.2,0.8],[0.9,0.1]], [[0.9,0.1],[0.9,0.1],[0.2,0.8],[0.9,0.1]] ],   [ [[0.9,0.1],[0.9,0.1],[0.9,0.1],[0.9,0.1]], [[0.2,0.8],[0.2,0.8],[0.2,0.8],[0.9,0.1]], [[0.9,0.1],[0.9,0.1],[0.2,0.8],[0.9,0.1]], [[0.9,0.1],[0.9,0.1],[0.2,0.8],[0.9,0.1]] ]    ])
y_pred1 = tf.constant(y_pred0)

y_label = np.array([[[1,0,1,0],[1,0,1,0],[0,0,1,0],[0,0,1,0]], [[1,0,1,0],[1,0,1,0],[0,0,1,0],[0,0,1,0]]])

mean__iou = intersection_over_union(y_pred1, y_label)

sess = tf.Session()
sess.run(tf.local_variables_initializer())
sess.run(tf.global_variables_initializer())

res = sess.run(mean__iou)

print(res)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).