Wednesday, June 29, 2016

Interface Caffe with Python

Being in Caffe root dir, Run the following command:



make pycaffe
make distribute

and add the path

echo export $PYTHONPATH=~/caffe/python:$PYTHONPATH >> ~/.bashrc

make sure it is aded to the system path by using os.sys.path.

TO create a graph of Network in ipython:

1.Make sure python-pydot is installed (else, install it using sudo apt-get install python-pydot)

It installs in addition: The following extra packages will be installed:
  

graphviz libcdt5 libcgraph6 libgvc6 libgvpr2 libpathplan4

Now run the following in ipython:

! python python/draw_net.py MyProgramms/conv.prototxt MyProgramms/conv.png
from IPython.display import Image
Image(filename='conv.png')

2. Trained caffe model is stored as .caffemodel



Thursday, June 23, 2016

ProtoBuff Compilation

Documentation is available for python: Google developers 

 Lets create a file with .proto extension with the following code:

package tutorial;

message Person {
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  message PhoneNumber {
    required string number = 1;
    optional PhoneType type = 2 [default = HOME];
  }

  repeated PhoneNumber phone = 4;
}

message AddressBook {
  repeated Person person = 1;
}
 
After creating addressbook.proto, to compile and to generate python file

protoc -I=$SOURCE_DIR --python_out=$DESTINATION_DIR $SOURCE_DIR/addressbook.proto
 


Example: i have a addressbook.proto in home directory, and compile it using the following command in terminal,

protoc -I=/home/arun  --python_out=/home/arun  ~/addressbook.proto 
 
 Because we want Python classes, you use the --python_out option – similar options are provided for other supported languages. 

The output .py file will be save in the directory mentioned as destination directory (which is again home in the above command)


Unlike when you generate Java and C++ protocol buffer code, the Python protocol buffer compiler doesn't generate your data access code for you directly. Instead (as you'll see if you look at addressbook_pb2.py) it generates special descriptors for all your messages, enums, and fields, and some mysteriously empty classes, one for each message type: 

class Person(message.Message):                                                    
  __metaclass__ = reflection.GeneratedProtocolMessageType                         
                                                                                  
  class PhoneNumber(message.Message):                                             
    __metaclass__ = reflection.GeneratedProtocolMessageType                       
    DESCRIPTOR = _PERSON_PHONENUMBER                                              
  DESCRIPTOR = _PERSON                                                            
                                                                                  
class AddressBook(message.Message):                                               
  __metaclass__ = reflection.GeneratedProtocolMessageType                         
  DESCRIPTOR = _ADDRESSBOOK                                                       


The important line in each class is __metaclass__ = reflection.GeneratedProtocolMessageType
At load time, the GeneratedProtocolMessageType metaclass uses the specified descriptors to create all the Python methods you need to work with each message type and adds them to the relevant classes. You can then use the fully-populated classes in your code.
The end effect of all this is that you can use the Person class as if it defined each field of the Message base class as a regular field. For example, you could write:

import addressbook_pb2              
person = addressbook_pb2.Person()   
person.id = 1234                    
person.name = "John Doe"            
person.email = "jdoe@example.com"   
phone = person.phone.add()          
phone.number = "555-4321"           
phone.type = addressbook_pb2.Person.HOME

Parsing and Serialization

Finally, each protocol buffer class has methods for writing and reading messages of your chosen type using the protocol buffer binary format. These include:
  • SerializeToString(): serializes the message and returns it as a string. Note that the bytes are binary, not text; we only use the str type as a convenient container.
  • ParseFromString(data): parses a message from the given string.
These are just a couple of the options provided for parsing and serialization. Again, see the Message API reference for a complete list.

Wednesday, June 22, 2016

Problems we Face when Running Opencv in Ubuntu

In Windows:


ImgColor=cv2.imread('/home/arun/Desktop/Arun.jpg',1) # Read it as color image

cv2.namedWindow('Figure', cv2.WINDOW_NORMAL)
cv2.imshow('Figure',ImgColor)
cv2.waitKey(0)
cv2.destroyAllWindows()

Opens the image and display it in the window named 'Figure'. Upon a key press it destroy all opened window. but it doesn't work in linux (opened window simply hangs)

In Linux:

ImgColor=cv2.imread('/home/arun/Desktop/Arun.jpg',1) # Read it as color image
 
cv2.startWindowThread() # Solves the issue
cv2.namedWindow('Figure', cv2.WINDOW_NORMAL)
cv2.imshow('Figure',ImgColor)
cv2.waitKey(0)
cv2.destroyAllWindows()


Installing Cafee for Deep Learning

General dependencies

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev 
 
before Installing the dependencies, check whether they are already installed:
 
sudo dpkg-query -l libopencv*
 
||/ Name                           Version              Architecture         Description
+++-==============================-====================-====================-=================================================================
rc  libopencv-calib3d2.4:i386      2.4.8+dfsg1-2ubuntu1 i386                 computer vision Camera Calibration library
rc  libopencv-contrib2.4:i386      2.4.8+dfsg1-2ubuntu1 i386                 computer vision contrib library
rc  libopencv-core2.4:i386         2.4.8+dfsg1-2ubuntu1 i386                 computer vision core library
rc  libopencv-features2d2.4:i386   2.4.8+dfsg1-2ubuntu1 i386                 computer vision Feature Detection and Descriptor Extraction libra
rc  libopencv-flann2.4:i386        2.4.8+dfsg1-2ubuntu1 i386                 computer vision Clustering and Search in Multi-Dimensional spaces
rc  libopencv-gpu2.4:i386          2.4.8+dfsg1-2ubuntu1 i386                 computer vision GPU library
....


so none of the are installed. You can use the following command too: 
 
sudo  dpkg -s libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev 
 
libhdf5-serial-dev protobuf-compiler

Prints:

dpkg-query: package 'libprotobuf-dev' is not installed and no information is available

dpkg-query: package 'libleveldb-dev' is not installed and no information is available

dpkg-query: package 'libsnappy-dev' is not installed and no information is available

dpkg-query: package 'libopencv-dev' is not installed and no information is available

dpkg-query: package 'libhdf5-serial-dev' is not installed and no information is available

dpkg-query: package 'protobuf-compiler' is not installed and no information is available

BLAS: install ATLAS by sudo apt-get install libatlas-base-dev 
or install OpenBLAS or MKL for better CPU performance. 
 
(Note: it was already installed in my system and up to date) 

Install Following Package: (for ubuntu 14.04)

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
 

Make File Configuration: (From Cafee Documentation)

Caffe has several dependencies:

  • CUDA is required for GPU mode.
    • library version 7+ and the latest driver version are recommended, but 6.* is fine too
    • 5.5, and 5.0 are compatible but considered legacy
  • BLAS via ATLAS, MKL, or OpenBLAS.
  • Boost >= 1.55
  • protobuf, glog, gflags, hdf5
Optional dependencies:

  • OpenCV >= 2.4 including 3.0
  • IO libraries: lmdb, leveldb (note: leveldb requires snappy)
  • cuDNN for GPU acceleration (v5)
Pycaffe and Matcaffe interfaces have their own natural needs.

  • For Python Caffe: Python 2.7 or Python 3.3+, numpy (>= 1.7), boost-provided boost.python
  • For MATLAB Caffe: MATLAB with the mex compiler.

 

cuDNN Caffe: for fastest operation Caffe is accelerated by drop-in integration of NVIDIA cuDNN. To speed up your Caffe models, install cuDNN then uncomment the USE_CUDNN := 1 flag in Makefile.config when installing Caffe. Acceleration is automatic. The current version is cuDNN v5; older versions are supported in older Caffe.

CPU-only Caffe: for cold-brewed CPU-only Caffe uncomment the CPU_ONLY := 1 flag in Makefile.config to configure and build Caffe without CUDA. This is helpful for cloud or cluster deployment.


Edit Makfile.config.example for your need:

cp Makefile.config.example Makefile.config
# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)
make all
make test
make runtest
 
after make runtest: (which nearly takes 6 minutes) 
 
[----------] 2 tests from SigmoidCrossEntropyLossLayerTest/1, where TypeParam = caffe::CPUDevice<double>
[ RUN      ] SigmoidCrossEntropyLossLayerTest/1.TestGradient
[       OK ] SigmoidCrossEntropyLossLayerTest/1.TestGradient (4 ms)
[ RUN      ] SigmoidCrossEntropyLossLayerTest/1.TestSigmoidCrossEntropyLoss
[       OK ] SigmoidCrossEntropyLossLayerTest/1.TestSigmoidCrossEntropyLoss (7 ms)
[----------] 2 tests from SigmoidCrossEntropyLossLayerTest/1 (11 ms total)

[----------] Global test environment tear-down
[==========] 1090 tests from 150 test cases ran. (358598 ms total)
[  PASSED  ] 1090 tests.
 


 Means that you have sucessfully installed cafe on your machine! Hurrah!!!!!!

Where the Packages are installed?

Deafult Python packages are installed in : /usr/lib/python2.7



argparse.py , os.py, calender.py, glob.py..............are default python modules.

External or Third party Modules are in : /usr/lib/python2.7/dist-packages/

 

 

Files will be installed into subdirectories of site.USER_BASE (written as userbase hereafter). This scheme installs pure Python modules and extension modules in the same location (also known as site.USER_SITE). Here are the values for UNIX, including Mac OS X:

Type of file Installation directory
modules userbase/lib/pythonX.Y/site-packages
scripts userbase/bin
data userbase
C headers userbase/include/pythonX.Y/distname

Examples:
 To locate where opencv's 'cv2.so' files installed?

sudo find / -name "cv2.so"  

/home/arun/opencv/build/lib/cv2.so
/usr/local/lib/python2.7/dist-packages/cv2.so

python notebook has to be aware of this location so that it recognises cv2 while importing. Lets check it out in the notebook.

print os.sys.path                          

['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-i386-linux-gnu', 
'/usr/lib/python2.7/lib-tk'
, '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', 
'/usr/local/lib/python2.7/dist-packages', 
'/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', 
'/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', 
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client', 
'/usr/local/lib/python2.7/dist-packages/IPython/extensions', 
'/home/arun/.ipython'] 
 
 
 

Insatlling Opencv 3.0 Python 2.7 and Supporting Packages in ubuntu

Assuming U have already installed Python2.7-dev and pip (python package manager). 

Step 1:

Open up a terminal and update the apt-get  package manager followed by upgrading any pre-installed packages:
Install OpenCV 3.0 and Python 2.7+ on Ubuntu
Shell
1
2
$ sudo apt-get update
$ sudo apt-get upgrade

 

Step 2:

Now we need to install our developer tools:
The pkg-config  is likely already installed, but be sure to include it just in case. We’ll be using git  to pull down the OpenCV repositories from GitHub. The  cmake  package is used to configure our build.

 

Step 3:

OpenCV needs to be able to load various image file formats from disk, including JPEG, PNG, TIFF, etc. In order to load these image formats from disk, we’ll need our image I/O packages:
Install OpenCV 3.0 and Python 2.7+ on Ubuntu
Shell
1
$ sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev

 

Step 4:

At this point, we have the ability to load a given image off of disk. But how do we display the actual image to our screen? The answer is the GTK development library, which the highgui  module of OpenCV depends on to guild Graphical User Interfaces (GUIs):

 

Step 5:

We can load images using OpenCV, but what about processing video streams and accessing individual frames? We’ve got that covered here:

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

Step 6:

Install libraries that are used to optimize various routines inside of OpenCV:

sudo apt-get install libatlas-base-dev gfortran

Step 7:

Our environment is now all setup — we can proceed to change to our home directory, pull down OpenCV from GitHub, and checkout the 3.0.0  version:

$ cd ~
$ git clone https://github.com/Itseez/opencv.git
$ cd opencv
$ git checkout 3.1.0   

(replace 3.1.0 by latest version such as 3.2.0)


we also need the opencv_contrib repo as well. Without this repository, we won’t have access to standard keypoint detectors and local invariant descriptors (such as SIFT, SURF, etc.) that were available in the OpenCV 2.4.X version. We’ll also be missing out on some of the newer OpenCV 3.0 features like text detection in natural images:

 
$ cd ~
$ git clone https://github.com/Itseez/opencv_contrib.git
$ cd opencv_contrib
$ git checkout 3.1.0
Time to setup the build:
cd ~/opencv
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
Update (3 January 2016): In order to build OpenCV 3.1.0 , you need to set -D INSTALL_C_EXAMPLES=OFF  (rather than ON ) in the cmake  command. There is a bug in the OpenCV v3.1.0 CMake build script that can cause errors if you leave this switch on. Once you set this switch to off, CMake should run without a problem.
Now we can finally compile OpenCV:
$ make -j4
Where you can replace the 4 with the number of available cores on your processor to speedup the compilation.
 
Thanks to Adreian


Installing Supporting Packages:

sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook 
python-pandas python-sympy python-nose

 

List of Support Packages available for python:

 

click here


FAQ

Package installation

There are two standard methods for installing a package.
pip install
The pip install script is available within our scientific Python installation and is very easy to use (when it works). During the installation process you already saw many examples of pip install in action. Features include:
  • If supplied with a package name then it will query the PyPI site to find out about that package. Assuming the package is there then pip install will automatically download and install the package.
  • Will accept a local tar file (assuming it contains an installable Python package) or a URL pointing to a tar file.
  • Can install in the user package area via pip install <package or URL> --user (but see discussion further down)
python setup.py install
Some packages may fail to install via pip install. Most often there will be some obvious (or not) error message about compilation or missing dependency. In this case the likely next step is to download the installation tar file and untar it. Go into the package directory and look for files like:
 
INSTALL
README
setup.py
setup.cfg

 

If there is an INSTALL or README file then hopefully you will find useful installation instructions. Most well-behaved python packages do the installation via a standard setup.py script. This is used as follows:
python setup.py --help  # get options
python setup.py install # install in the python area (root / admin req'd)
python setup.py install --user # install to user's package area

 

Where do packages get installed?

An important option in the installation process is where to put the package files. We’ve seen the --user option in pip install and python setup.py install. What’s up with that? In the section below we document how this works. See the discussion in Multiple Pythons on your computer for a reason you might want to do this, but first please read this warning:
Warning
We strongly recommend against installing packages with --user unless you are an expert and really understand what you are doing, . This is because the local user version will always take precedence and can thus potentially disrupt other Python installations and cause hard-to-understand problems. Big analysis packages like CIAO, STSci_Python or CASA are carefully tested assuming the integrated environment they provide. If you start mucking this up then all bets are off.

WITH --user

Packages get installed in a local user-owned directory when you do something like either of the following:
pip install --user aplpy
python setup.py install --user 
 
This puts the packages into:
Mac ~/Library/Python/2.x/lib/python/site-packages
Linux ~/.local/lib/python-2.x/site-packages
Windows %APPDATA%/Python/Python2x/site-packages

WITHOUT --user

 

If you use Anaconda or a non-root Python installation then there is no issue with permissions on any platform since the entire installation is local to a directory you own.

However, installing to a system-wide Python installation will require root or admin privilege. Installing this way has the benefit of making the package available for all users of the Python installation, but has the downside that it is more difficult to back out changes if required. In general we recommend using only the system package manager (e.g. yum) to install packages to the system Python. This will ensure integrity of your system Python, which is important even if you are the only user.

How do I find a package once installed?

Finding the file associated with a package or module is simple, just use the help command in IPython:
 
import scipy
help scipy

Where does Python look for modules?

The official reference on Modifying Python’s Search Path gives all the details. In summary:
When the Python interpreter executes an import statement, it looks for modules on a search path. A default value for the path is configured into the Python binary when the interpreter is built. You can determine the path by importing the sys module and printing the value of sys.path:

$ python
Python 2.2 (#11, Oct  3 2002, 13:31:27)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/lib/python2.3', '/usr/local/lib/python2.3/plat-linux2',
 '/usr/local/lib/python2.3/lib-tk', '/usr/local/lib/python2.3/lib-dynload',
 '/usr/local/lib/python2.3/site-packages']
>>>

Within a script it is possible to adjust the search path by modify sys.path which is just a Python list. Generally speaking you will want to put your path at the front of the list using insert:
import sys 
 sys.path.insert(0, '/my/path/python/packages') 
 
You can also add paths to the search path using the PYTHONPATH environment variable.


Package Manipulation in Ubuntu





To See where the  packages installed:

dpkg -L <packagename>

For example:
                            ~$ dpkg -L python 

/.
/usr
/usr/lib
/usr/lib/valgrind
/usr/lib/valgrind/python.supp
/usr/share
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/dh_python2.1.gz
/usr/share/python
/usr/share/python/runtime.d
/usr/share/python/runtime.d/public_modules.rtremove
/usr/share/python/runtime.d/public_modules.rtinstall
/usr/share/python/dist_fallback
/usr/share/python/dh_python2
/usr/share/python/python.mk
/usr/share/apps
/usr/share/apps/konsole
/usr/share/apps/konsole/python.desktop
/usr/share/doc-base
/usr/share/doc-base/python-policy
/usr/share/debhelper
/usr/share/debhelper/autoscripts
/usr/share/debhelper/autoscripts/postinst-pycompile
/usr/share/debhelper/autoscripts/prerm-pyclean
/usr/share/debhelper/autoscripts/preinst-pycentral-clean
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/python
/usr/share/pixmaps
/usr/share/perl5
/usr/share/perl5/Debian
/usr/share/perl5/Debian/Debhelper
/usr/share/perl5/Debian/Debhelper/Sequence
/usr/share/perl5/Debian/Debhelper/Sequence/python2.pm
/usr/share/doc
/usr/share/doc/python
/usr/share/doc/python/faq
/usr/share/doc/python/faq/programming.html
/usr/share/doc/python/faq/library.html
/usr/share/doc/python/faq/general.html
/usr/share/doc/python/faq/installed.html
/usr/share/doc/python/faq/windows.html
/usr/share/doc/python/faq/gui.html
/usr/share/doc/python/faq/extending.html
/usr/share/doc/python/python-policy.txt.gz
/usr/share/doc/python/copyright
/usr/share/doc/python/FAQ.html
/usr/share/doc/python/python-policy.html
/usr/share/doc/python/python-policy.html/ch-module_packages.html
/usr/share/doc/python/python-policy.html/ap-packaging_tools.html
/usr/share/doc/python/python-policy.html/index.html
/usr/share/doc/python/python-policy.html/ch-other.html
/usr/share/doc/python/python-policy.html/ch-programs.html
/usr/share/doc/python/python-policy.html/ch-embed.html
/usr/share/doc/python/python-policy.html/ap-upgrade.html
/usr/share/doc/python/python-policy.html/ch-python.html
/usr/share/doc/python/python-policy.html/ap-build_dependencies.html
/usr/share/doc/python/python-policy.sgml.gz
/usr/share/doc/python2.7
/usr/bin
/usr/bin/dh_python2
/usr/share/man/man1/pydoc.1.gz
/usr/share/man/man1/pygettext.1.gz
/usr/share/man/man1/pdb.1.gz
/usr/share/man/man1/2to3.1.gz
/usr/share/pixmaps/python.xpm
/usr/share/doc/python/README.Debian
/usr/share/doc/python/changelog.Debian.gz
/usr/share/doc/python2.7/python-policy.txt.gz
/usr/share/doc/python2.7/python-policy.html
/usr/share/doc/python2.7/python-policy.sgml.gz
/usr/bin/2to3
/usr/bin/pygettext
/usr/bin/pydoc
/usr/bin/pdb

Install PIP for downloading Python supporting packages:

 sudo apt-get install python-pip


Use the following command to check list of installed packages:
 
dpkg --get-selections | grep -v deinstall > ~/Desktop/packages
 
(the -v tag "inverts" grep to return non-matching lines)  

Install Ipython Notebook 

                             pip install "ipython[notebook]"                  

Install it with super user privilege 

 

Uninstall Opencv Library packages in Ubuntu

Just Run the command bellow as a sudo user: 
 
sudo apt-get autoremove opencv-doc opencv-data libopencv-dev 
libopencv2.4-java libopencv2.4-jni python-opencv libopencv-core2.4 
libopencv-gpu2.4 libopencv-ts2.4 libopencv-photo2.4 libopencv-contrib2.4 
ibopencv-imgproc2.4 libopencv-superres2.4 libopencv-stitching2.4 libopencv-ocl2.4 
libopencv-legacy2.4 libopencv-ml2.4 libopencv-video2.4 libopencv-videostab2.4 
libopencv-objdetect2.4 libopencv-calib3d2.4 
 
It will remove all the packages listed above (Cross check if anything is missing by running
apt-cache search opencv) 

Do you want to continue? [Y/n] y
(Reading database ... 179318 files and directories currently installed.)
Removing libopencv-dev (2.4.8+dfsg1-2ubuntu1) ...
Removing libcv-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libcvaux-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv2.4-java (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv2.4-jni (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-videostab-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-videostab2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libhighgui-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-superres-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-stitching-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-ocl-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-stitching2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-superres2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-ocl2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-contrib-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-contrib2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-ts-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-legacy-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-ml-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-video-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-legacy2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-gpu-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-gpu2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-photo-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-ts2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-ml2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-objdetect-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-objdetect2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-photo2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing opencv-data (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-highgui-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopenexr-dev (1.6.1-7ubuntu1) ...
Removing libilmbase-dev (1.0.1-6ubuntu1) ...
Removing libopencv-calib3d-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-calib3d2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-video2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-features2d-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-features2d2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-flann-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-flann2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-imgproc-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-highgui2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libgtkglext1 (1.2.0-3.1fakesync3) ...
Removing libopenexr6:i386 (1.6.1-7ubuntu1) ...
Removing libilmbase6:i386 (1.0.1-6ubuntu1) ...
Removing libopencv-core-dev:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-imgproc2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Removing libopencv-core2.4:i386 (2.4.8+dfsg1-2ubuntu1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
 
Successfully UN-installed:
 

Install Anaconda 32 Bit Version In Linux

In Terminal:
 
Get 32 Bit Version:
 

Down Load Resent version of anaconda 
 
Install Now:
 
bash Anaconda-2.4.0-Linux-x86.sh 

Upon Agreeing License Agreement: Following Packages Will Be installed:


Do you approve the license terms? [yes|no]
[no] >>> y

Anaconda will now be installed into this location:
/home/arun/anaconda

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/home/arun/anaconda] >>>
PREFIX=/home/arun/anaconda
installing: python-2.7.10-0 ...
installing: conda-3.14.1-py27_0 ...
installing: conda-build-1.14.1-py27_0 ...
installing: conda-env-2.2.3-py27_0 ...
installing: _license-1.1-py27_0 ...
installing: abstract-rendering-0.5.1-np19py27_0 ...
installing: alabaster-0.7.3-py27_0 ...
installing: argcomplete-0.8.9-py27_0 ...
installing: astropy-1.0.3-np19py27_0 ...
installing: babel-1.3-py27_0 ...
installing: bcolz-0.9.0-np19py27_0 ...
installing: beautiful-soup-4.3.2-py27_0 ...
installing: binstar-0.11.0-py27_0 ...
installing: bitarray-0.8.1-py27_0 ...
installing: blaze-core-0.8.0-np19py27_0 ...
installing: blz-0.6.2-np19py27_1 ...
installing: bokeh-0.9.0-np19py27_0 ...
installing: boto-2.38.0-py27_0 ...
installing: bottleneck-1.0.0-np19py27_0 ...
installing: cairo-1.12.18-4 ...
installing: cdecimal-2.3-py27_0 ...
installing: certifi-14.05.14-py27_0 ...
installing: cffi-1.1.0-py27_0 ...
installing: clyent-0.3.4-py27_0 ...
installing: colorama-0.3.3-py27_0 ...
installing: configobj-5.0.6-py27_0 ...
installing: cryptography-0.9.1-py27_0 ...
installing: curl-7.43.0-0 ...
installing: cython-0.22.1-py27_0 ...
installing: cytoolz-0.7.3-py27_0 ...
installing: datashape-0.4.5-np19py27_0 ...
installing: decorator-3.4.2-py27_0 ...
installing: docutils-0.12-py27_0 ...
installing: dynd-python-0.6.5-np19py27_0 ...
installing: enum34-1.0.4-py27_0 ...
installing: fastcache-1.0.2-py27_0 ...
installing: flask-0.10.1-py27_1 ...
installing: fontconfig-2.11.1-4 ...
installing: freetype-2.5.2-2 ...
installing: funcsigs-0.4-py27_0 ...
installing: gevent-1.0.1-py27_0 ...
installing: gevent-websocket-0.9.3-py27_0 ...
installing: greenlet-0.4.7-py27_0 ...
installing: grin-1.2.1-py27_1 ...
installing: h5py-2.5.0-np19py27_3 ...
installing: hdf5-1.8.15.1-1 ...
installing: idna-2.0-py27_0 ...
installing: ipaddress-1.0.7-py27_0 ...
installing: ipython-3.2.0-py27_0 ...
installing: ipython-notebook-3.2.0-py27_0 ...
installing: ipython-qtconsole-3.2.0-py27_0 ...
installing: itsdangerous-0.24-py27_0 ...
installing: jdcal-1.0-py27_0 ...
installing: jedi-0.8.1-py27_0 ...
installing: jinja2-2.7.3-py27_1 ...
installing: jpeg-8d-0 ...
installing: jsonschema-2.4.0-py27_0 ...
installing: libdynd-0.6.5-0 ...
installing: libffi-3.0.13-0 ...
installing: libpng-1.6.17-0 ...
installing: libsodium-0.4.5-0 ...
installing: libtiff-4.0.2-1 ...
installing: libxml2-2.9.2-0 ...
installing: libxslt-1.1.28-0 ...
installing: llvmlite-0.5.0-py27_0 ...
installing: lxml-3.4.4-py27_0 ...
installing: markupsafe-0.23-py27_0 ...
installing: matplotlib-1.4.3-np19py27_2 ...
installing: mistune-0.5.1-py27_1 ...
installing: mock-1.0.1-py27_0 ...
installing: multipledispatch-0.4.7-py27_0 ...
installing: networkx-1.9.1-py27_0 ...
installing: nltk-3.0.3-np19py27_0 ...
installing: nose-1.3.7-py27_0 ...
installing: numba-0.19.1-np19py27_0 ...
installing: numexpr-2.4.3-np19py27_0 ...
installing: numpy-1.9.2-py27_0 ...
installing: odo-0.3.2-np19py27_0 ...
installing: openpyxl-1.8.5-py27_0 ...
installing: openssl-1.0.1k-1 ...
installing: pandas-0.16.2-np19py27_0 ...
installing: patsy-0.3.0-np19py27_0 ...
installing: pep8-1.6.2-py27_0 ...
installing: pillow-2.8.2-py27_0 ...
installing: pip-7.0.3-py27_0 ...
installing: pixman-0.26.2-0 ...
installing: ply-3.6-py27_0 ...
installing: psutil-2.2.1-py27_0 ...
installing: ptyprocess-0.4-py27_0 ...
installing: py-1.4.27-py27_0 ...
installing: py2cairo-1.10.0-py27_2 ...
installing: pyasn1-0.1.7-py27_0 ...
installing: pycosat-0.6.1-py27_0 ...
installing: pycparser-2.14-py27_0 ...
installing: pycrypto-2.6.1-py27_0 ...
installing: pycurl-7.19.5.1-py27_2 ...
installing: pyflakes-0.9.2-py27_0 ...
installing: pygments-2.0.2-py27_0 ...
installing: pyopenssl-0.15.1-py27_1 ...
installing: pyparsing-2.0.3-py27_0 ...
installing: pyqt-4.11.3-py27_1 ...
installing: pytables-3.2.0-np19py27_0 ...
installing: pytest-2.7.1-py27_0 ...
installing: python-dateutil-2.4.2-py27_0 ...
installing: pytz-2015.4-py27_0 ...
installing: pyyaml-3.11-py27_1 ...
installing: pyzmq-14.7.0-py27_0 ...
installing: qt-4.8.6-3 ...
installing: readline-6.2-2 ...
installing: requests-2.7.0-py27_0 ...
installing: rope-0.9.4-py27_1 ...
installing: runipy-0.1.3-py27_0 ...
installing: scikit-image-0.11.3-np19py27_0 ...
installing: scikit-learn-0.16.1-np19py27_0 ...
installing: scipy-0.15.1-np19py27_0 ...
installing: setuptools-17.1.1-py27_0 ...
installing: sip-4.16.5-py27_0 ...
installing: six-1.9.0-py27_0 ...
installing: snowballstemmer-1.2.0-py27_0 ...
installing: sockjs-tornado-1.0.1-py27_0 ...
installing: sphinx-1.3.1-py27_0 ...
installing: sphinx_rtd_theme-0.1.7-py27_0 ...
installing: spyder-2.3.5.2-py27_0 ...
installing: spyder-app-2.3.5.2-py27_0 ...
installing: sqlalchemy-1.0.5-py27_0 ...
installing: sqlite-3.8.4.1-1 ...
installing: ssl_match_hostname-3.4.0.2-py27_0 ...
installing: statsmodels-0.6.1-np19py27_0 ...
installing: sympy-0.7.6-py27_0 ...
installing: system-5.8-2 ...
installing: terminado-0.5-py27_0 ...
installing: theano-0.7.0-np19py27_0 ...
installing: tk-8.5.18-0 ...
installing: toolz-0.7.2-py27_0 ...
installing: tornado-4.2-py27_0 ...
installing: ujson-1.33-py27_0 ...
installing: unicodecsv-0.9.4-py27_0 ...
installing: util-linux-2.21-0 ...
installing: werkzeug-0.10.4-py27_0 ...
installing: xlrd-0.9.3-py27_0 ...
installing: xlsxwriter-0.7.3-py27_0 ...
installing: xlwt-1.0.0-py27_0 ...
installing: yaml-0.1.6-0 ...
installing: zeromq-4.0.5-0 ...
installing: zlib-1.2.8-0 ...
installing: anaconda-2.3.0-np19py27_0 ...
installing: _cache-0.0-x0 ...
Python 2.7.10 :: Continuum Analytics, Inc.
creating default environment...
installation finished.
Do you wish the installer to prepend the Anaconda install location
to PATH in your /home/arun/.bashrc ? [yes|no]
[no] >>> y

Prepending PATH=/home/arun/anaconda/bin to PATH in /home/arun/.bashrc
A backup will be made to: /home/arun/.bashrc-anaconda.bak


For this change to become active, you have to open a new terminal.

Thank you for installing Anaconda!

Apt-Get To Install Package

From Ubuntu Documentation

Introduction to APT

"In the beginning there was the .tar.gz. Users had to compile each program that they wanted to use on their GNU/Linux systems. When Debian was created, it was deemed necessary that the system include a method of managing the packages installed on the machine. The name dpkg was given to this system. Thus the famous 'package' first came into being on GNU/Linux, a while before Red Hat decided to create their own 'rpm' system.
 
A new dilemma quickly took hold of the minds of the makers of GNU/Linux. They needed a rapid, practical, and efficient way to install packages that would manage dependencies automatically and take care of their configuration files while upgrading. Here again, Debian led the way and gave birth to APT, the Advanced Packaging Tool, which has since been ported by Conectiva for use with rpm and has been adopted by some other distributions."
-- From Debian APT HOWTO

Commands

IconsPage/info.png All these commands except the search commands must be run as root or with superuser privileges, see sudo for more information.
  • IconsPage/example.png
    sudo apt-get install ubuntu-desktop 

Installation commands

  • apt-get install <package_name> 
    This command installs a new package.
  • apt-get build-dep <package_name> 
    This command searches the repositories and installs the build dependencies for <package_name>. If the package is not in the repositories it will return an error.
  • aptitude install <package_name>
    Aptitude is an Ncurses viewer of packages installed or available. Aptitude can be used from the command line in a similar way to apt-get. See man aptitude for more information.
  • APT and aptitude will accept multiple package names as a space delimited list. For example:
    apt-get install <package1_name> <package2_name> <package3_name>

auto-apt

  • auto-apt run <command_string>
    When invoked, the auto-apt command automatically installs packages upon missing file access. If a program tries to access a file known to belong in an uninstalled package, auto-apt will install that package using apt-get. This feature requires apt and sudo to work.

  • Auto-apt keeps databases which need to be kept up-to-date in order for it to be effective. This is achieved by calling the commands auto-apt update, auto-apt updatedb and auto-apt update-local. 
  • Usage example
    • IconsPage/example.png You're compiling a program and, all of a sudden, there's an error because it needs a file you don't have. The program auto-apt asks you to install packages if they're needed, stopping the relevant process and continuing once the package is installed.
           # auto-apt run ./configure
      It will then ask to install the needed packages and call apt-get automatically. If you're running X, a graphical interface will replace the default text interface.
    • Maintenance commands

    • apt-get update
      Run this command after changing /etc/apt/sources.list or /etc/apt/preferences . For information regarding /etc/apt/preferences, see PinningHowto. Run this command periodically to make sure your source list is up-to-date. This is the equivalent of "Reload" in Synaptic or "Fetch updates" in Adept.
    • apt-get upgrade
      This command upgrades all installed packages. This is the equivalent of "Mark all upgrades" in Synaptic.
    • apt-get dist-upgrade
      The same as the above, except add the "smart upgrade" checkbox. It tells APT to use "smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of less important ones if necessary.
      IconsPage/note.png "apt-get dist-upgrade" does not perform distribution upgrade. See [http://www.ubuntu.com/getubuntu/upgrading upgrading] for more information.
    • apt-get check
      This command is a diagnostic tool. It does an update of the package lists and checks for broken dependencies.
    • 
      
    •  
    • apt-get -f install
      This command does the same thing as Edit->Fix Broken Packages in Synaptic. Do this if you get complaints about packages with "unmet dependencies".

    • apt-get autoclean
      This command removes .deb files for packages that are no longer installed on your system. Depending on your installation habits, removing these files from /var/cache/apt/archives may regain a significant amount of diskspace.

    • apt-get clean
      The same as above, except it removes all packages from the package cache. This may not be desirable if you have a slow Internet connection, since it will cause you to redownload any packages you need to install a program.
      • The package cache is in /var/cache/apt/archives . The command
        du -sh /var/cache/apt/archives
        will tell you how much space cached packages are consuming.
      •  
    • dpkg-reconfigure <package_name>
      Reconfigure the named package. With many packages, you’ll be prompted with some configuration questions you may not have known were there.
      • IconsPage/example.png For example:

List of Basic Commands in Ubuntu

sudo: Executing Commands with Elevated Privileges

  • Most of the following commands will need to be prefaced with the sudo command. This elevates privileges to the root-user administrative level temporarily, which is necessary when working with directories or files not owned by your user account. When using sudo you will be prompted for your password. Only users with sudo (administrative) privileges will be able to use this command. You should never use normal sudo to start graphical applications as root. (Please see RootSudo for more information on using sudo correctly.)

File & Directory Commands

  • The tilde (~) symbol stands for your home directory. If you are user, then the tilde (~) stands for /home/user
  • pwd: The pwd command will allow you to know in which directory you're located (pwd stands for "print working directory"). Example: "pwd" in the Desktop directory will show "~/Desktop". Note that the GNOME Terminal also displays this information in the title bar of its window. A useful gnemonic is "present working directory."
  • ls: The ls command will show you ('list') the files in your current directory. Used with certain options, you can see sizes of files, when files were made, and permissions of files. Example: "ls ~" will show you the files that are in your home directory.
  • cd: The cd command will allow you to change directories. When you open a terminal you will be in your home directory. To move around the file system you will use cd. Examples:
    • To navigate into the root directory, use "cd /"
    • To navigate to your home directory, use "cd" or "cd ~"
    • To navigate up one directory level, use "cd .."
    • To navigate to the previous directory (or back), use "cd -"
    • To navigate through multiple levels of directory at once, specify the full directory path that you want to go to. For example, use, "cd /var/www" to go directly to the /www subdirectory of /var/. As another example, "cd ~/Desktop" will move you to the Desktop subdirectory inside your home directory.
  • cp: The cp command will make a copy of a file for you. Example: "cp file foo" will make an exact copy of "file" and name it "foo", but the file "file" will still be there. If you are copying a directory, you must use "cp -r directory foo" (copy recursively). (To understand what "recursively" means, think of it this way: to copy the directory and all its files and subdirectories and all their files a
    • and subdirectories of the subdirectories and all their files, and on and on, "recursively")
    • mv: The mv command will move a file to a different location or will rename a file. Examples are as follows: "mv file foo" will rename the file "file" to "foo". "mv foo ~/Desktop" will move the file "foo" to your Desktop directory, but it will not rename it. You must specify a new file name to rename a file.
      • To save on typing, you can substitute '~' in place of the home directory.
      • Note that if you are using mv with sudo you can use the ~ shortcut, because the terminal expands the ~ to your home directory. However, when you open a root shell with sudo -i or sudo -s, ~ will refer to the root account's home directory, not your own.
    • rm: Use this command to remove or delete a file in your directory.
    • rmdir: The rmdir command will delete an empty directory. To delete a directory and all of its contents recursively, use rm -r instead.
    • mkdir: The mkdir command will allow you to create directories. Example: "mkdir music" will create a directory called "music".
    • man: The man command is used to show you the manual of other commands. Try "man man" to get the man page for man itself. See the "Man & Getting Help" section down the page for more information.
    • sudo: The sudo command is used to perform file operations on files that the Root User would only be allowed to change. An example would be trying to move one of your documents that another user accidentally moved to / back to your documents directory. Normally, to move the file, you would type mv /mydoc.odt ~/Documents/mydoc.odt, but you are not allowed to modify files outside of your home directory. To get around this, you would type sudo mv /mydoc.odt ~/Documents/mydoc.odt. This will successfully move the file back to its correct location, provided that you are not a standard user, who has less (administrative) ability than an administrator. Be aware, though, that by using the sudo command, you need to be extra careful. It is easier to damage your system by using the sudo command. For more information about the sudo command, click here

      Running a File Within a Directory

      So you've decided to run a file using the command-line? Well... there's a command for that too!
    • ./filename.extension
    After navigating to the file's directory, this command will enable any Ubuntu user to run files compiled via GCC or any other programming language. Although the example above indicates a file name extension, please notice that, differently from some other operating systems, Ubuntu (and other Linux-based systems) do not care about file extensions (they can be anything, or nothing). Keep in mind that the 'extension' will vary depending upon the language the source code is written in. Also, it is not possible, for compiled languages (like C and C++) to run the source code directly -- the file must be compiled first, which means it will be translated from a human-readable programming language to something the computer can understand. Some possible extensions: ".c" for C source, ".cpp" for C++, ".rb" for Ruby, ".py" for Python, etc. Also, remember that (in the case of interpreted languages like Ruby & Python) you must have a version of that language installed on Ubuntu before trying to run files written with it.
    Finally, the file will only be executed if the file permissions are correct -- please see the FilePermissions help page for details.

    System Information Commands

  • df: The df command displays filesystem disk space usage for all mounted partitions. "df -h" is probably the most useful - it uses megabytes (M) and gigabytes (G) instead of blocks to report. (-h means "human-readable")
  • du: The du command displays the disk usage for a directory. It can either display the space used for all subdirectories or the total for the directory you run it on. Example:
user@users-desktop:~$ du /media/floppy
1032    /media/floppy/files
1036    /media/floppy/
user@users-desktop:~$ du -sh /media/floppy
1.1M    /media/floppy/
  • -s means "Summary" and -h means "Human Readable"
  • free: The free command displays the amount of free and used memory in the system. "free -m" will give the information using megabytes, which is probably most useful for current computers.
  • top: The top ('table of processes') command displays information on your Linux system, running processes and system resources, including CPU, RAM & swap usage and total number of tasks being run. To exit top, press "q"

    • uname -a: The uname command with the -a option prints all system information, including machine name, kernel name & version, and a few other details. Most useful for checking which kernel you're using.
    • lsb_release -a: The lsb_release command with the -a option prints version information for the Linux release you're running, for example:
    user@computer:~$ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 11.10
    Release:        11.10
    Codename:       oneiric
  • ip addr reports on your system's network interfaces.

Adding A New User

  • "adduser newuser" command will create a new general user called "newuser" on your system, and to assign a password for the newuser account use "passwd newuser".

Options

The default behaviour for a command may usually be modified by adding a --option to the command. The ls command for example has an -s option so that "ls -s" will include file sizes in the listing. There is also a -h option to get those sizes in a "human readable" format.
Options can be grouped in clusters so "ls -sh" is exactly the same command as "ls -s -h". Most options have a long version, prefixed with two dashes instead of one, so even "ls --size --human-readable" is the same command.

"Man" and getting help

Warning /!\ man command, info command and command --help are the most important tools at the command line.
  • Nearly every command and application in Linux will have a man (manual) file, so finding them is as simple as typing "man "command"" to bring up a longer manual entry for the specified command. For example, "man mv" will bring up the mv (move) manual.
    Move up and down the man file with the arrow keys, and quit back to the command prompt with "q".
    "man man" will bring up the manual entry for the man command, which is a good place to start!
    "man intro" is especially useful - it displays the "Introduction to user commands" which is a well-written, fairly brief introduction to the Linux command line.
    There are also info pages, which are generally more in-depth than man pages. Try "info info" for the introduction to info pages.
    Some software developers prefer info to man (for instance, GNU developers), so if you find a very widely used command or app that doesn't have a man page, it's worth checking for an info page.
    Virtually all commands understand the -h (or --help) option which will produce a short usage description of the command and it's options, then exit back to the command prompt. Try "man -h" or "man --help" to see this in action.
    Caveat: It's possible (but rare) that a program doesn't understand the -h option to mean help. For this reason, check for a man or info page first, and try the long option --help before -h.

    Searching for man files

    If you aren't sure which command or application you need to use, you can try searching the man files.
  • man -k foo will search the man files for foo. Try "man -k nautilus" to see how this works.
    • Note that this is the same as doing apropos command.
  • man -f foo searches only the titles of your system's man files. Try "man -f gnome", for example.
    • Note that this is the same as doing whatis command.