Thursday, 28 June 2018

TensorFlow Installation with GPU support in Ubuntu 17.10


This page was made for installation of tensorflow 1.8.0. Go to https://www.tensorflow.org/install/linux/ to check latest version.

Installing the Nvidia drivers

Add the graphics drivers PPA :

sudo add-apt-repository ppa:graphics-drivers

sudo apt-get update

Select the required graphics driver:

Open software updater and select settings


Select the required Drivers from Additional drivers tab

Nvidia driver version 390 is a requirement for Cuda 9.1. But for tensorflow 1.8 we require Cuda 9.0 (Cuda 9.1 wont work). So Nvidia driver version 384 and above should work.

Installing CUDA Toolkit

TensorFlow requires CUDA Toolkit 9.0. But the  CUDA Toolkit 9.0 link in the TensorFlow website redirects to latest CUDA Toolkit (9.2 at time of this post). Use the following link to download  CUDA Toolkit 9.0 from the archive.

CUDA Toolkit 9.0

Installing cuDNN

cuDNN SDK v7. For details, see NVIDIA's documentation. Ensure that you create the CUDA_HOME environment variable as described in the NVIDIA documentation.

Install libcupti-dev library

libcupti-dev is the NVIDIA CUDA Profile Tools Interface. This library provides advanced profiling support. To install this library, issue the following command for CUDA Toolkit >= 9.0:

sudo apt install cuda-command-line-tools-9-0

and add its path to your LD_LIBRARY_PATH environment variable:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}/usr/local/cuda/extras/CUPTI/lib64

[OPTIONAL] For optimized inferencing performance, you can also install NVIDIA TensorRT 3.0. The minimal set of TensorRT runtime components needed for use with the pre-built tensorflow-gpu package can be installed as follows:
$ wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1404/x86_64/nvinfer-runtime-trt-repo-ubuntu1404-3.0.4-ga-cuda9.0_1.0-1_amd64.deb $ sudo dpkg -i nvinfer-runtime-trt-repo-ubuntu1404-3.0.4-ga-cuda9.0_1.0-1_amd64.deb $ sudo apt-get update $ sudo apt-get install -y --allow-downgrades libnvinfer-dev libcudnn7-dev=7.0.5.15-1+cuda9.0 libcudnn7=7.0.5.15-1+cuda9.0
IMPORTANT: For compatibility with the pre-built tensorflow-gpu package, please use the Ubuntu 14.04 package of TensorRT as shown above, even when installing onto an Ubuntu 16.04 system.

To avoid cuDNN version conflicts during later system upgrades, you can hold the cuDNN version at 7.0.5:
  • $ sudo apt-mark hold libcudnn7 libcudnn7-dev
    To later allow upgrades, you can remove the hold:
    $ sudo apt-mark unhold libcudnn7 libcudnn7-dev
If you have an earlier version of the preceding packages, please upgrade to the specified versions.

Determine how to install TensorFlow

You must pick the mechanism by which you install TensorFlow. The supported choices are as follows:

    Tuesday, 9 December 2014



    Simulation of Real/Pure Pursuit problem



    Hot PursuitWhen target is aware of the pursuer.

    Pure Pursuit- When target is not aware of pursuer. In this case, the course of the target is known.

    Pure Pursuit Problem example


    A fighter aircraft sights an enemy bomber and flies directly toward it, in order to catch up and destroy it. We have to determine the attack the attack course of the fighter and how long does the fighter take to catch up with the bomber.

    If the target flies along a straight line, the problem can be solved directly with analytic techniques. But if the path of the bomber is curved, the problem can not be solved directly. We can solve such problems using simulation.

    We are given following conditions:
    1. Both target and pursuer are flying in the same 2 dimensional plane.
    2. The fighter's speed is constant that is VF.
    3. The target's path is known.
    4. Minimum distance required by the fighter to fire a missile at bomber is 10 units.
    5. If the target is not caught within given time t (here t = 12), the target escapes.
    6. Initial coordinates of the pursuer (fighter) are known.

    We will choose our coordinate system such that, initially target will be lying on the X axis and pursuer will be lying on Y axis as shown in the figure below.

    The fighter looks at the target at instant t, aligns its velocity vector with line of sight (i.e. points itself towards the target). It continues to fly in that direction for one unit of time (up to t+1). At (t+1) it looks at the target again and realigns itself.
    The distance between the 2 (dist[t]) at a given instant of time can be calculated by using distance formula.

    dist[t] = √( (yb[t]-yf[t])² + (xb[t]-yf[t])² )

    The angle θ of the line from fighter to target at a given time t is given by

    Sin 
    θ =  (yb[t]-yf[t]) /dist[t]
    Cos 
    θ = (xb[t]-xf[t]) /dist[t]

    Using these values, next position of fighter at time (t+1) is
    xf[t+1]= xf[t] + VF 
    Sin θ
    yf[t+1]= yf[t] + VF
    Cos 
    θ

    (try putting different velocities of fighter or different coordinates of bomber in the code given below)

    Java code for the simulation:
    package simulation;
    
    /**
     *
     * @author avichal
     */
    public class Simulation {
    
        
        public static void main(String[] args) {
            /*Co-ordinates of the bomber*/
            double[] xb={80,90,99,108,116,125,133,141,151,160,169,179,180};
            double[] yb={0,-2,-5,-9,-15,-18,-23,-29,-28,-25,-21,-20,-17};
            
            /*Co_ordinates of fighter to be determined*/
            double[] xf=new double[13];
            double[] yf=new double[13];
            xf[0]=0;
            yf[0]=50;
            
            double vf=20;   //speed of fighter
            boolean status=true;
            double dist;
            
            for (int t=0;t<12;t++)
            {
               dist=Math.sqrt((xb[t]-xf[t])*(xb[t]-xf[t])+(yb[t]-yf[t])*(yb[t]-yf[t]));
               if(dist<=10)
               {
                    status=false;
                    
                    for(int i=0;i<13;i++)
                    {
                        System.out.println(xf[i]+" "+yf[i]);
                    }
                    System.out.println("Target Destroyed at time t="+t);
                    
                    break;
               }
               yf[t+1]=yf[t]+vf*((yb[t]-yf[t])/dist);
               xf[t+1]=xf[t]+vf*((xb[t]-xf[t])/dist);
            }
            
            if(status)
            {
                for(int i=0;i<13;i++)
                {
                    System.out.println(xf[i]+" "+yf[i]);
                }
                System.out.println("Target escaped!");
            }
        }
        
    }