<jupyter_start><jupyter_text>Colab notebook or tutorial [How to run PyTorch with GPU and CUDA 8.0 support on Google Colab](https://www.dlology.com/blog/how-to-run-pytorch-with-gpu-and-cuda-92-support-on-google-colab/)  New Section<jupyter_code>!nvidia-smi
!cat /etc/*-release<jupyter_output>DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
NAME="Ubuntu"
VERSION="18.04.5 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.5 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic<jupyter_text>Install [Cuda 8.0](https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1710&target_type=deblocal)<jupyter_code>!wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
# cd ../
!ls
!dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
!ls /var/
!ls /var/cuda-repo-8-0-local-ga2 | grep .pub
!apt-key add /var/cuda-repo-8-0-local-ga2/7fa2af80.pub
!apt-get update
!apt-get install cuda-8-0<jupyter_output>Reading package lists... Done
Building dependency tree       
Reading state information... Done
cuda-8-0 is already the newest version (8.0.61-1).
0 upgraded, 0 newly installed, 0 to remove and 13 not upgraded.<jupyter_text>Install [PyTorch](https://pytorch.org/) with Cuda 8.0 support<jupyter_code>!nvcc --version
!pip install torch==0.4.0
#!pip install torchvision
!git clone https://github.com/UTS-CAS/planercnn_with_adf.git
cd planercnn_with_adf
!pip install -r requirements.txt
!ls /usr/local/cuda-8.0
# %%writefile make.sh

# #!/usr/bin/env bash

# # CUDA_PATH=/usr/local/cuda/

# export CUDA_PATH=/usr/local/cuda-9.2/
# #You may also want to ad the following
# #export C_INCLUDE_PATH=/opt/cuda/include

# export CXXFLAGS="-std=c++11"
# export CFLAGS="-std=c99"

# # python setup.py build_ext --inplace
# # rm -rf build

# CUDA_ARCH="-gencode arch=compute_30,code=sm_30 \
#            -gencode arch=compute_35,code=sm_35 \
#            -gencode arch=compute_50,code=sm_50 \
#            -gencode arch=compute_52,code=sm_52 \
#            -gencode arch=compute_60,code=sm_60 \
#            -gencode arch=compute_61,code=sm_61 "

# # compile NMS
# cd nms/src/cuda/
# echo "Compiling nms kernels by nvcc..."
# #nvcc -c -o nms_cuda_kernel.cu.o nms_cuda_kernel.cu -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
# nvcc -c -o nms_kernel.cu.o nms_kernel.cu -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH

# cd ../../

# python build.py
!export CUDA_PATH=/usr/local/cuda-8.0/
!nvcc --version
!ls
!sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update && \
sudo apt-get install gcc-5 g++-5 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50 --slave /usr/bin/g++ g++ /usr/bin/g++-5 && \
gcc -v
cd /content/planercnn_with_adf/
!ls
cd nms/src/cuda/
!gcc --version
# !sudo dpkg --configure -a # run it in case below cmd fails
!sudo apt-get install gcc-5 g++-5 g++-5-multilib gfortran-5
!sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50 --slave /usr/bin/g++ g++ /usr/bin/g++-5
!sudo update-alternatives --config gcc
!gcc --version
!nvcc -c -o nms_kernel.cu.o nms_kernel.cu -x cu -Xcompiler -fPIC -arch=sm_60
cd ../../
!python build.py
cd ..
cd roialign/roi_align/src/cuda/
!nvcc -c -o crop_and_resize_kernel.cu.o crop_and_resize_kernel.cu -x cu -Xcompiler -fPIC -arch=sm_60
cd ../../
!python build.py
cd ../../
#!python evaluate_adf.py --methods=f --suffix=warping_refine --dataset=inference --customDataFolder=example_images
ls
mkdir inputs
%%writefile inputs/camera.txt
587 587 320 240 640 480
# !zip -r testfile.zip test
!ls
cd /content/planercnn_with_adf/
!wget https://www.dropbox.com/s/yjcg6s57n581sk0/checkpoint.zip?dl=0
!mkdir checkpoint
!mv "checkpoint.zip?dl=0" "planercnn_refine.zip" 
!mv planercnn_refine.zip checkpoint/
cd checkpoint/
!unzip planercnn_refine.zip
from google.colab import drive
drive.mount('/content/drive')
cp /content/drive/My\ Drive/computer_vision/session14_assignment/planercnn-master/inputs/Images/* /content/planercnn_with_adf/inputs/
## Update evaluate_adf.py - comment line 644, 645, 646
# rm /content/planercnn_with_adf/test/inference/*
ls /content/planercnn_with_adf/inputs/ | wc -l
from shutil import copyfile
import shutil
import os
import glob
cd /content/planercnn_with_adf

!mkdir input_temp
img_names_list1 = glob.glob('inputs/*')
img_names_list1.remove("inputs/camera.txt")
len(img_names_list1)
def copy_images(src, tar, input_filename):
  files = glob.glob(src)
  # print(files)
  for f in files:
    filename = f.split("/")[-1]
    if('image' in filename or 'segmentation_0_final' in filename):
      if 'image_0' in filename:
        new_input_filename = input_filename.split('.')[:-1][0]+'.png'
        new_filename = os.path.dirname(os.path.realpath(f))+"/"+new_input_filename
        os.rename(f,new_filename)
        shutil.copy(new_filename, f"{tar}{new_input_filename}")
      elif 'segmentation_0_final' in filename:
        new_output_filename = input_filename.split('.')[:-1][0]+'_segmentation_final.png'
        new_filename = os.path.dirname(os.path.realpath(f))+"/"+new_output_filename
        os.rename(f,new_filename)
        shutil.copy(new_filename, f"{tar}{new_output_filename}")
def clean_dir(dir):
  os.system(f'rm -f {dir}*')
output = '/content/drive/My Drive/computer_vision/session14_assignment/planercnn-master/outputs/'
for i in range(3590):
  if len(img_names_list1)>0:
    img_names_temp = img_names_list1[:1]
  print(f'running set - {i}')
  del img_names_list1[:1]
  os.system('rm -f input_temp/*')
  for item in img_names_temp:
    src = item
    filename = item.split("/")[1]
    dst = 'input_temp/'+filename
    copyfile(src, dst) # copy 100 images
  copyfile('inputs/camera.txt', 'input_temp/camera.txt') # copy camera.txt file
  os.system('rm -f test/inference/*') # Cleaning inference folder to clean before evaluation.
  os.system('python evaluate_adf.py --methods=f --suffix=warping_refine --dataset=inference --customDataFolder=input_temp')
  copy_images('test/inference/*', output, filename)
  # print(f'Yet to run - {len(img_names_list1)} images')
ls /content/drive/My\ Drive/computer_vision/session14_assignment/planercnn-master/outputs/ | wc -l<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup