<jupyter_start><jupyter_text>INF6804 Vision par ordinateurPolytechnique MontréalAuthor: <NAME>siamfc visual object tracker example.Original GitHub: https://github.com/huanglianghua/siamfc-pytorch Install the required packages.<jupyter_code>pip install torch torchvision got10k opencv-python<jupyter_output>Requirement already satisfied: torch in /usr/local/lib/python3.6/dist-packages (1.6.0+cu101)
Requirement already satisfied: torchvision in /usr/local/lib/python3.6/dist-packages (0.7.0+cu101)
Requirement already satisfied: got10k in /usr/local/lib/python3.6/dist-packages (0.1.3)
Requirement already satisfied: opencv-python in /usr/local/lib/python3.6/dist-packages (4.1.2.30)
Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from torch) (0.16.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from torch) (1.18.5)
Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.6/dist-packages (from torchvision) (7.0.0)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/dist-packages (from got10k) (3.2.2)
Requirement already satisfied: fire in /usr/local/lib/python3.6/dist-packages (from got10k) (0.3.1)
Requirement already satisfied: wget in /usr/local/lib/python3.6/dist-packages (from got10k) (3.2)
R[...]<jupyter_text>Clone the repo.<jupyter_code>import os
# get siamfc-pytorch source
if not os.path.exists('siamfc-pytorch'):
  !git clone https://github.com/huanglianghua/siamfc-pytorch.git<jupyter_output><empty_output><jupyter_text>Download the pretrained weights.<jupyter_code>pretrained_file_name = 'siamfc_alexnet_e50.pth'
if not os.path.exists(pretrained_file_name):
  !gdown https://drive.google.com/uc?id=1UdxuBQ1qtisoWYFZxLgMFJ9mJtGVw6n4<jupyter_output><empty_output><jupyter_text>Download and unzip the DragonBaby sequence from the Visual Tracker Benchmark.<jupyter_code>file_name = 'DragonBaby.zip'
if not os.path.exists(file_name):
  !gdown http://cvlab.hanyang.ac.kr/tracker_benchmark/seq/DragonBaby.zip
if not os.path.exists('DragonBaby'):
  !unzip DragonBaby.zip<jupyter_output><empty_output><jupyter_text>Update the path.<jupyter_code>import sys
sys.path.append('siamfc-pytorch/')<jupyter_output><empty_output><jupyter_text>Import the necessary libraries.<jupyter_code>import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import numpy as np
import time
import cv2
import os
from collections import namedtuple
from torch.optim.lr_scheduler import ExponentialLR
from torch.utils.data import DataLoader
from got10k.trackers import Tracker
from siamfc import ops
from siamfc.backbones import AlexNetV1
from siamfc.heads import SiamFC
from siamfc.losses import BalancedLoss
from siamfc.datasets import Pair
from siamfc.transforms import SiamFCTransforms
from siamfc.siamfc import Net
from siamfc.siamfc import TrackerSiamFC
import glob<jupyter_output><empty_output><jupyter_text>Define the paths for the images, the starting rectangle and the pretrained weights. Then execute the tracker on the images.<jupyter_code>seq_dir = os.path.expanduser('DragonBaby/')
img_files = sorted(glob.glob(seq_dir + 'img/*.jpg'))
anno = np.loadtxt(seq_dir + 'groundtruth_rect.txt', delimiter=',', usecols=range(4))

net_path = 'siamfc_alexnet_e50.pth'
tracker = TrackerSiamFC(net_path=net_path)
boxes, times = tracker.track(img_files, anno[0], visualize=False)<jupyter_output><empty_output><jupyter_text>For each box, print it on the corresponding image. Stop after NBR_FRAMES.<jupyter_code>from google.colab.patches import cv2_imshow

NBR_FRAMES = 25
for index, box in enumerate(boxes):
  if index > NBR_FRAMES:
    break
  image_path = os.path.join(seq_dir, 'img/' + str(index+1).zfill(4) + '.jpg')
  image = cv2.imread(image_path)
  box = [int(item) for item in box]
  cv2.rectangle(image, (box[0], box[1]), (box[0]+box[2], box[1]+box[3]), (255, 0, 0), 2) 
  cv2_imshow(image)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11361336032388664, 'fraction_numerical': 0.028087044534412957, 'mean_word_length': 6.293357933579336, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '440355', 'license': 'MIT', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1421, 'n_words': 310, 'path': 'siamfc_example.ipynb', 'repo_name': 'gabilodeau/INF6804', 'size': '3962'}