# Path: annotate/annotate_attributes.py
# ATTRIBUTE_GROUPS = [
#     ATTRIBUTE_GROUP_ROAD_TYPE,
#     ATTRIBUTE_GROUP_INTERSECTION,
#     ATTRIBUTE_GROUP_DIRECTION,
#     ATTRIBUTE_GROUP_LANE_COUNT,
#     ATTRIBUTE_GROUP_CURVE,
#     ATTRIBUTE_GROUP_SPACE_FRONT,
#     ATTRIBUTE_GROUP_SPACE_LEFT,
#     ATTRIBUTE_GROUP_SPACE_RIGHT,
#     ATTRIBUTE_GROUP_OFFROAD
# ]
# 
# Path: lib/util.py
# def to_numpy(var):
#     #if ia.is_numpy_array(var):
#     if isinstance(var, (np.ndarray, np.generic)):
#         return var
#     else:
#         return var.data.cpu().numpy()
# 
# Path: lib/util.py
# def template_match(needle, haystack):
# def compress_to_jpg(img):
# def compress_img(img, method):
# def decompress_img(img_compressed):
# def draw_image(img, other_img, x, y, copy=True, raise_if_oob=False):
# def draw_point(img, y, x, size=5, color=[255, 0, 0], alpha=1.0, copy=True):
# def draw_line(img, y1, x1, y2, x2, color=[0, 255, 0], alpha=1.0, thickness=1, clip_result=True, copy=True):
# def draw_direction_circle(img, y, x, r_inner, r_outer, angle_start, angle_end, color_border=[0, 255, 0], color_fill=[0, 200, 0], alpha=1.0):
# def draw_text(img, y, x, text, color=[0, 255, 0], size=25):
# def to_variable(inputs, volatile=False, requires_grad=True):
# def to_variables(inputs, volatile=False, requires_grad=True):
# def to_cuda(inputs, gpu=Config.GPU):
# def to_numpy(var):
# def draw_heatmap_overlay(img, heatmap, alpha=0.5):
# def create_2d_gaussian_old(size, fwhm=3, center=None):
# def create_2d_gaussian(size, sigma):
# FONT_CACHE = dict()


import sys
import os
import train
import imgaug as ia
import numpy as np
from annotate.annotate_attributes import ATTRIBUTE_GROUPS
from lib.util import to_numpy
from lib import util
    grids_pred = to_numpy(outputs_grids_pred)[0]
    atts_pred = to_numpy(outputs_atts_pred)[0]
    multiactions_pred = to_numpy(outputs_multiactions_pred)[0]
    flow_pred = to_numpy(outputs_flow_pred)[0]
    canny_pred = to_numpy(outputs_canny_pred)[0]
    flipped_pred = to_numpy(outputs_flipped_pred)[0]

    image = (np.squeeze(image).transpose(1, 2, 0) * 255).astype(np.uint8)
    ae_pred = (np.squeeze(ae_pred).transpose(1, 2, 0) * 255).astype(np.uint8)
    grids_gt = (np.squeeze(grids_gt).transpose(1, 2, 0) * 255).astype(np.uint8)
    grids_pred = (np.squeeze(grids_pred).transpose(1, 2, 0) * 255).astype(np.uint8)
    atts_gt = np.squeeze(atts_gt)
    atts_pred = np.squeeze(atts_pred)
    multiactions_gt = np.squeeze(multiactions_gt)
    multiactions_pred = np.squeeze(multiactions_pred)
    flow_gt = (flow_gt.transpose(1, 2, 0) * 255).astype(np.uint8)
    flow_pred = (flow_pred.transpose(1, 2, 0) * 255).astype(np.uint8)
    canny_gt = (canny_gt.transpose(1, 2, 0) * 255).astype(np.uint8)
    canny_pred = (canny_pred.transpose(1, 2, 0) * 255).astype(np.uint8)

    #print(image.shape, grid_gt.shape, grid_pred.shape)

    h, w = int(image.shape[0]*0.5), int(image.shape[1]*0.5)
    #h, w = image.shape[0:2]
    image_rs = ia.imresize_single_image(image, (h, w), interpolation="cubic")
    grids_vis = []
    for i in xrange(grids_gt.shape[2]):
        grid_gt_rs = ia.imresize_single_image(grids_gt[..., i][:, :, np.newaxis], (h, w), interpolation="cubic")
        grid_pred_rs = ia.imresize_single_image(grids_pred[..., i][:, :, np.newaxis], (h, w), interpolation="cubic")
        grid_gt_hm = util.draw_heatmap_overlay(image_rs, np.squeeze(grid_gt_rs) / 255)

# Path: annotate/annotate_attributes.py
# ATTRIBUTE_GROUPS = [
#     ATTRIBUTE_GROUP_ROAD_TYPE,
#     ATTRIBUTE_GROUP_INTERSECTION,
#     ATTRIBUTE_GROUP_DIRECTION,
#     ATTRIBUTE_GROUP_LANE_COUNT,
#     ATTRIBUTE_GROUP_CURVE,
#     ATTRIBUTE_GROUP_SPACE_FRONT,
#     ATTRIBUTE_GROUP_SPACE_LEFT,
#     ATTRIBUTE_GROUP_SPACE_RIGHT,
#     ATTRIBUTE_GROUP_OFFROAD
# ]
# 
# Path: lib/util.py
# def to_numpy(var):
#     #if ia.is_numpy_array(var):
#     if isinstance(var, (np.ndarray, np.generic)):
#         return var
#     else:
#         return var.data.cpu().numpy()
# 
# Path: lib/util.py
# def template_match(needle, haystack):
# def compress_to_jpg(img):
# def compress_img(img, method):
# def decompress_img(img_compressed):
# def draw_image(img, other_img, x, y, copy=True, raise_if_oob=False):
# def draw_point(img, y, x, size=5, color=[255, 0, 0], alpha=1.0, copy=True):
# def draw_line(img, y1, x1, y2, x2, color=[0, 255, 0], alpha=1.0, thickness=1, clip_result=True, copy=True):
# def draw_direction_circle(img, y, x, r_inner, r_outer, angle_start, angle_end, color_border=[0, 255, 0], color_fill=[0, 200, 0], alpha=1.0):
# def draw_text(img, y, x, text, color=[0, 255, 0], size=25):
# def to_variable(inputs, volatile=False, requires_grad=True):
# def to_variables(inputs, volatile=False, requires_grad=True):
# def to_cuda(inputs, gpu=Config.GPU):
# def to_numpy(var):
# def draw_heatmap_overlay(img, heatmap, alpha=0.5):
# def create_2d_gaussian_old(size, fwhm=3, center=None):
# def create_2d_gaussian(size, sigma):
# FONT_CACHE = dict()


# Path: train_semisupervised/visualization.py
import sys
import os
import train
import imgaug as ia
import numpy as np
from annotate.annotate_attributes import ATTRIBUTE_GROUPS
from lib.util import to_numpy
from lib import util

    grids_pred = to_numpy(outputs_grids_pred)[0]
    atts_pred = to_numpy(outputs_atts_pred)[0]
    multiactions_pred = to_numpy(outputs_multiactions_pred)[0]
    flow_pred = to_numpy(outputs_flow_pred)[0]
    canny_pred = to_numpy(outputs_canny_pred)[0]
    flipped_pred = to_numpy(outputs_flipped_pred)[0]

    image = (np.squeeze(image).transpose(1, 2, 0) * 255).astype(np.uint8)
    ae_pred = (np.squeeze(ae_pred).transpose(1, 2, 0) * 255).astype(np.uint8)
    grids_gt = (np.squeeze(grids_gt).transpose(1, 2, 0) * 255).astype(np.uint8)
    grids_pred = (np.squeeze(grids_pred).transpose(1, 2, 0) * 255).astype(np.uint8)
    atts_gt = np.squeeze(atts_gt)
    atts_pred = np.squeeze(atts_pred)
    multiactions_gt = np.squeeze(multiactions_gt)
    multiactions_pred = np.squeeze(multiactions_pred)
    flow_gt = (flow_gt.transpose(1, 2, 0) * 255).astype(np.uint8)
    flow_pred = (flow_pred.transpose(1, 2, 0) * 255).astype(np.uint8)
    canny_gt = (canny_gt.transpose(1, 2, 0) * 255).astype(np.uint8)
    canny_pred = (canny_pred.transpose(1, 2, 0) * 255).astype(np.uint8)

    #print(image.shape, grid_gt.shape, grid_pred.shape)

    h, w = int(image.shape[0]*0.5), int(image.shape[1]*0.5)
    #h, w = image.shape[0:2]
    image_rs = ia.imresize_single_image(image, (h, w), interpolation="cubic")
    grids_vis = []
    for i in xrange(grids_gt.shape[2]):
        grid_gt_rs = ia.imresize_single_image(grids_gt[..., i][:, :, np.newaxis], (h, w), interpolation="cubic")
        grid_pred_rs = ia.imresize_single_image(grids_pred[..., i][:, :, np.newaxis], (h, w), interpolation="cubic")
        grid_gt_hm = util.draw_heatmap_overlay(image_rs, np.squeeze(grid_gt_rs) / 255)

        grid_pred_hm = util.draw_heatmap_overlay(image_rs, np.squeeze(grid_pred_rs) / 255)