# -*- coding: utf-8 -*-
"""MOT17.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1FCMlmucVBpAZUxN20QFQNhvGZFCD5zCz

# install miniconda, setup venv for python 3.7
"""

# Commented out IPython magic to ensure Python compatibility.
# %%bash
# MINICONDA_INSTALLER_SCRIPT=Miniconda3-4.5.4-Linux-x86_64.sh
# MINICONDA_PREFIX=/usr/local
# wget https://repo.continuum.io/miniconda/$MINICONDA_INSTALLER_SCRIPT
# chmod +x $MINICONDA_INSTALLER_SCRIPT
# ./$MINICONDA_INSTALLER_SCRIPT -b -f -p $MINICONDA_PREFIX
# conda install --channel defaults conda python=3.7 --yes
# conda update --channel defaults --all --yes
#

import sys
_ = (sys.path.append("/usr/local/lib/python3.7/site-packages"))

!python --version

# Commented out IPython magic to ensure Python compatibility.
# %%bash
# conda create -n myenv python=3.7
# conda activate myenv

"""# ======================================================================"""

# Always execute in each runtime session
from google.colab import drive
drive.mount('/content/drive/',force_remount=True)
import os
# os.listdir("/content/drive/MyDrive/DIP_HW3")

# 1️⃣ Change to GPU
# Runtime > Change runtime type > GPU
!nvidia-smi -L                       # sanity-check the GPU

# Commented out IPython magic to ensure Python compatibility.
!git clone -q https://github.com/ifzhang/ByteTrack.git
# %cd ByteTrack

!python --version

!pip install -r requirements.txt

!pip install cython; pip3 install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
# Cython-bbox
!pip install cython_bbox

# faiss cpu / gpu
!pip install faiss-cpu
!pip install faiss-gpu

# Commented out IPython magic to ensure Python compatibility.
# build the cython tracker (takes <30 s)
# %cd /content/ByteTrack
!python setup.py -q develop

import pathlib, zipfile, os
ZIP = "/content/drive/MyDrive/DIP_HW3/MOT17.zip"
if not pathlib.Path("/content/MOT17").exists():
    print("➜ Unzipping MOT17 …")
    with zipfile.ZipFile(ZIP) as zf:
        zf.extractall("/content")      # ➜ /content/MOT17/{train,test}
else:
    print("✓ MOT17 already present")

# Commented out IPython magic to ensure Python compatibility.
# %%bash
# mkdir -p /content/ByteTrack/pretrained

!gdown --id "1P4mY0Yyd3PPTybgZkjMYhFri88nTmJX5" --output /content/ByteTrack/pretrained/bytetrack_x_mot17.pth.tar

# Commented out IPython magic to ensure Python compatibility.
# %mkdir /content/result

!wget https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x.pt
!pip3 install ultralytics supervision onemetric
!pip3 install --upgrade protobuf==3.20.0

!git clone https://github.com/Megvii-BaseDetection/YOLOX.git

# Commented out IPython magic to ensure Python compatibility.
# %cd /content/ByteTrack