def loop_body(i, losses, predictions, predictions_lab):
     f = feature_map[i]
     l = labels[i]
     end_points = colorizer(f[:NUM_REF], tf.one_hot(l[:NUM_REF], NUM_CLUSTERS),
                            f[NUM_REF:], l[NUM_REF:])
     mean_losses = tf.reduce_mean(tf.reduce_mean(end_points['losses'], 2), 1)
     losses = tf.concat([losses, tf.expand_dims(mean_losses, 0)], 0)
     pred = end_points['predictions']
     predictions = tf.concat([predictions, tf.expand_dims(pred, 0)], 0)
     predictions_lab = tf.concat([predictions_lab, tf.expand_dims(kmeans.labels_to_lab(pred), 0)], 0)
     return i+1, losses, predictions, predictions_lab
예제 #2
0
    all_images = get_images(image_set) / 255.
    all_images_gray = all_images.mean(3)
    all_images_gray = np.array(
        [cv2.resize(img, (256, 256)) for img in all_images_gray])
    all_images_gray = np.repeat(np.expand_dims(all_images_gray, -1), 3, -1)

    # load model
    with tf.Graph().as_default() as graph:
        saver = tf.train.import_meta_graph(graph_path)

        images = graph.get_tensor_by_name('images:0')
        features = graph.get_tensor_by_name('features:0')
        annotations = tf.placeholder(tf.float32, shape=[3, 32, 32, n_colors])

        end_points = colorizer(features[0, 0:3], annotations, features[0, 3:4])
        predictions = end_points['predictions']
        temperature = end_points['temperature']

    def apply_mask(image, mask):
        return mask[:, :, 0:1] * image + (np.expand_dims(
            mask[:, :, 1:], -1) * colors[1:].reshape(1, 1, -1, 3)).sum(2)

    cv2.imshow('Reference frame', apply_mask(all_images[0], annotation_large))
    with tf.Session(graph=graph) as sess:
        saver.restore(sess, model_path)

        _annotations = np.expand_dims(annotation, 0).repeat(3, 0)
        for t in xrange(1, all_images.shape[0]):
            _images = all_images_gray[[max(t - 3, 0), max(t - 2, 0), t - 1, t]]
            _predictions = sess.run(