# Copyright (c) 2023, NVIDIA CORPORATION.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""test input encoder."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import numpy as np
import tensorflow as tf
from nvidia_tao_tf1.cv.ssd.box_coder.input_encoder import SSDInputEncoder
from nvidia_tao_tf1.cv.ssd.box_coder.ssd_input_encoder import SSDInputEncoderNP


def test_input_encoder_np():
    encoder = SSDInputEncoderNP(img_height=300,
                                img_width=300,
                                n_classes=3,
                                predictor_sizes=[(1, 2), (1, 2)],
                                scales=[0.1, 0.88, 1.05],
                                aspect_ratios_per_layer=[[1.0, 2.0, 0.5, 3.0, 1.0/3.0],
                                                         [1.0, 2.0, 0.5]],
                                two_boxes_for_ar1=True,
                                steps=None,
                                offsets=None,
                                clip_boxes=False,
                                variances=[0.1, 0.1, 0.2, 0.2],
                                pos_iou_threshold=0.5,
                                neg_iou_limit=0.5,
                                normalize_coords=True)

    gt = np.array([[0, 10, 10, 100, 100], [1, 2, 3, 6, 8]])

    # expected value from GitHub original repo based on Numpy
    expected = '''np.array(
       [[  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.1       ,   0.1       ,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.29664794,   0.29664794,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.07071068,   0.14142136,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.17320508,   0.05773503,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.05773503,   0.17320508,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.1       ,   0.1       ,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.29664794,   0.29664794,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.07071068,   0.14142136,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.17320508,   0.05773503,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.05773503,   0.17320508,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.88      ,   0.88      ,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  0.        ,   1.        ,   0.        ,  -2.46207404,
         -5.01084082, -21.38983255, -20.27411479,   0.25      ,
          0.5       ,   0.96124919,   0.96124919,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -1.07137391,
         -2.54451304,  -3.64782921,  -7.11356512,   0.25      ,
          0.5       ,   0.62225397,   1.24450793,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.88      ,   0.88      ,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.96124919,   0.96124919,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.62225397,   1.24450793,   0.1       ,
          0.1       ,   0.2       ,   0.2       ]])'''

    assert np.max(abs(encoder(gt)[:, :-1] - eval(expected)[:, :-1])) < 1e-5


def test_input_encoder_multimatch_np():
    encoder = SSDInputEncoderNP(img_height=300,
                                img_width=300,
                                n_classes=3,
                                predictor_sizes=[(1, 10), (1, 10)],
                                scales=[0.1, 0.88, 1.05],
                                aspect_ratios_per_layer=[[2.0],
                                                         [2.0]],
                                two_boxes_for_ar1=True,
                                steps=None,
                                offsets=None,
                                clip_boxes=False,
                                variances=[0.1, 0.1, 0.2, 0.2],
                                pos_iou_threshold=0.01,
                                neg_iou_limit=0.01,
                                normalize_coords=True)

    raw_gt = '''np.array(
      [[1, 0, 139, 36, 171],
       [1, 23, 139, 66, 171],
       [0, 50, 139, 306, 171]])'''

    gt = eval(raw_gt)

    # expected value from GitHub original repo based on Numpy
    expected = '''np.array(
       [[  0.        ,   1.        ,   0.        ,   0.70710678,
          2.3570226 ,  -0.82126017,   2.05556056,   0.05      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  0.        ,   1.        ,   0.        ,  -0.11785113,
          2.3570226 ,   0.06714572,   2.05556056,   0.15      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  0.        ,   1.        ,   0.        ,  -7.18891894,
          2.3570226 ,   0.06714572,   2.05556056,   0.25      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  17.20626501,
          2.3570226 ,   8.98703236,   2.05556056,   0.35      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  10.1351972 ,
          2.3570226 ,   8.98703236,   2.05556056,   0.45      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   3.06412939,
          2.3570226 ,   8.98703236,   2.05556056,   0.55      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -4.00693843,
          2.3570226 ,   8.98703236,   2.05556056,   0.65      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        , -11.07800624,
          2.3570226 ,   8.98703236,   2.05556056,   0.75      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        , -18.14907405,
          2.3570226 ,   8.98703236,   2.05556056,   0.85      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        , -25.22014186,
          2.3570226 ,   8.98703236,   2.05556056,   0.95      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   4.36584869,
          0.26784348,  -1.88672624,  -8.81819805,   0.05      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   3.56231825,
          0.26784348,  -1.88672624,  -8.81819805,   0.15      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   2.75878782,
          0.26784348,  -1.88672624,  -8.81819805,   0.25      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   1.95525739,
          0.26784348,  -1.88672624,  -8.81819805,   0.35      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   1.15172695,
          0.26784348,  -1.88672624,  -8.81819805,   0.45      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.34819652,
          0.26784348,  -1.88672624,  -8.81819805,   0.55      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -0.45533391,
          0.26784348,  -1.88672624,  -8.81819805,   0.65      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -1.25886435,
          0.26784348,  -1.88672624,  -8.81819805,   0.75      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -2.06239478,
          0.26784348,  -1.88672624,  -8.81819805,   0.85      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -2.86592521,
          0.26784348,  -1.88672624,  -8.81819805,   0.95      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ]])'''

    assert np.max(abs(encoder(gt)[:, :-1] - eval(expected)[:, :-1])) < 1e-5


def test_input_encoder():
    encoder = SSDInputEncoder(img_height=300,
                              img_width=300,
                              n_classes=3,
                              predictor_sizes=[(1, 2), (1, 2)],
                              scales=[0.1, 0.88, 1.05],
                              aspect_ratios_per_layer=[[1.0, 2.0, 0.5, 3.0, 1.0/3.0],
                                                       [1.0, 2.0, 0.5]],
                              two_boxes_for_ar1=True,
                              steps=None,
                              offsets=None,
                              clip_boxes=False,
                              variances=[0.1, 0.1, 0.2, 0.2],
                              pos_iou_threshold=0.5,
                              neg_iou_limit=0.5,
                              normalize_coords=True)

    gt = tf.constant(np.array([[0, 10, 10, 100, 100], [1, 2, 3, 6, 8]]))

    # expected value from GitHub original repo based on Numpy
    expected = '''np.array(
       [[ 1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.1       ,   0.1       ,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.29664794,   0.29664794,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.07071068,   0.14142136,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.17320508,   0.05773503,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.05773503,   0.17320508,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.1       ,   0.1       ,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.29664794,   0.29664794,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.07071068,   0.14142136,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.17320508,   0.05773503,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.05773503,   0.17320508,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   0.88      ,   0.88      ,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  0.        ,   1.        ,   0.        ,  -2.46207404,
         -5.01084082, -21.38983255, -20.27411479,   0.25      ,
          0.5       ,   0.96124919,   0.96124919,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.25      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -1.07137391,
         -2.54451304,  -3.64782921,  -7.11356512,   0.25      ,
          0.5       ,   0.62225397,   1.24450793,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.88      ,   0.88      ,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.96124919,   0.96124919,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.        ,
          0.        ,   0.        ,   0.        ,   0.75      ,
          0.5       ,   0.62225397,   1.24450793,   0.1       ,
          0.1       ,   0.2       ,   0.2       ]])'''

    with tf.Session() as sess:
        assert np.max(abs(sess.run(encoder([gt]))[:, :, :-1] - eval(expected)[:, :-1])) < 1e-5


def test_input_encoder_multimatch():
    encoder = SSDInputEncoder(img_height=300,
                              img_width=300,
                              n_classes=3,
                              predictor_sizes=[(1, 10), (1, 10)],
                              scales=[0.1, 0.88, 1.05],
                              aspect_ratios_per_layer=[[2.0],
                                                       [2.0]],
                              two_boxes_for_ar1=True,
                              steps=None,
                              offsets=None,
                              clip_boxes=False,
                              variances=[0.1, 0.1, 0.2, 0.2],
                              pos_iou_threshold=0.01,
                              neg_iou_limit=0.01,
                              normalize_coords=True)

    raw_gt = '''np.array(
      [[1, 0, 139, 36, 171],
       [1, 23, 139, 66, 171],
       [0, 50, 139, 306, 171]])'''

    gt = tf.constant(eval(raw_gt))

    # expected value from GitHub original repo based on Numpy
    expected = '''np.array(
       [[  0.        ,   1.        ,   0.        ,   0.70710678,
          2.3570226 ,  -0.82126017,   2.05556056,   0.05      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  0.        ,   1.        ,   0.        ,  -0.11785113,
          2.3570226 ,   0.06714572,   2.05556056,   0.15      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  0.        ,   1.        ,   0.        ,  -7.18891894,
          2.3570226 ,   0.06714572,   2.05556056,   0.25      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  17.20626501,
          2.3570226 ,   8.98703236,   2.05556056,   0.35      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  10.1351972 ,
          2.3570226 ,   8.98703236,   2.05556056,   0.45      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   3.06412939,
          2.3570226 ,   8.98703236,   2.05556056,   0.55      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -4.00693843,
          2.3570226 ,   8.98703236,   2.05556056,   0.65      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        , -11.07800624,
          2.3570226 ,   8.98703236,   2.05556056,   0.75      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        , -18.14907405,
          2.3570226 ,   8.98703236,   2.05556056,   0.85      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        , -25.22014186,
          2.3570226 ,   8.98703236,   2.05556056,   0.95      ,
          0.5       ,   0.14142136,   0.07071068,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   4.36584869,
          0.26784348,  -1.88672624,  -8.81819805,   0.05      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   3.56231825,
          0.26784348,  -1.88672624,  -8.81819805,   0.15      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   2.75878782,
          0.26784348,  -1.88672624,  -8.81819805,   0.25      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   1.95525739,
          0.26784348,  -1.88672624,  -8.81819805,   0.35      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   1.15172695,
          0.26784348,  -1.88672624,  -8.81819805,   0.45      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,   0.34819652,
          0.26784348,  -1.88672624,  -8.81819805,   0.55      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -0.45533391,
          0.26784348,  -1.88672624,  -8.81819805,   0.65      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -1.25886435,
          0.26784348,  -1.88672624,  -8.81819805,   0.75      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -2.06239478,
          0.26784348,  -1.88672624,  -8.81819805,   0.85      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ],
       [  1.        ,   0.        ,   0.        ,  -2.86592521,
          0.26784348,  -1.88672624,  -8.81819805,   0.95      ,
          0.5       ,   1.24450793,   0.62225397,   0.1       ,
          0.1       ,   0.2       ,   0.2       ]])'''

    with tf.Session() as sess:
        assert np.max(abs(sess.run(encoder([gt]))[:, :, :-1] - eval(expected)[:, :-1])) < 1e-5
