# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + id="RWtqpFWDmntd" colab_type="code" colab={}
# !cat /proc/cpuinfo

# + id="uv0F7a6xa8wF" colab_type="code" outputId="821679a4-be81-4988-b1e4-24cc92415c2c" executionInfo={"status": "ok", "timestamp": 1591248164511, "user_tz": -540, "elapsed": 26095, "user": {"displayName": "\uc2e0\uc6a9\uc2b9", "photoUrl": "", "userId": "09296461578988112178"}} colab={"base_uri": "https://localhost:8080/", "height": 124}
# This cell imports the drive library and mounts your Google Drive as a VM local drive. You can access to your Drive files 
# using this path "/content/gdrive/My Drive/"

from google.colab import drive
drive.mount('/content/gdrive')


# + id="Tm-0mZQPc-tH" colab_type="code" colab={}
# Not Necessary cell
# List the content of your local computer folder 
# !ls -la "/content/gdrive/My Drive/yolo/darknet"

# + id="TOeRpBV_f1sZ" colab_type="code" outputId="000730cb-f684-4942-b3c7-f5b4875ed8b8" executionInfo={"status": "ok", "timestamp": 1590555079391, "user_tz": -540, "elapsed": 8447, "user": {"displayName": "\uc2e0\uc6a9\uc2b9", "photoUrl": "", "userId": "09296461578988112178"}} colab={"base_uri": "https://localhost:8080/", "height": 418}
# !sudo apt-get install tree

# + id="SQ8NLU4Jf6lV" colab_type="code" colab={}
# !tree /content/gdrive/My\ Drive/yolo/darknet/

# + id="nHQ6Zlo-f-GV" colab_type="code" outputId="98013aeb-f113-40d7-bc4e-c8d0493f4f44" executionInfo={"status": "ok", "timestamp": 1589969481792, "user_tz": -540, "elapsed": 3216, "user": {"displayName": "\uc2e0\uc6a9\uc2b9", "photoUrl": "", "userId": "09296461578988112178"}} colab={"base_uri": "https://localhost:8080/", "height": 86}
# This cell can be commented once you checked the current CUDA version
# CUDA: Let's check that Nvidia CUDA is already pre-installed and which version is it. In some time from now maybe you 
# !/usr/local/cuda/bin/nvcc --version

# + id="qXirnSvJgN1k" colab_type="code" outputId="985ea48f-7b54-466e-f205-7b3c93c9c25c" executionInfo={"status": "ok", "timestamp": 1589969489090, "user_tz": -540, "elapsed": 6841, "user": {"displayName": "\uc2e0\uc6a9\uc2b9", "photoUrl": "", "userId": "09296461578988112178"}} colab={"base_uri": "https://localhost:8080/", "height": 121}
# We're unzipping the cuDNN files from your Drive folder directly to the VM CUDA folders
# !tar -xzvf gdrive/My\ Drive/darknet/cuDNN/cudnn-10.0-linux-x64-v7.5.0.56.tgz -C /usr/local/
# !chmod a+r /usr/local/cuda/include/cudnn.h

# Now we check the version we already installed. Can comment this line on future runs
# !cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

# + id="na5XeB8Mgy3s" colab_type="code" outputId="4c9a7af1-c5e6-4e9f-af6c-ff392763cf8b" executionInfo={"status": "ok", "timestamp": 1589969129460, "user_tz": -540, "elapsed": 17588, "user": {"displayName": "\uc2e0\uc6a9\uc2b9", "photoUrl": "", "userId": "09296461578988112178"}} colab={"base_uri": "https://localhost:8080/", "height": 121}
# !git clone https://github.com/kriyeng/darknet/

# + id="rZ8Exb80i_Nq" colab_type="code" outputId="19c1271f-438c-4120-83fe-99a482f64b7a" executionInfo={"status": "ok", "timestamp": 1590555168747, "user_tz": -540, "elapsed": 1374, "user": {"displayName": "\uc2e0\uc6a9\uc2b9", "photoUrl": "", "userId": "09296461578988112178"}} colab={"base_uri": "https://localhost:8080/", "height": 69}
# %cd /content/gdrive/My\ Drive/yolo/darknet/darknet
# %pwd

# + id="iNsBPf8rg3HL" colab_type="code" colab={}
# Check the folder
# !ls

# I have a branch where I have done the changes commented above
# !git checkout feature/google-colab

#Compile Darknet
# !make

#Copies the Darknet compiled version to Google drive
# !cp ./darknet /content/gdrive/My\ Drive/yolo/darknet/bin/darknet

# + id="wPEJcpPnjdsr" colab_type="code" colab={}
def imShow(path):
  import cv2
  import matplotlib.pyplot as plt
  # %matplotlib inline

  image = cv2.imread(path)
  height, width = image.shape[:2]
  resized_image = cv2.resize(image,(3*width, 3*height), interpolation = cv2.INTER_CUBIC)

  fig = plt.gcf()
  fig.set_size_inches(18, 10)
  plt.axis("off")
  #plt.rcParams['figure.figsize'] = [10, 5]
  plt.imshow(cv2.cvtColor(resized_image, cv2.COLOR_BGR2RGB))
  plt.show()


# + id="6vOzB6xanRMA" colab_type="code" outputId="70fb775d-89bb-451b-eb19-fac53769f3dc" executionInfo={"status": "ok", "timestamp": 1589972666325, "user_tz": -540, "elapsed": 2272657, "user": {"displayName": "\uc2e0\uc6a9\uc2b9", "photoUrl": "", "userId": "09296461578988112178"}} colab={"base_uri": "https://localhost:8080/", "height": 209}
# Not necessary cell
# Get yolov3 weights
# #!wget https://pjreddie.com/media/files/yolov3.weights

# + id="Z4CjPlPDjlJv" colab_type="code" colab={}
# Not necessary cell
# Execute darknet using YOLOv3 model with pre-trained weights to detect objects on 'person.jpg'
# !./darknet detect cfg/yolov3.cfg yolov3.weights.1 data/giraffe.jpg -dont-show

# Show the result using the helper imgShow()
imShow('predictions.jpg')

# + id="42ww45zRRS4e" colab_type="code" outputId="d91b314c-acab-4371-82ce-c715ed54a7c7" executionInfo={"status": "ok", "timestamp": 1591248674366, "user_tz": -540, "elapsed": 1199, "user": {"displayName": "\uc2e0\uc6a9\uc2b9", "photoUrl": "", "userId": "09296461578988112178"}} colab={"base_uri": "https://localhost:8080/", "height": 34}
# cd "/content/gdrive/My Drive/yolo/darknet"

# + id="CsPUMzSyStOj" colab_type="code" outputId="4084b590-9ac9-4970-baed-91e85f149f7f" executionInfo={"status": "ok", "timestamp": 1590559017061, "user_tz": -540, "elapsed": 205755, "user": {"displayName": "\uc2e0\uc6a9\uc2b9", "photoUrl": "", "userId": "09296461578988112178"}} colab={"base_uri": "https://localhost:8080/", "height": 209}
# !wget https://pjreddie.com/media/files/yolov3-tiny.weights

# + id="LrurE6XZtPfc" colab_type="code" colab={}
# !./darknet partial cfg/yolov3-tiny.cfg yolov3-tiny.weights yolov3-tiny.conv.15 15

# + id="q2DYjHwberIK" colab_type="code" colab={}
# !chmod 755 darknet

# + id="7nNVd3Z6XUDV" colab_type="code" outputId="dffcc142-3389-4760-e116-a9635c04243c" executionInfo={"status": "ok", "timestamp": 1591270705462, "user_tz": -540, "elapsed": 13325274, "user": {"displayName": "\uc2e0\uc6a9\uc2b9", "photoUrl": "", "userId": "09296461578988112178"}} colab={"base_uri": "https://localhost:8080/", "height": 1000}
# !./darknet detector train "/content/gdrive/My Drive/yolo/darknet/obj.data" "/content/gdrive/My Drive/yolo/darknet/cfg/yong-mine.cfg" "/content/gdrive/My Drive/yolo/darknet/yolov3-tiny.conv.15" -dont_show 

StarcoderdataJupyterScriptsDedupFiltered