Saturday, October 7, 2017

Run mnist example on Caffe


  1. Go to Caffe folder. 
  2. sudo sh data/mnist/get_mnist.sh
  3. sudo sh examples/mnist/create_mnist.sh
  4. sudo vi examples/mnist/lenet_solver.prototxt
  5. sudo time sh examples/mnist/train_lenet.sh
Done
http://blog.csdn.net/xzy_thu/article/details/70842934

Install Caffe on Ubuntu 16.04 (CPU only)


  1. Install a clean Ubuntu 16.04 and mkdir workspace
  2. sudo apt install git and git clone https://github.com/BVLC/caffe
  3. sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
  4. sudo apt-get install libatlas-base-dev
  5. sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
  6. Go to python folder inside the caffe directory: cd python/
  7. Install pip: sudo apt install python-pip
  8. Upgrade pip: sudo -H pip install --upgrade pip
  9. Install all the dependency in requirements.txt via: 
    1. for req in 'cat requirements.txt'; do pip install $req; done
    2. sudo pip install -r requirements.txt
  10. sudo apt-get install python-dev
  11. sudo apt-get install -y python-numpy python-scipy
  12. sudo apt-get install --no-install-recommends libboost-all-dev
  13. Go to caffe folder and cp Makefile.config.example Makefile.config. 
  14. Edit Makefile.config: 
    1. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
    2. LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
    3. Uncomment: CPU_ONLY := 1 if this is CPU only mode
  15. Now make!
    1. make pycaffe
    2. make all
    3. make test
    4. make runtest
    5. make distribute
  16. export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
  17. Verify by running python2.7:
    1. >>> import caffe
    2. >>> caffe._version__
  18. Install opencv: 
    1. sudo apt-get install python-opencv
    2. sudo pip install opencv-python
  19. Install lmdb: sudo pip install lmdb
You should be able to see All Pass. Happy Ending. 
http://blog.csdn.net/qq_25737169/article/details/77773884

Thursday, August 27, 2015

How to achieve splitting equally to N number of people using a coin

What do I mean to split equally to N number of people using a coin? For example, we have a group of six people. Suppose we need a coin to decide who's going to buy the group a round of drink and we have to make this decision unbiased. All we have is a quarter. What can we do about this coin? We can't make this coin into a dice.. :(

Analysis:
We start to notice that flip a coin once makes each 1/2 equally.
If we define flip twice and define both head, head first and then tail, tail first and then head, and both tails as four different outcomes then we have 1/4 (1/2 * 1/2).
Same applies when we flip three times, which give 1/8 (1/2 * 1/2 * 1/2).

Here's the solution:
Suppose head represents 0 and tail is 1 when we flip the coin.
Flip 3 times of coin
Denote each time's result as 0 or 1.
000 – 3 heads
001 – head, head, tail
010 – head, tail, head
011 – head, tail, tail
100 – tail, head, head
101 – tail, head, tail
110 – tail, tail, head
111 – 3 tails

There are eight of them all with 1/8 possibility. We can simply use 6 of them and discard the rest. If the group of people is beyond 8 people then we can simply add one more flip to increase the range up to 16 (1/2 * 1/2 * 1/2 * 1/2).

Thursday, September 18, 2014

Java - Hash Tables

A simple hash function:
h(k)=k mod N.
If a hash function is chosen well, it should guarantee that the probability that two different keys get hashed to the same bucket is at most 1/N. Therefore, instead, the below hash function is more appropriate:
h(k)= (ak+b) mod N.

Android Development using Python in Linux (Ubuntu)

There are a few steps:
Prerequisite:
$ sudo apt-get install python-setuptools python-pygame python-opengl python-gst0.10 python-enchant gstreamer0.10-plugins-good cython python-dev build-essential libgl1-mesa-dev libgles2-mesa-dev

$ python
>>> import pkg_resources
>>> print pkg_resources.resource_filename('kivy', '../share/kivy-examples')
# Copy the address
>>> exit()

$ ln -s address

# Check the kivy examples
$ cd kivy-examples
$ cd demo/touchtracer
$ python main.py

Build the distribution
./distribute.sh -m "kivy"
The file "distribute.sh" can be found at /home/bz/python-for-android


Linux for dummies like myself


You will be amazed about how incredible the materials out there from which we can learn. Below is some:

Ryan's Tutorial has this amazing Linux basic tutorial:
http://ryanstutorials.net/linuxtutorial/

I have learned a lot about bash command in Linux system from Ryan's Tutorial.

I found the book "Linux All-in-One For Dummies" very informative about Linux system you may need. More importantly, you can get it free from IT ebooks for free.


It's quite different to issue all kinds of commands in the shell in Linux system. Although it seems hard to get on your hand at the first sight, you may be quite familiar with how things work after you get to know some basic commands and get your hand wet in this.

grep can be used to search this keyword in a file/log in Linux. It's very handy feature to search. The system will provide the search result in no time. It's suitable to extract the specific thing you can looking for in some large files. e.g. grep "keyword" /destination/location. Another example: scan_r |grep delay; the command is also known as a combined command.

cat displays the content of a file on the command screen. e.g. cat /home/file

at any stage, if you feel like to issue the command in more than one line, and would like to break a line into a new line, you can use backslash \.
e.g. ls /etc; cat \
file |grep name

Asterisk (*): Matches zero or more characters in a filename. That means* denotes all files in a directory.

Question mark (?): Matches any single character. If you type test?, thatmatches any five-character text that begins with test.

Set of characters in brackets: Matches any single character from that set. The string [aB], for example, matches only files named a or B, The string [aB]*, though, matches any filename that starts with a or B.

cp can copy a file/directory from one location to another. e.g. cp -avr /source/location /dest/location

Two takeout note for new learner like me:
1. up-arrow is your best companion... it can bring up all history command that's ever issued in that command window. It will become handy when you ask somebody to perform some tasks and you can review and learn the command afterwards. Also, Tab button saves a lot of time to type something in full... double press Tab can bring up any files that match your current partial input if there's any.
2. avoid using space in file name. If you do use a space in a filename, you have to use backslash \ before each space. If you want to copy the file it would also cause problem... If you have to deal with tons of files, say PNG screenshots, that contains space in it, just tar (compress approach) everything would do the trick.