-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyolo_object_detection.py
61 lines (39 loc) · 1.81 KB
/
yolo_object_detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
"""yolo_object_detection.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1pJWCn-WfDdXSP6RqaJ5i7bksjAqfSt2Y
## Let's mount google drive first for a storage and GPU
"""
from google.colab import drive
drive.mount('/content/gdrive')
# make sure you use Tesla K80 GPU (12GB), by changing 'runtmie type'
!nvidia-smi
"""## Clone Darknet GitHub repository"""
import os
os.environ['PATH'] += ':/usr/local/cuda/bin'
!rm -fr darknet
!git clone https://github.com/AlexeyAB/darknet/
!apt install gcc-5 g++-5 -y
!ln -s /usr/bin/gcc-5 /usr/local/cuda/bin/gcc
!ln -s /usr/bin/g++-5 /usr/local/cuda/bin/g++
"""## Go to the darknet folder, enable GPU, then compile the entire thing"""
# Commented out IPython magic to ensure Python compatibility.
# %cd darknet
!sed -i 's/GPU=0/GPU=1/g' Makefile
!sed -i 's/OPENCV=0/OPENCV=1/g' Makefile
!make
"""## Get the YOLO Weights file"""
!wget https://pjreddie.com/media/files/yolov3.weights
!chmod a+x ./darknet
"""## To get the working Directory"""
!pwd
from google.colab import drive
drive.mount('/content/drive')
!apt install ffmpeg libopencv-dev libgtk-3-dev python-numpy python3-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libtiff5-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libv4l-dev libtbb-dev qtbase5-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip
"""## It's time to upload the video"""
from google.colab import files
uploaded = files.upload()
!./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights -dont_show test.mp4 -i 0 -out_filename output1.avi -thresh 0.7
from google.colab import files
files.download('output1.avi')