Story of putting ubuntu in HDD from complete ignorance and yolov3

Introduction

What is LINUX in the first place? Even though it is a level, I decided to do object detection. I've suffered at the level of a few months so I'll leave the way.

It's for people who don't touch CUI or linux. I don't know much about it myself, so there are some mistakes and redundant parts, but that's the atmosphere.

environment

GPU:RTX2060 (windows10 pro)

I wanted to use both windows and ubuntu stress-free, so I prepared and built two HDDs.

Build

ubuntu installation

Things necessary

・ HDD ・ USB memory of 4GB or more Both HDD and USB can be reused, but ** the contents will be erased **, so please prepare the one you are not using.

ubuntu installation media creation

Download the Ubuntu 18.04 iso from here. The new one has less information, so the weakness is 18.04. Beginners will be miserable with 20.04. All you have to do is put this in a USB memory.

And since there is software to insert it, I will prepare that as well. I used the Universal USB Installer. When using this, select the USB memory as well as the writing destination.

Did you insert the HDD for ubuntu? After inserting it, it is next.

launch ubuntu

Start ubuntu from the USB memory. Hold down SHIFT and restart windows, or open the boot menu during boot and select a USB stick-like one. How to open the boot menu is written in a mysterious sentence such as F8 or F11 that appears when the PC is booting. Press the key that corresponds to that moment. This depends on the manufacturer, so please check it yourself. I opened at F11.

When you start it, a menu that you do not understand will appear, so start ubuntu with the one that says ubuntu without install.

This is where ubuntu starts. All you have to do is launch the installation on your desktop. You will be asked where to install it, but select a blank HDD. ** Never select an HDD that contains windows. All the data will die. ** **

In the middle "There is a new ubuntu called ubuntu 20.04 LTS!" It may be said, but please ignore it.

You can remove the USB memory when you are done.

Change the boot order of the drive (for people with two HDDs)

At this rate, every time you try to start ubuntu, the F11 continuous hitting tournament will start. Therefore, let the child who starts windows and ubuntu called BIOS start ubuntu preferentially.

Just like when you opened the boot menu earlier, this time press F2 or the Delete key on the boot screen. Again, depending on the manufacturer, I was Delete.

You should now have the BIOS screen open. The OS settings and so on are rolling, but look for Boot Device Priority or a name close to it. If you find it, put the boot order of the HDD containing ubuntu first. Most of the HDDs that were originally stuck are young HDDs.

ubuntu is a good kid who asks me what to start, so now it starts comfortably.

Foundation construction

Initial action

There is a software list at the bottom left, so open a terminal. It's a black programmer-like thing. If you can't find it, it's somewhere in the list, so look for it.

When it opens, enter the following. The $ mark is a mark on the line to be entered. Enter the part excluding this.

$ sudo apt update
$ sudo apt upgrade

sudo has root privileges. If you are told "You do not have permission / permission" or "Run as root", you can usually solve it by putting this at the beginning. apt is a package management command called * APT (Advanced Packaging Tool) *. If you make any changes, do update and upgrade. It's better to be new.

For long sentences, enter a little at the beginning and press the TAB key to complete it to some extent, so let's use it.

By the way, if you find sudo troublesome, you can solve it by logging in to the root.

$ sudo su -

//Use exit to log out of the root
$ exit

I can't use CTRL + V! Those who say can be happy with CTRL + SHIFT + V.

If that doesn't work in the future, try update and sudo first. It will be solved relatively.

Insert the NVIDIA driver

It is a child that runs the GPU. I referred to https://qiita.com/kawazu191128/items/8a46308be6949f5bda57.

First of all, let us know the recommended driver.

$ ubuntu-drivers devices

This will install the recommended driver. I was nvidia-driver-455.

$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update
$ sudo apt install nvidia-driver-455

Now that the driver is in, reboot.

$ sudo reboot

After rebooting, make sure it recognizes the GPU and you're done.

$ nvidia-smi

In my case, the letters RTX 2060 came out.

OpenCV installation

It is a child necessary for calculation. Maru Pakuri of the following things https://qiita.com/usk81/items/98e54e2463e9d8a11415

First, add the repository.

$ sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu bionic-security main"

Next, I will put in the dependent libraries.

$ sudo apt -y install build-essential checkinstall cmake unzip pkg-config yasm
$ sudo apt -y install git gfortran python3-dev
$ sudo apt -y install libjpeg-dev libpng-dev libtiff-dev libtbb-dev
$ sudo apt -y install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libatlas-base-dev libxvidcore-dev libx264-dev libgtk-3-dev

Finally I will install OpenCV.

$ cd /usr/local/src
$ sudo git clone https://github.com/opencv/opencv.git
$ sudo git clone https://github.com/opencv/opencv_contrib.git
$ cd opencv_contrib
$ sudo git checkout -b 3.4.3 refs/tags/3.4.3
$ cd ../opencv/
$ sudo git checkout -b 3.4.3 refs/tags/3.4.3

cd is a command to move the current position (directory). You can move it with cd destination, and you can go back one level with two points like cd ../. You can also come back to where you were originally with cd ~ /.

git is a command to do something from github. If you are asked to install something, follow it obediently.

Next, let's use the downloaded OpenCV.

$ sudo mkdir build
$ cd build

mkdir creates a make directory, or directory. By the way, directory ≒ folder. If you're looking at this article, you don't have to worry about the difference.

I will make it available when I move to build. It takes a lot of time so don't be scared.

$ sudo cmake -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D WITH_TBB=ON \
    -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
$ sudo make -j12
$ sudo make install

//Check if it worked
$ echo /usr/local/lib > /etc/ld.so.conf.d/opencv.conf
$ ldconfig -v

\ is a sign that "I will enter it on the next line, so do not execute it yet". It may also be written as \. Compile with make, that is, make it usable. -j12 specifies the number of CPU cores to use. If you are not sure, please omit it. echo is like print. I'm not sure.

Finally, check if OpenCV is included. If the version (3.4.3 this time) is displayed, it is successful.

$ opencv_version

Install CUDA Toolkit

It makes the GPU usable for a wide range of purposes. https://qiita.com/okubo999/items/79e1d97a7a3a3de70de2 For reference.

Bring the CUDA Toolkit from the Official Site. According to the overseas Aniki on the bulletin board, 10.2 seems to be good, so I chose 10.2. Postscript: If you think that you have tried TensorFlow in the future, please set it to 10.0. It does not support 10.2.

Linux -> x84_64 -> Ubuntu -> 18.04 -> deb(network) If you press, the method is written. However, I will change it a little at the end.

$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
$ sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
$ sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
$ sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
$ sudo apt update
$ sudo apt -y install cuda-toolkit-10-2

You can download it with wget. It comes from www + get. Since I want only the toolkit this time, I specify only the toolkit at the end.

If this is left as it is, the PC will not use it well, so add a path.

$ nano ~/.bashrc

Then add the following to the last line:

.bashrc


## CUDA and cuDNN paths
export PATH=/usr/local/cuda-10.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

nano is a text editor. I think that various things will appear below, so please refer to it. ^ Such as ^ X means pressing CTRL at the same time. When asked for YES or NO, enter y or n.

Finally, reflect the path.

$ source ~/.bashrc

//If you see various things below, you are successful
$ nvcc -V
$ echo $PATH

cuDNN installation

It makes CUDA easy to use for artificial intelligence. Install the one that matches the version of CUDA from the Official Site. This time it is 7.6.5.

If you are asked to register, I will obey you quietly.

When you open the archive Download cuDNN v7.6.5 (November 18th, 2019), for CUDA 10.2 Because there is, from there cuDNN Runtime Library for Ubuntu18.04 (Deb) cuDNN Developer Library for Ubuntu18.04 (Deb) cuDNN Code Samples and User Guide for Ubuntu18.04 (Deb) Download.

If you download it as it is, it will be in the download folder, but it is dirty so I created a workspace and put it there.

$ mkdir workspace
$ cd workspace

After downloading, go to the downloaded path (using cd). Let's expand it.

$ sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb 
$ sudo dpkg -i libcudnn7-dev_7.6.5.32-1+cuda10.2_amd64.deb 
$ sudo dpkg -i libcudnn7-doc_7.6.5.32-1+cuda10.2_amd64.deb 

dpkg is a child that manipulates .deb.

If you come this far, you are almost victorious.

Machine learning

Finally I will enter the machine learning part. Refer to https://qiita.com/okubo999/items/79e1d97a7a3a3de70de2

Preparation of darknet

First, prepare the framework darknet.

It will be messy from here, so please create a workspace and work on it. (Addition: I changed to an improved version (?) Of Alexey because learning of my own data did not go well with the original darknet.)

$ git clone https://github.com/AlexeyAB/darknet.git
$ cd darknet
$ nano Makefile

After opening Makefile, do the following.

Makefile


GPU=1
cuDNN=1
OPENCV=1 

Makefile is the setting used when making. I want to use GPU this time, so I rewrote it a little.

Now you can use it by making it.

$ make

If you run darknet and there are no errors, you win.

$ ./darknet 
usage: ./darknet [function]

Use YOLO v3

Finally the main subject. First, bring the trained data.

$ wget https://pjreddie.com/media/files/yolov3.weights

If wget stops due to an error etc., you can restart it by using --continue. In this case, it looks like this. $ wget --continue https://pjreddie.com/media/files/yolov3.weights

It's finally time to run.

$ ./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg

If you get the output image, you are a complete victory. Thank you for your support.

YOLO is stopping?

CUDA Error:out of memory
darknet: ./src/cuda.c:36: check_error: Assertion '0' failed.

If you say something like that, it is said that the performance of the GPU is fucking. If that happens, put up with the sharpness and drop the settings. Since there is a size setting in ** darknet / cfg / yolov3.cfg **, make it smaller by a multiple of 32.

darknet/cfg/yolov3.cfg


width=416
height=416

There are other settings that work, but I find resizing to be the most effective and intuitive. If you see the dog in front of the bicycle, you're graduating from fucking. Thank you for your support.

I want to add an option

You can add various options to yolov3, but even if you add it to the above, it will be ** ignored **. Let's add -dont_show to make the image output pear.

//Do not display the result image
$ ./darknet detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights data/dog.jpg -dont_show

detect has become detector, and cfg / coco.data has been added. If you leave detect, only one option will pass, and test will bring up a ridiculous amount of windows.

I want to make yolov4

Actually, yolov1 ~ v4 is included in darknet. It's easy to try yolov4

$ ./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights data/dog.jpg -dont_show

Just change the number to 3-> 4. It's a little slower, but it's more accurate. yolov3 has more articles on the internet, but please choose the one you like.

in conclusion

The other day, my ubuntu turned into hell due to a crashed chain of firefox and reinstalled, so I left it as a memorandum. I've been wandering around WSL and ubuntu 20.04, but stability is still important.

After that, I did my original goal of learning with my own data refer to this article.

urlukg.jpg

Great cat ears.

Recommended Posts

Story of putting ubuntu in HDD from complete ignorance and yolov3
The story of throwing BLOB data from EXCEL in DBUnit
The story of "duplicate symbol" after putting Swifty Tesseract and OpenCV
The story of forgetting to close a file in Java and failing
The story of acquiring Java Silver in two months from completely inexperienced.
The story of installing raspi-config on ubuntu 18.04 and changing the initial settings of GPIO