From cf49b543583de4fd970203ef27dfdb37b28ae9c2 Mon Sep 17 00:00:00 2001 From: Martin Danelljan Date: Thu, 16 Jan 2020 16:10:32 +0100 Subject: [PATCH] Updates and fixes for newer PyTorch versions. Using PyTorch's tensorboard instead of TensorboardX. --- INSTALL.md | 4 ++-- INSTALL_win.md | 4 ++-- README.md | 10 ---------- install.sh | 4 ++-- ltr/admin/loading.py | 23 +++++++++++++++++------ ltr/admin/tensorboard.py | 2 +- ltr/models/target_classifier/optimizer.py | 2 +- pytracking/libs/operation.py | 3 +-- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index ab0c66b0..e5be73b2 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -23,10 +23,10 @@ conda install pytorch torchvision cudatoolkit=10.0 -c pytorch - It is possible to use any PyTorch supported version of CUDA (not necessarily v10). - For more details about PyTorch installation, see https://pytorch.org/get-started/previous-versions/. -#### Install matplotlib, pandas, opencv, visdom and tensorboadX +#### Install matplotlib, pandas, opencv, visdom and tensorboad ```bash conda install matplotlib pandas -pip install opencv-python tensorboardX visdom +pip install opencv-python visdom tb-nightly ``` diff --git a/INSTALL_win.md b/INSTALL_win.md index 9548b889..ca269b7d 100644 --- a/INSTALL_win.md +++ b/INSTALL_win.md @@ -25,10 +25,10 @@ conda install pytorch torchvision cudatoolkit=10.0 -c pytorch - It is possible to use any PyTorch supported version of CUDA (not necessarily v10), but better be the same version with your preinstalled CUDA (if you have one) - For more details about PyTorch installation, see https://pytorch.org/get-started/previous-versions/. -#### Install matplotlib, pandas, opencv, visdom and tensorboadX +#### Install matplotlib, pandas, opencv, visdom and tensorboad ```bash conda install matplotlib pandas -pip install opencv-python tensorboardX visdom +pip install opencv-python visdom tb-nightly ``` diff --git a/README.md b/README.md index 3a5c3c23..4d78f1ca 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,5 @@ # PyTracking A general python framework for training and running visual object trackers, based on **PyTorch**. - -### **News:** Code released for **DiMP**!!! -Code now released for our new tracker **DiMP**, accepted as an Oral at ICCV 2019. -This release also includes many **new features**, including: -* Visualization with Visdom -* VOT integration -* Many new network modules -* Multi GPU training -* PyTorch v1.2 support - ## Highlights diff --git a/install.sh b/install.sh index 9a5aa118..ebdc4d4f 100644 --- a/install.sh +++ b/install.sh @@ -39,8 +39,8 @@ pip install opencv-python echo "" echo "" -echo "****************** Installing tensorboardX ******************" -pip install tensorboardX +echo "****************** Installing tensorboard ******************" +pip install tb-nightly echo "" echo "" diff --git a/ltr/admin/loading.py b/ltr/admin/loading.py index e47097e3..635d71a6 100644 --- a/ltr/admin/loading.py +++ b/ltr/admin/loading.py @@ -3,8 +3,16 @@ import sys from pathlib import Path import importlib +import inspect +def load_trained_network(workspace_dir, network_path, checkpoint=None): + checkpoint_dir = os.path.join(workspace_dir, 'checkpoints') + directory = '{}/{}'.format(checkpoint_dir, network_path) + + net, _ = load_network(directory, checkpoint) + return net + def load_network(network_dir=None, checkpoint=None, constructor_fun_name=None, constructor_module=None, **kwargs): """Loads a network checkpoint file. @@ -18,6 +26,7 @@ def load_network(network_dir=None, checkpoint=None, constructor_fun_name=None, c The extra keyword arguments are supplied to the network constructor to replace saved ones. """ + if network_dir is not None: net_path = Path(network_dir) else: @@ -58,14 +67,16 @@ def load_network(network_dir=None, checkpoint=None, constructor_fun_name=None, c net_constr.fun_name = constructor_fun_name if constructor_module is not None: net_constr.fun_module = constructor_module - for arg, val in kwargs.items(): - if arg in net_constr.kwds.keys(): - net_constr.kwds[arg] = val - else: - print('WARNING: Keyword argument "{}" not found when loading network.'.format(arg)) # Legacy networks before refactoring if net_constr.fun_module.startswith('dlframework.'): net_constr.fun_module = net_constr.fun_module[len('dlframework.'):] + net_fun = getattr(importlib.import_module(net_constr.fun_module), net_constr.fun_name) + net_fun_args = list(inspect.signature(net_fun).parameters.keys()) + for arg, val in kwargs.items(): + if arg in net_fun_args: + net_constr.kwds[arg] = val + else: + print('WARNING: Keyword argument "{}" not found when loading network. It was ignored.'.format(arg)) net = net_constr.get() else: raise RuntimeError('No constructor for the given network.') @@ -118,4 +129,4 @@ def _cleanup_legacy_env(): if m.startswith('dlframework'): del_modules.append(m) for m in del_modules: - del sys.modules[m] \ No newline at end of file + del sys.modules[m] diff --git a/ltr/admin/tensorboard.py b/ltr/admin/tensorboard.py index 323ac4f1..b4db6cad 100644 --- a/ltr/admin/tensorboard.py +++ b/ltr/admin/tensorboard.py @@ -1,6 +1,6 @@ import os from collections import OrderedDict -from tensorboardX import SummaryWriter +from torch.utils.tensorboard import SummaryWriter class TensorboardWriter: diff --git a/ltr/models/target_classifier/optimizer.py b/ltr/models/target_classifier/optimizer.py index 41cc57a9..da076ffd 100644 --- a/ltr/models/target_classifier/optimizer.py +++ b/ltr/models/target_classifier/optimizer.py @@ -148,7 +148,7 @@ def forward(self, weights, feat, bb, sample_weight=None, num_iter=None, compute_ scores_grad = sample_weight * (score_mask * scores_grad) # Compute optimal step length - alpha_num = (weights_grad * weights_grad).view(num_sequences, -1).sum(dim=1) + alpha_num = (weights_grad * weights_grad).sum(dim=(1,2,3)) alpha_den = ((scores_grad * scores_grad).view(num_images, num_sequences, -1).sum(dim=(0,2)) + reg_weight * alpha_num).clamp(1e-8) alpha = alpha_num / alpha_den diff --git a/pytracking/libs/operation.py b/pytracking/libs/operation.py index 4eb69d3b..20fa3d88 100644 --- a/pytracking/libs/operation.py +++ b/pytracking/libs/operation.py @@ -39,5 +39,4 @@ def conv1x1(input: torch.Tensor, weight: torch.Tensor): if weight is None: return input - return torch.matmul(weight.view(weight.shape[0], weight.shape[1]), - input.view(input.shape[0], input.shape[1], -1)).view(input.shape[0], weight.shape[0], input.shape[2], input.shape[3]) + return torch.conv2d(input, weight)