import os

import numpy as np
from paddle import fluid

from ltr.models.bbreg.atom import atom_resnet50, atom_resnet18
from ltr.models.siamese.siam import siamfc_alexnet
from ltr.models.siam.siam import SiamRPN_AlexNet, SiamMask_ResNet50_sharp, SiamMask_ResNet50_base
from pytracking.admin.environment import env_settings
from pytracking.features.featurebase import MultiFeatureBase
from pytracking.libs import TensorList
from pytracking.libs.paddle_utils import n2p


class ResNet18(MultiFeatureBase):
    """ResNet18 feature.
    args:
        output_layers: List of layers to output.
        net_path: Relative or absolute net path (default should be fine).
        use_gpu: Use GPU or CPU.
    """

    def __init__(self,
                 output_layers=('block2', ),
                 net_path='atom_iou',
                 use_gpu=True,
                 *args,
                 **kwargs):
        super().__init__(*args, **kwargs)

        self.output_layers = list(output_layers)
        self.use_gpu = use_gpu
        self.net_path = net_path

    def initialize(self):
        with fluid.dygraph.guard():
            if os.path.isabs(self.net_path):
                net_path_full = self.net_path
            else:
                net_path_full = os.path.join(env_settings().network_path,
                                             self.net_path)

            self.net = atom_resnet18(
                backbone_pretrained=False,
                backbone_is_test=True,
                iounet_is_test=True)

            state_dictsm, _ = fluid.load_dygraph(net_path_full)
            self.net.load_dict(state_dictsm)
            self.net.train()

            self.iou_predictor = self.net.bb_regressor

        self.layer_stride = {
            'conv0': 2,
            'conv1': 2,
            'block0': 4,
            'block1': 8,
            'block2': 16,
            'block3': 32,
            'classification': 16,
            'fc': None
        }
        self.layer_dim = {
            'conv0': 64,
            'conv1': 64,
            'block0': 64,
            'block1': 128,
            'block2': 256,
            'block3': 512,
            'classification': 256,
            'fc': None
        }

        self.iounet_feature_layers = self.net.bb_regressor_layer

        if isinstance(self.pool_stride, int) and self.pool_stride == 1:
            self.pool_stride = [1] * len(self.output_layers)

        self.feature_layers = sorted(
            list(set(self.output_layers + self.iounet_feature_layers)))

        self.mean = np.reshape([0.485, 0.456, 0.406], [1, -1, 1, 1])
        self.std = np.reshape([0.229, 0.224, 0.225], [1, -1, 1, 1])

    def free_memory(self):
        if hasattr(self, 'net'):
            del self.net
        if hasattr(self, 'iou_predictor'):
            del self.iou_predictor
        if hasattr(self, 'iounet_backbone_features'):
            del self.iounet_backbone_features
        if hasattr(self, 'iounet_features'):
            del self.iounet_features

    def dim(self):
        return TensorList([self.layer_dim[l] for l in self.output_layers])

    def stride(self):
        return TensorList([
            s * self.layer_stride[l]
            for l, s in zip(self.output_layers, self.pool_stride)
        ])

    def extract(self, im: np.ndarray, debug_save_name=None):
        with fluid.dygraph.guard():
            if debug_save_name is not None:
                np.savez(debug_save_name, im)

            im = im / 255.  # don't use im /= 255. since we don't want to alter the input
            im -= self.mean
            im /= self.std
            im = n2p(im)

            output_features = self.net.extract_features(im, self.feature_layers)

            # Store the raw resnet features which are input to iounet
            iounet_backbone_features = TensorList([
                output_features[layer] for layer in self.iounet_feature_layers
            ])
            self.iounet_backbone_features = iounet_backbone_features.numpy()

            # Store the processed features from iounet, just before pooling
            self.iounet_features = TensorList([
                f.numpy()
                for f in self.iou_predictor.get_iou_feat(
                    iounet_backbone_features)
            ])

            output = TensorList([
                output_features[layer].numpy() for layer in self.output_layers
            ])
            return output


class ResNet50(MultiFeatureBase):
    """ResNet50 feature.
    args:
        output_layers: List of layers to output.
        net_path: Relative or absolute net path (default should be fine).
        use_gpu: Use GPU or CPU.
    """

    def __init__(self,
                 output_layers=('block2', ),
                 net_path='atom_iou',
                 use_gpu=True,
                 *args,
                 **kwargs):
        super().__init__(*args, **kwargs)

        self.output_layers = list(output_layers)
        self.use_gpu = use_gpu
        self.net_path = net_path

    def initialize(self):
        with fluid.dygraph.guard():
            if os.path.isabs(self.net_path):
                net_path_full = self.net_path
            else:
                net_path_full = os.path.join(env_settings().network_path,
                                             self.net_path)

            self.net = atom_resnet50(
                backbone_pretrained=False,
                backbone_is_test=True,
                iounet_is_test=True)

            state_dictsm, _ = fluid.load_dygraph(net_path_full)
            self.net.load_dict(state_dictsm)
            self.net.train()

            self.iou_predictor = self.net.bb_regressor

        self.layer_stride = {
            'conv0': 2,
            'conv1': 2,
            'block0': 4,
            'block1': 8,
            'block2': 16,
            'block3': 32,
            'classification': 16,
            'fc': None
        }
        self.layer_dim = {
            'conv0': 64,
            'conv1': 64,
            'block0': 256,
            'block1': 512,
            'block2': 1024,
            'block3': 2048,
            'classification': 256,
            'fc': None
        }

        self.iounet_feature_layers = self.net.bb_regressor_layer

        if isinstance(self.pool_stride, int) and self.pool_stride == 1:
            self.pool_stride = [1] * len(self.output_layers)

        self.feature_layers = sorted(
            list(set(self.output_layers + self.iounet_feature_layers)))

        self.mean = np.reshape([0.485, 0.456, 0.406], [1, -1, 1, 1])
        self.std = np.reshape([0.229, 0.224, 0.225], [1, -1, 1, 1])

    def free_memory(self):
        if hasattr(self, 'net'):
            del self.net
        if hasattr(self, 'iou_predictor'):
            del self.iou_predictor
        if hasattr(self, 'iounet_backbone_features'):
            del self.iounet_backbone_features
        if hasattr(self, 'iounet_features'):
            del self.iounet_features

    def dim(self):
        return TensorList([self.layer_dim[l] for l in self.output_layers])

    def stride(self):
        return TensorList([
            s * self.layer_stride[l]
            for l, s in zip(self.output_layers, self.pool_stride)
        ])

    def extract(self, im: np.ndarray, debug_save_name=None):
        with fluid.dygraph.guard():
            if debug_save_name is not None:
                np.savez(debug_save_name, im)

            im = im / 255.  # don't use im /= 255. since we don't want to alter the input
            im -= self.mean
            im /= self.std
            im = n2p(im)

            output_features = self.net.extract_features(im, self.feature_layers)

            # Store the raw resnet features which are input to iounet
            iounet_backbone_features = TensorList([
                output_features[layer] for layer in self.iounet_feature_layers
            ])
            self.iounet_backbone_features = iounet_backbone_features.numpy()

            # Store the processed features from iounet, just before pooling
            self.iounet_features = TensorList([
                f.numpy()
                for f in self.iou_predictor.get_iou_feat(
                    iounet_backbone_features)
            ])

            output = TensorList([
                output_features[layer].numpy() for layer in self.output_layers
            ])
            return output


class SFCAlexnet(MultiFeatureBase):
    """Alexnet feature.
    args:
        output_layers: List of layers to output.
        net_path: Relative or absolute net path (default should be fine).
        use_gpu: Use GPU or CPU.
    """

    def __init__(self,
                 output_layers=('conv5', ),
                 net_path='estimator',
                 use_gpu=True,
                 *args,
                 **kwargs):
        super().__init__(*args, **kwargs)

        self.output_layers = list(output_layers)
        self.use_gpu = use_gpu
        self.net_path = net_path

    def initialize(self):
        with fluid.dygraph.guard():
            if os.path.isabs(self.net_path):
                net_path_full = self.net_path
            else:
                net_path_full = os.path.join(env_settings().network_path,
                                             self.net_path)

            self.net = siamfc_alexnet(
                backbone_pretrained=False,
                backbone_is_test=True,
                estimator_is_test=True)

            state_dictsm, _ = fluid.load_dygraph(net_path_full)
            self.net.load_dict(state_dictsm)
            self.net.train()

            self.target_estimator = self.net.target_estimator

        self.layer_stride = {'conv5': 8}
        self.layer_dim = {'conv5': 256}

        self.estimator_feature_layers = self.net.target_estimator_layer

        if isinstance(self.pool_stride, int) and self.pool_stride == 1:
            self.pool_stride = [1] * len(self.output_layers)

        self.feature_layers = sorted(
            list(set(self.output_layers + self.estimator_feature_layers)))

        self.mean = np.reshape([0., 0., 0.], [1, -1, 1, 1])
        self.std = np.reshape([1 / 255., 1 / 255., 1 / 255.], [1, -1, 1, 1])

    def free_memory(self):
        if hasattr(self, 'net'):
            del self.net
        if hasattr(self, 'target_estimator'):
            del self.target_estimator
        if hasattr(self, 'estimator_backbone_features'):
            del self.estimator_backbone_features

    def dim(self):
        return TensorList([self.layer_dim[l] for l in self.output_layers])

    def stride(self):
        return TensorList([
            s * self.layer_stride[l]
            for l, s in zip(self.output_layers, self.pool_stride)
        ])

    def extract(self, im: np.ndarray, debug_save_name=None):
        with fluid.dygraph.guard():
            if debug_save_name is not None:
                np.savez(debug_save_name, im)

            im = im / 255.  # don't use im /= 255. since we don't want to alter the input
            im -= self.mean
            im /= self.std
            im = n2p(im)

            output_features = self.net.extract_features(im, self.feature_layers)

            # Store the raw backbone features which are input to estimator
            estimator_backbone_features = TensorList([
                output_features[layer]
                for layer in self.estimator_feature_layers
            ])
            self.estimator_backbone_features = estimator_backbone_features.numpy(
            )

            output = TensorList([
                output_features[layer].numpy() for layer in self.output_layers
            ])
            return output


class SRPNAlexNet(MultiFeatureBase):
    """Alexnet feature.
    args:
        output_layers: List of layers to output.
        net_path: Relative or absolute net path (default should be fine).
        use_gpu: Use GPU or CPU.
    """

    def __init__(self,
                 net_path='estimator',
                 use_gpu=True,
                 *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.use_gpu = use_gpu
        self.net_path = net_path

    def initialize(self):
        with fluid.dygraph.guard():
            if os.path.isabs(self.net_path):
                net_path_full = self.net_path
            else:
                net_path_full = os.path.join(env_settings().network_path, self.net_path)

            self.net = SiamRPN_AlexNet(backbone_pretrained=False, is_test=True)

            state_dict, _ = fluid.load_dygraph(net_path_full)
            self.net.load_dict(state_dict)
            self.net.eval()

    def free_memory(self):
        if hasattr(self, 'net'):
            del self.net

    def extract(self, im: np.ndarray, debug_save_name=None):
        with fluid.dygraph.guard():
            if debug_save_name is not None:
                np.savez(debug_save_name, im)

            im = n2p(im)

            output_features = self.net.extract_backbone_features(im)

            # Store the raw backbone features which are input to estimator
            output = TensorList([layer.numpy() for layer in output_features])
            return output


class SMaskResNet50_base(MultiFeatureBase):
    """Resnet50-dilated feature.
    args:
        output_layers: List of layers to output.
        net_path: Relative or absolute net path (default should be fine).
        use_gpu: Use GPU or CPU.
    """

    def __init__(self,
                 net_path='estimator',
                 use_gpu=True,
                 *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.use_gpu = use_gpu
        self.net_path = net_path

    def initialize(self):
        with fluid.dygraph.guard():
            if os.path.isabs(self.net_path):
                net_path_full = self.net_path
            else:
                net_path_full = os.path.join(env_settings().network_path, self.net_path)

            self.net = SiamMask_ResNet50_base(backbone_pretrained=False, is_test=True)

            state_dict, _ = fluid.load_dygraph(net_path_full)
            self.net.load_dict(state_dict)
            self.net.eval()

    def free_memory(self):
        if hasattr(self, 'net'):
            del self.net

    def extract(self, im: np.ndarray, debug_save_name=None):
        with fluid.dygraph.guard():
            if debug_save_name is not None:
                np.savez(debug_save_name, im)

            im = n2p(im)

            output_features = self.net.extract_backbone_features(im)

            # Store the raw backbone features which are input to estimator
            output = TensorList([layer.numpy() for layer in output_features])
            return output


class SMaskResNet50_sharp(MultiFeatureBase):
    """Resnet50-dilated feature.
    args:
        output_layers: List of layers to output.
        net_path: Relative or absolute net path (default should be fine).
        use_gpu: Use GPU or CPU.
    """

    def __init__(self,
                 net_path='estimator',
                 use_gpu=True,
                 *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.use_gpu = use_gpu
        self.net_path = net_path

    def initialize(self):
        with fluid.dygraph.guard():
            if os.path.isabs(self.net_path):
                net_path_full = self.net_path
            else:
                net_path_full = os.path.join(env_settings().network_path, self.net_path)

            self.net = SiamMask_ResNet50_sharp(backbone_pretrained=False, is_test=True)

            state_dict, _ = fluid.load_dygraph(net_path_full)
            self.net.load_dict(state_dict)
            self.net.eval()

    def free_memory(self):
        if hasattr(self, 'net'):
            del self.net

    def extract(self, im: np.ndarray, debug_save_name=None):
        with fluid.dygraph.guard():
            if debug_save_name is not None:
                np.savez(debug_save_name, im)

            im = n2p(im)

            output_features = self.net.extract_backbone_features(im)

            # Store the raw backbone features which are input to estimator
            output = TensorList([layer.numpy() for layer in output_features])
            return output

[((83, 20, 83, 68), 'numpy.reshape', 'np.reshape', ({(83, 31, 83, 52): '[0.485, 0.456, 0.406]', (83, 54, 83, 67): '[1, -1, 1, 1]'}, {}), '([0.485, 0.456, 0.406], [1, -1, 1, 1])', True, 'import numpy as np\n'), ((84, 19, 84, 67), 'numpy.reshape', 'np.reshape', ({(84, 30, 84, 51): '[0.229, 0.224, 0.225]', (84, 53, 84, 66): '[1, -1, 1, 1]'}, {}), '([0.229, 0.224, 0.225], [1, -1, 1, 1])', True, 'import numpy as np\n'), ((97, 15, 97, 74), 'pytracking.libs.TensorList', 'TensorList', ({(97, 26, 97, 73): '[self.layer_dim[l] for l in self.output_layers]'}, {}), '([self.layer_dim[l] for l in self.output_layers])', False, 'from pytracking.libs import TensorList\n'), ((204, 20, 204, 68), 'numpy.reshape', 'np.reshape', ({(204, 31, 204, 52): '[0.485, 0.456, 0.406]', (204, 54, 204, 67): '[1, -1, 1, 1]'}, {}), '([0.485, 0.456, 0.406], [1, -1, 1, 1])', True, 'import numpy as np\n'), ((205, 19, 205, 67), 'numpy.reshape', 'np.reshape', ({(205, 30, 205, 51): '[0.229, 0.224, 0.225]', (205, 53, 205, 66): '[1, -1, 1, 1]'}, {}), '([0.229, 0.224, 0.225], [1, -1, 1, 1])', True, 'import numpy as np\n'), ((218, 15, 218, 74), 'pytracking.libs.TensorList', 'TensorList', ({(218, 26, 218, 73): '[self.layer_dim[l] for l in self.output_layers]'}, {}), '([self.layer_dim[l] for l in self.output_layers])', False, 'from pytracking.libs import TensorList\n'), ((307, 20, 307, 59), 'numpy.reshape', 'np.reshape', ({(307, 31, 307, 43): '[0.0, 0.0, 0.0]', (307, 45, 307, 58): '[1, -1, 1, 1]'}, {}), '([0.0, 0.0, 0.0], [1, -1, 1, 1])', True, 'import numpy as np\n'), ((308, 19, 308, 76), 'numpy.reshape', 'np.reshape', ({(308, 30, 308, 60): '[1 / 255.0, 1 / 255.0, 1 / 255.0]', (308, 62, 308, 75): '[1, -1, 1, 1]'}, {}), '([1 / 255.0, 1 / 255.0, 1 / 255.0], [1, -1, 1, 1])', True, 'import numpy as np\n'), ((319, 15, 319, 74), 'pytracking.libs.TensorList', 'TensorList', ({(319, 26, 319, 73): '[self.layer_dim[l] for l in self.output_layers]'}, {}), '([self.layer_dim[l] for l in self.output_layers])', False, 'from pytracking.libs import TensorList\n'), ((36, 13, 36, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((37, 15, 37, 43), 'os.path.isabs', 'os.path.isabs', ({(37, 29, 37, 42): 'self.net_path'}, {}), '(self.net_path)', False, 'import os\n'), ((43, 23, 46, 36), 'ltr.models.bbreg.atom.atom_resnet18', 'atom_resnet18', (), '', False, 'from ltr.models.bbreg.atom import atom_resnet50, atom_resnet18\n'), ((48, 30, 48, 63), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', ({(48, 49, 48, 62): 'net_path_full'}, {}), '(net_path_full)', False, 'from paddle import fluid\n'), ((106, 13, 106, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((113, 17, 113, 24), 'pytracking.libs.paddle_utils.n2p', 'n2p', ({(113, 21, 113, 23): 'im'}, {}), '(im)', False, 'from pytracking.libs.paddle_utils import n2p\n'), ((118, 39, 120, 14), 'pytracking.libs.TensorList', 'TensorList', ({(118, 50, 120, 13): '[output_features[layer] for layer in self.iounet_feature_layers]'}, {}), '([output_features[layer] for layer in self.iounet_feature_layers])', False, 'from pytracking.libs import TensorList\n'), ((157, 13, 157, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((158, 15, 158, 43), 'os.path.isabs', 'os.path.isabs', ({(158, 29, 158, 42): 'self.net_path'}, {}), '(self.net_path)', False, 'import os\n'), ((164, 23, 167, 36), 'ltr.models.bbreg.atom.atom_resnet50', 'atom_resnet50', (), '', False, 'from ltr.models.bbreg.atom import atom_resnet50, atom_resnet18\n'), ((169, 30, 169, 63), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', ({(169, 49, 169, 62): 'net_path_full'}, {}), '(net_path_full)', False, 'from paddle import fluid\n'), ((227, 13, 227, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((234, 17, 234, 24), 'pytracking.libs.paddle_utils.n2p', 'n2p', ({(234, 21, 234, 23): 'im'}, {}), '(im)', False, 'from pytracking.libs.paddle_utils import n2p\n'), ((239, 39, 241, 14), 'pytracking.libs.TensorList', 'TensorList', ({(239, 50, 241, 13): '[output_features[layer] for layer in self.iounet_feature_layers]'}, {}), '([output_features[layer] for layer in self.iounet_feature_layers])', False, 'from pytracking.libs import TensorList\n'), ((278, 13, 278, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((279, 15, 279, 43), 'os.path.isabs', 'os.path.isabs', ({(279, 29, 279, 42): 'self.net_path'}, {}), '(self.net_path)', False, 'import os\n'), ((285, 23, 288, 39), 'ltr.models.siamese.siam.siamfc_alexnet', 'siamfc_alexnet', (), '', False, 'from ltr.models.siamese.siam import siamfc_alexnet\n'), ((290, 30, 290, 63), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', ({(290, 49, 290, 62): 'net_path_full'}, {}), '(net_path_full)', False, 'from paddle import fluid\n'), ((328, 13, 328, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((335, 17, 335, 24), 'pytracking.libs.paddle_utils.n2p', 'n2p', ({(335, 21, 335, 23): 'im'}, {}), '(im)', False, 'from pytracking.libs.paddle_utils import n2p\n'), ((340, 42, 343, 14), 'pytracking.libs.TensorList', 'TensorList', ({(340, 53, 343, 13): '[output_features[layer] for layer in self.estimator_feature_layers]'}, {}), '([output_features[layer] for layer in self.estimator_feature_layers])', False, 'from pytracking.libs import TensorList\n'), ((371, 13, 371, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((372, 15, 372, 43), 'os.path.isabs', 'os.path.isabs', ({(372, 29, 372, 42): 'self.net_path'}, {}), '(self.net_path)', False, 'import os\n'), ((377, 23, 377, 79), 'ltr.models.siam.siam.SiamRPN_AlexNet', 'SiamRPN_AlexNet', (), '', False, 'from ltr.models.siam.siam import SiamRPN_AlexNet, SiamMask_ResNet50_sharp, SiamMask_ResNet50_base\n'), ((379, 28, 379, 61), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', ({(379, 47, 379, 60): 'net_path_full'}, {}), '(net_path_full)', False, 'from paddle import fluid\n'), ((388, 13, 388, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((392, 17, 392, 24), 'pytracking.libs.paddle_utils.n2p', 'n2p', ({(392, 21, 392, 23): 'im'}, {}), '(im)', False, 'from pytracking.libs.paddle_utils import n2p\n'), ((419, 13, 419, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((420, 15, 420, 43), 'os.path.isabs', 'os.path.isabs', ({(420, 29, 420, 42): 'self.net_path'}, {}), '(self.net_path)', False, 'import os\n'), ((425, 23, 425, 86), 'ltr.models.siam.siam.SiamMask_ResNet50_base', 'SiamMask_ResNet50_base', (), '', False, 'from ltr.models.siam.siam import SiamRPN_AlexNet, SiamMask_ResNet50_sharp, SiamMask_ResNet50_base\n'), ((427, 28, 427, 61), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', ({(427, 47, 427, 60): 'net_path_full'}, {}), '(net_path_full)', False, 'from paddle import fluid\n'), ((436, 13, 436, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((440, 17, 440, 24), 'pytracking.libs.paddle_utils.n2p', 'n2p', ({(440, 21, 440, 23): 'im'}, {}), '(im)', False, 'from pytracking.libs.paddle_utils import n2p\n'), ((467, 13, 467, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((468, 15, 468, 43), 'os.path.isabs', 'os.path.isabs', ({(468, 29, 468, 42): 'self.net_path'}, {}), '(self.net_path)', False, 'import os\n'), ((473, 23, 473, 87), 'ltr.models.siam.siam.SiamMask_ResNet50_sharp', 'SiamMask_ResNet50_sharp', (), '', False, 'from ltr.models.siam.siam import SiamRPN_AlexNet, SiamMask_ResNet50_sharp, SiamMask_ResNet50_base\n'), ((475, 28, 475, 61), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', ({(475, 47, 475, 60): 'net_path_full'}, {}), '(net_path_full)', False, 'from paddle import fluid\n'), ((484, 13, 484, 34), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ({}, {}), '()', False, 'from paddle import fluid\n'), ((488, 17, 488, 24), 'pytracking.libs.paddle_utils.n2p', 'n2p', ({(488, 21, 488, 23): 'im'}, {}), '(im)', False, 'from pytracking.libs.paddle_utils import n2p\n'), ((108, 16, 108, 45), 'numpy.savez', 'np.savez', ({(108, 25, 108, 40): 'debug_save_name', (108, 42, 108, 44): 'im'}, {}), '(debug_save_name, im)', True, 'import numpy as np\n'), ((229, 16, 229, 45), 'numpy.savez', 'np.savez', ({(229, 25, 229, 40): 'debug_save_name', (229, 42, 229, 44): 'im'}, {}), '(debug_save_name, im)', True, 'import numpy as np\n'), ((330, 16, 330, 45), 'numpy.savez', 'np.savez', ({(330, 25, 330, 40): 'debug_save_name', (330, 42, 330, 44): 'im'}, {}), '(debug_save_name, im)', True, 'import numpy as np\n'), ((390, 16, 390, 45), 'numpy.savez', 'np.savez', ({(390, 25, 390, 40): 'debug_save_name', (390, 42, 390, 44): 'im'}, {}), '(debug_save_name, im)', True, 'import numpy as np\n'), ((438, 16, 438, 45), 'numpy.savez', 'np.savez', ({(438, 25, 438, 40): 'debug_save_name', (438, 42, 438, 44): 'im'}, {}), '(debug_save_name, im)', True, 'import numpy as np\n'), ((486, 16, 486, 45), 'numpy.savez', 'np.savez', ({(486, 25, 486, 40): 'debug_save_name', (486, 42, 486, 44): 'im'}, {}), '(debug_save_name, im)', True, 'import numpy as np\n'), ((40, 45, 40, 59), 'pytracking.admin.environment.env_settings', 'env_settings', ({}, {}), '()', False, 'from pytracking.admin.environment import env_settings\n'), ((161, 45, 161, 59), 'pytracking.admin.environment.env_settings', 'env_settings', ({}, {}), '()', False, 'from pytracking.admin.environment import env_settings\n'), ((282, 45, 282, 59), 'pytracking.admin.environment.env_settings', 'env_settings', ({}, {}), '()', False, 'from pytracking.admin.environment import env_settings\n'), ((375, 45, 375, 59), 'pytracking.admin.environment.env_settings', 'env_settings', ({}, {}), '()', False, 'from pytracking.admin.environment import env_settings\n'), ((423, 45, 423, 59), 'pytracking.admin.environment.env_settings', 'env_settings', ({}, {}), '()', False, 'from pytracking.admin.environment import env_settings\n'), ((471, 45, 471, 59), 'pytracking.admin.environment.env_settings', 'env_settings', ({}, {}), '()', False, 'from pytracking.admin.environment import env_settings\n')]