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

[((2621, 2669), 'numpy.reshape', 'np.reshape', (['[0.485, 0.456, 0.406]', '[1, -1, 1, 1]'], {}), '([0.485, 0.456, 0.406], [1, -1, 1, 1])\n', (2631, 2669), True, 'import numpy as np\n'), ((2690, 2738), 'numpy.reshape', 'np.reshape', (['[0.229, 0.224, 0.225]', '[1, -1, 1, 1]'], {}), '([0.229, 0.224, 0.225], [1, -1, 1, 1])\n', (2700, 2738), True, 'import numpy as np\n'), ((3133, 3192), 'pytracking.libs.TensorList', 'TensorList', (['[self.layer_dim[l] for l in self.output_layers]'], {}), '([self.layer_dim[l] for l in self.output_layers])\n', (3143, 3192), False, 'from pytracking.libs import TensorList\n'), ((6700, 6748), 'numpy.reshape', 'np.reshape', (['[0.485, 0.456, 0.406]', '[1, -1, 1, 1]'], {}), '([0.485, 0.456, 0.406], [1, -1, 1, 1])\n', (6710, 6748), True, 'import numpy as np\n'), ((6769, 6817), 'numpy.reshape', 'np.reshape', (['[0.229, 0.224, 0.225]', '[1, -1, 1, 1]'], {}), '([0.229, 0.224, 0.225], [1, -1, 1, 1])\n', (6779, 6817), True, 'import numpy as np\n'), ((7212, 7271), 'pytracking.libs.TensorList', 'TensorList', (['[self.layer_dim[l] for l in self.output_layers]'], {}), '([self.layer_dim[l] for l in self.output_layers])\n', (7222, 7271), False, 'from pytracking.libs import TensorList\n'), ((10362, 10404), 'numpy.reshape', 'np.reshape', (['[0.0, 0.0, 0.0]', '[1, -1, 1, 1]'], {}), '([0.0, 0.0, 0.0], [1, -1, 1, 1])\n', (10372, 10404), True, 'import numpy as np\n'), ((10422, 10482), 'numpy.reshape', 'np.reshape', (['[1 / 255.0, 1 / 255.0, 1 / 255.0]', '[1, -1, 1, 1]'], {}), '([1 / 255.0, 1 / 255.0, 1 / 255.0], [1, -1, 1, 1])\n', (10432, 10482), True, 'import numpy as np\n'), ((10802, 10861), 'pytracking.libs.TensorList', 'TensorList', (['[self.layer_dim[l] for l in self.output_layers]'], {}), '([self.layer_dim[l] for l in self.output_layers])\n', (10812, 10861), False, 'from pytracking.libs import TensorList\n'), ((1123, 1144), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (1142, 1144), False, 'from paddle import fluid\n'), ((1162, 1190), 'os.path.isabs', 'os.path.isabs', (['self.net_path'], {}), '(self.net_path)\n', (1175, 1190), False, 'import os\n'), ((1420, 1508), 'ltr.models.bbreg.atom.atom_resnet18', 'atom_resnet18', ([], {'backbone_pretrained': '(False)', 'backbone_is_test': '(True)', 'iounet_is_test': '(True)'}), '(backbone_pretrained=False, backbone_is_test=True,\n    iounet_is_test=True)\n', (1433, 1508), False, 'from ltr.models.bbreg.atom import atom_resnet50, atom_resnet18\n'), ((1590, 1623), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', (['net_path_full'], {}), '(net_path_full)\n', (1608, 1623), False, 'from paddle import fluid\n'), ((3442, 3463), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (3461, 3463), False, 'from paddle import fluid\n'), ((3725, 3732), 'pytracking.libs.paddle_utils.n2p', 'n2p', (['im'], {}), '(im)\n', (3728, 3732), False, 'from pytracking.libs.paddle_utils import n2p\n'), ((3930, 4006), 'pytracking.libs.TensorList', 'TensorList', (['[output_features[layer] for layer in self.iounet_feature_layers]'], {}), '([output_features[layer] for layer in self.iounet_feature_layers])\n', (3940, 4006), False, 'from pytracking.libs import TensorList\n'), ((5199, 5220), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (5218, 5220), False, 'from paddle import fluid\n'), ((5238, 5266), 'os.path.isabs', 'os.path.isabs', (['self.net_path'], {}), '(self.net_path)\n', (5251, 5266), False, 'import os\n'), ((5496, 5584), 'ltr.models.bbreg.atom.atom_resnet50', 'atom_resnet50', ([], {'backbone_pretrained': '(False)', 'backbone_is_test': '(True)', 'iounet_is_test': '(True)'}), '(backbone_pretrained=False, backbone_is_test=True,\n    iounet_is_test=True)\n', (5509, 5584), False, 'from ltr.models.bbreg.atom import atom_resnet50, atom_resnet18\n'), ((5666, 5699), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', (['net_path_full'], {}), '(net_path_full)\n', (5684, 5699), False, 'from paddle import fluid\n'), ((7521, 7542), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (7540, 7542), False, 'from paddle import fluid\n'), ((7804, 7811), 'pytracking.libs.paddle_utils.n2p', 'n2p', (['im'], {}), '(im)\n', (7807, 7811), False, 'from pytracking.libs.paddle_utils import n2p\n'), ((8009, 8085), 'pytracking.libs.TensorList', 'TensorList', (['[output_features[layer] for layer in self.iounet_feature_layers]'], {}), '([output_features[layer] for layer in self.iounet_feature_layers])\n', (8019, 8085), False, 'from pytracking.libs import TensorList\n'), ((9279, 9300), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (9298, 9300), False, 'from paddle import fluid\n'), ((9318, 9346), 'os.path.isabs', 'os.path.isabs', (['self.net_path'], {}), '(self.net_path)\n', (9331, 9346), False, 'import os\n'), ((9576, 9668), 'ltr.models.siamese.siam.siamfc_alexnet', 'siamfc_alexnet', ([], {'backbone_pretrained': '(False)', 'backbone_is_test': '(True)', 'estimator_is_test': '(True)'}), '(backbone_pretrained=False, backbone_is_test=True,\n    estimator_is_test=True)\n', (9590, 9668), False, 'from ltr.models.siamese.siam import siamfc_alexnet\n'), ((9750, 9783), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', (['net_path_full'], {}), '(net_path_full)\n', (9768, 9783), False, 'from paddle import fluid\n'), ((11111, 11132), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (11130, 11132), False, 'from paddle import fluid\n'), ((11394, 11401), 'pytracking.libs.paddle_utils.n2p', 'n2p', (['im'], {}), '(im)\n', (11397, 11401), False, 'from pytracking.libs.paddle_utils import n2p\n'), ((11607, 11686), 'pytracking.libs.TensorList', 'TensorList', (['[output_features[layer] for layer in self.estimator_feature_layers]'], {}), '([output_features[layer] for layer in self.estimator_feature_layers])\n', (11617, 11686), False, 'from pytracking.libs import TensorList\n'), ((12528, 12549), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (12547, 12549), False, 'from paddle import fluid\n'), ((12567, 12595), 'os.path.isabs', 'os.path.isabs', (['self.net_path'], {}), '(self.net_path)\n', (12580, 12595), False, 'import os\n'), ((12779, 12835), 'ltr.models.siam.siam.SiamRPN_AlexNet', 'SiamRPN_AlexNet', ([], {'backbone_pretrained': '(False)', 'is_test': '(True)'}), '(backbone_pretrained=False, is_test=True)\n', (12794, 12835), False, 'from ltr.models.siam.siam import SiamRPN_AlexNet, SiamMask_ResNet50_sharp, SiamMask_ResNet50_base\n'), ((12867, 12900), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', (['net_path_full'], {}), '(net_path_full)\n', (12885, 12900), False, 'from paddle import fluid\n'), ((13142, 13163), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (13161, 13163), False, 'from paddle import fluid\n'), ((13277, 13284), 'pytracking.libs.paddle_utils.n2p', 'n2p', (['im'], {}), '(im)\n', (13280, 13284), False, 'from pytracking.libs.paddle_utils import n2p\n'), ((14091, 14112), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (14110, 14112), False, 'from paddle import fluid\n'), ((14130, 14158), 'os.path.isabs', 'os.path.isabs', (['self.net_path'], {}), '(self.net_path)\n', (14143, 14158), False, 'import os\n'), ((14342, 14405), 'ltr.models.siam.siam.SiamMask_ResNet50_base', 'SiamMask_ResNet50_base', ([], {'backbone_pretrained': '(False)', 'is_test': '(True)'}), '(backbone_pretrained=False, is_test=True)\n', (14364, 14405), False, 'from ltr.models.siam.siam import SiamRPN_AlexNet, SiamMask_ResNet50_sharp, SiamMask_ResNet50_base\n'), ((14437, 14470), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', (['net_path_full'], {}), '(net_path_full)\n', (14455, 14470), False, 'from paddle import fluid\n'), ((14712, 14733), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (14731, 14733), False, 'from paddle import fluid\n'), ((14847, 14854), 'pytracking.libs.paddle_utils.n2p', 'n2p', (['im'], {}), '(im)\n', (14850, 14854), False, 'from pytracking.libs.paddle_utils import n2p\n'), ((15662, 15683), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (15681, 15683), False, 'from paddle import fluid\n'), ((15701, 15729), 'os.path.isabs', 'os.path.isabs', (['self.net_path'], {}), '(self.net_path)\n', (15714, 15729), False, 'import os\n'), ((15913, 15977), 'ltr.models.siam.siam.SiamMask_ResNet50_sharp', 'SiamMask_ResNet50_sharp', ([], {'backbone_pretrained': '(False)', 'is_test': '(True)'}), '(backbone_pretrained=False, is_test=True)\n', (15936, 15977), False, 'from ltr.models.siam.siam import SiamRPN_AlexNet, SiamMask_ResNet50_sharp, SiamMask_ResNet50_base\n'), ((16009, 16042), 'paddle.fluid.load_dygraph', 'fluid.load_dygraph', (['net_path_full'], {}), '(net_path_full)\n', (16027, 16042), False, 'from paddle import fluid\n'), ((16284, 16305), 'paddle.fluid.dygraph.guard', 'fluid.dygraph.guard', ([], {}), '()\n', (16303, 16305), False, 'from paddle import fluid\n'), ((16419, 16426), 'pytracking.libs.paddle_utils.n2p', 'n2p', (['im'], {}), '(im)\n', (16422, 16426), False, 'from pytracking.libs.paddle_utils import n2p\n'), ((3527, 3556), 'numpy.savez', 'np.savez', (['debug_save_name', 'im'], {}), '(debug_save_name, im)\n', (3535, 3556), True, 'import numpy as np\n'), ((7606, 7635), 'numpy.savez', 'np.savez', (['debug_save_name', 'im'], {}), '(debug_save_name, im)\n', (7614, 7635), True, 'import numpy as np\n'), ((11196, 11225), 'numpy.savez', 'np.savez', (['debug_save_name', 'im'], {}), '(debug_save_name, im)\n', (11204, 11225), True, 'import numpy as np\n'), ((13227, 13256), 'numpy.savez', 'np.savez', (['debug_save_name', 'im'], {}), '(debug_save_name, im)\n', (13235, 13256), True, 'import numpy as np\n'), ((14797, 14826), 'numpy.savez', 'np.savez', (['debug_save_name', 'im'], {}), '(debug_save_name, im)\n', (14805, 14826), True, 'import numpy as np\n'), ((16369, 16398), 'numpy.savez', 'np.savez', (['debug_save_name', 'im'], {}), '(debug_save_name, im)\n', (16377, 16398), True, 'import numpy as np\n'), ((1304, 1318), 'pytracking.admin.environment.env_settings', 'env_settings', ([], {}), '()\n', (1316, 1318), False, 'from pytracking.admin.environment import env_settings\n'), ((5380, 5394), 'pytracking.admin.environment.env_settings', 'env_settings', ([], {}), '()\n', (5392, 5394), False, 'from pytracking.admin.environment import env_settings\n'), ((9460, 9474), 'pytracking.admin.environment.env_settings', 'env_settings', ([], {}), '()\n', (9472, 9474), False, 'from pytracking.admin.environment import env_settings\n'), ((12709, 12723), 'pytracking.admin.environment.env_settings', 'env_settings', ([], {}), '()\n', (12721, 12723), False, 'from pytracking.admin.environment import env_settings\n'), ((14272, 14286), 'pytracking.admin.environment.env_settings', 'env_settings', ([], {}), '()\n', (14284, 14286), False, 'from pytracking.admin.environment import env_settings\n'), ((15843, 15857), 'pytracking.admin.environment.env_settings', 'env_settings', ([], {}), '()\n', (15855, 15857), False, 'from pytracking.admin.environment import env_settings\n')]