<jupyter_start><jupyter_text>SetupClone repo, install dependencies and check PyTorch and GPU.<jupyter_code>!git clone --recurse-submodules https://github.com/mikel-brostrom/Yolov5_DeepSort_Pytorch.git  # clone repo
%cd Yolov5_DeepSort_Pytorch
%pip install -qr requirements.txt  # install dependencies

import torch
from IPython.display import Image, clear_output  # to display images

clear_output()
print(f"Setup complete. Using torch {torch.__version__} ({torch.cuda.get_device_properties(0).name if torch.cuda.is_available() else 'CPU'})")<jupyter_output>Setup complete. Using torch 1.9.0+cu102 (CPU)<jupyter_text>Download dataGet test video from repo and extract the first 2 seconds of it<jupyter_code># get yolov5m model trained on the crowd-human dataset
!wget -nc https://github.com/mikel-brostrom/Yolov5_DeepSort_Pytorch/releases/download/v.2.0/crowdhuman_yolov5m.pt -O /content/Yolov5_DeepSort_Pytorch/yolov5/weights/crowdhuman_yolov5m.pt

# get the test video from the repo
!wget -nc https://github.com/mikel-brostrom/Yolov5_DeepSort_Pytorch/releases/download/v.2.0/test.avi
# extract 3 seconds worth of video frames of it
!y | ffmpeg -ss 00:00:00 -i test.avi -t 00:00:02 -c copy out.avi<jupyter_output>File ‘/content/Yolov5_DeepSort_Pytorch/yolov5/weights/crowdhuman_yolov5m.pt’ already there; not retrieving.
File ‘test.avi’ already there; not retrieving.

/bin/bash: y: command not found
ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --[...]<jupyter_text>Run inference on videoThe ``cv2.imshow()`` and ``cv.imshow()`` functions from the [opencv-python](https://github.com/skvark/opencv-python) package are incompatible with Jupyter notebook; see https://github.com/jupyter/notebook/issues/3935. Hence we chose to save it to file in this notebook. Locally you can use the ``--show-vid`` flag in order visualize the tracking in real-time<jupyter_code>!python track.py --yolo_weights /content/Yolov5_DeepSort_Pytorch/yolov5/weights/crowdhuman_yolov5m.pt --source out.avi --save-vid<jupyter_output>Downloading https://github.com/mikel-brostrom/Yolov5_DeepSort_Pytorch/releases/download/v.2.0/ckpt.t7 to deep_sort_pytorch/deep_sort/deep/checkpoint/ckpt.t7...
100% 43.9M/43.9M [00:02<00:00, 18.6MB/s]

/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  /pytorch/c10/core/TensorImpl.h:1156.)
  return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
video 1/1 (1/120) /content/Yolov5_DeepSort_Pytorch/out.avi: 384x640 40 persons, 32 heads, Done. (0.799s)
video 1/1 (2/120) /content/Yolov5_DeepSort_Pytorch/out.avi: 384x640 40 persons, 33 heads, Done. (0.596s)
video 1/1 (3/120) /content/Yolov5_DeepSort_Pytorch/out.avi: 384x640 41 persons, 35 heads, Done. (0.600s)
video 1/1 (4/120) /content/Yolov5_DeepSort_Pytorch/out.avi: 384x640 41 persons,[...]<jupyter_text>Show resultshttps://stackoverflow.com/questions/60977179/how-to-play-avi-file-in-google-colabConvert avi to mp4<jupyter_code>!ffmpeg -i /content/Yolov5_DeepSort_Pytorch/inference/output/out.avi output.mp4<jupyter_output>ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lib[...]<jupyter_text>Get the file content into data_url<jupyter_code>from IPython.display import HTML
from base64 import b64encode
mp4 = open('output.mp4','rb').read()
data_url = "data:video/mp4;base64," + b64encode(mp4).decode()<jupyter_output><empty_output><jupyter_text>Display it with HTML<jupyter_code>HTML("""
<video controls>
      <source src="%s" type="video/mp4">
</video>
""" % data_url)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13539367181751288, 'fraction_numerical': 0.0481972038263429, 'mean_word_length': 4.790202342917998, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 24, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '167428', 'license': 'Apache-2.0', 'n_tokens_mistral': 2170, 'n_tokens_neox': 1978, 'n_words': 403, 'path': 'Yolov5_DeepSort_Pytorch_tutorial.ipynb', 'repo_name': 'hoooooola/examples', 'size': '5436'}