Archive for the ‘Programming’ Category

Install Deepnet on Mac

November 15, 2013 3 comments

This may help to have Nitish’s deepnet work on your mac. The code is very clean, most important thing is to follow the instructions here


a) You will need Numpy, Scipy installed first, because the tools is largely python. Simply way is to use ‘brew‘. For example, follow the instructions here.

b) CUDA Toolkit and SDK.
Follow the instructions(CUDA5.5):
NVIDIA CUDA Toolkit (available at

I followed both instruction on
and instruction from the deepnet to set the system paths:

export PATH=/Developer/NVIDIA/CUDA-5.5/bin:$PATH

Follow the deepnet instruction: for mac, it is the ‘~.profile’, edit/add to the file:

export CUDA_BIN=/usr/local/cuda-5.0/bin
export CUDA_LIB=/usr/local/cuda-5.0/lib

First make sure CUDA installed right:
install the examples: <dir>

and go to /Developer/NVIDIA/CUDA-5.5/samples, choose any simple example subfolder, go into and do ‘make’, after make completed, you can do a simple test.

(c) Protocol Buffers.

Download the file:

Follow the instructions to compile/install it.  It will be install (generally in /usr/local/bin/protoc). It was said that you only need to include the directory that contains ‘proc’, so add to path:
export PATH=$PATH:/usr/local/bin


For making the cuda work, do ‘make’ in cudamat , but change all the ‘uint’ to ‘unsigned’ in file: cudamat_conv_kernels.cuh
or do a #define uint unsigned
Then run ‘make’ in cudamat folder

(3,4) STEP 3,4

continue follow step 3, and 4 on you will get there.

Note (1): I did not install separately for  cudamat library by Vlad Mnih and cuda-convnet library by Alex Krizhevsky.

Note (2): If you do NOT have GPU: another alternative is to not use GPU, most recent mac come with NVIDIA 650, but some old version may use intel graphical card. In that case you can still do the deep learning part, but using eigenmat. The drawback is that it will be very slow. 

Install eigen from here:
if given error <Eigen/..> can not found, change to “Eigen/…”
also you need to change python path, including path to where ‘libeigenmat.dylib’ located. It it still fails to find: libeigenmat.dylib. It may not hurt to give it a direct path, edit the file <eigenmat/>.
_eigenmat = ct.cdll.LoadLibrary(‘the-path-to/libeigenmat.dylib’)


Use Amazon-Turk Command-line tool

October 1, 2012 Leave a comment

AMT-CMD tool box
Do svn to get all the src

  •  Follow instunctions of the UserGuide.html (aws-mturk-clt-1.3.1) to set MTURK_CMD_HOME and JAVA_HOME to point to correct locations.
  •  Also, follow the UserGuide to set up the your-personal-access-key-information in the property file, and pay attention to activate the sanbox server(disable the production server) if you want to give a few try first. I found that I have to change the http to https (of the api address), in order to make it work.

JAVA_HOME=/usr                 (for example)

Configure env.source  in command_line_wrappers
Edit your-path-to-thecvAnotationtool/command_line_wrappers/env.source:
Set CODE_ROOT to point to your-path-to-thecvAnotationtool/command_line_wrappers
Set MTURK_CMD_HOME and JAVA_HOME to point to correct locations
Run bash and do source your-path-to-thecvAnotationtool/command_line_wrappers/env.source (every time you start new shell). Alternatively place it in your .bashrc .

Example 1 — standard AMT –cmd job example  (helloword, best_image, etc)
Follow the UserGuide, down the page, there are several examples, you can simply follow the instruction to run any of them.

Example 2
From the downloaded your-path-to-thecvAnotationtool folder, go to <tasks/attributes_grid>
Do command line run:
../../../command_line_wrappers/ –sandbox

Fix UIActionSheet Cancel Button

May 22, 2012 Leave a comment

I found that using the UIActionSheet, it seems that the “Cancel” button does not function well. It turns out to be a normal problem, where here gives the right answer. I followed the instruction and changed the code (self — is the


[self.actionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)


[self.actionSheet showInView:self.parentViewController.tabBarController.view];

Categories: MacOS, Objective-C, Programming

Tutorial Sites For iOS Developer

April 7, 2012 Leave a comment

Cocoa & Objective-C is the base of Mac Os X.
Objective-C Language is an extensive to C and makes C OO(Object Oriented).

ObjectiveC Quick Learning:

ObjectiveC Tutorial:    ( very cool one)

How to generate certificat signing request ( I like their QA part, include a lot of basic points you will need to start your ios development):

The developer video site:

Delegate is sth like callback function or notify mechanism. When some events happens, we call the corresponding method defined in the delegate class. As to application delegate, the delegate object specified in the UIApplicationMain is responsible to respond to the event which will affect the whole application. For example, when the application is about to run out of memory, the method ‘didReceiveMemoryWarning’ is invoked, and this is defined by an ObjectiveC protocal——UIApplicationDelegate. This protocal defines when and which delegate method should be invoked. For an application delegate class, it should declare in its .h file that it will implement a certain protocal , and then implement all the method which was not taged with ‘optional’ in the protocal.

For example:
There are a lot of other delegate protocal defined in the iPhone. If we want to implement some delegate class to handle certain events generated from a text field in the UI, we can choose UITextFieldDelegate protocal. This protocal defines the methods which will be invoked by the events which are generated by a text, like content changed.
The last thing we need to do is to assign the delegate class of a certain control or view with the delegate class we just implemented.

Some useful links:

iPhone Camera Focussing:


OpencvFrameWork for iOS:

UIColor CheatSheet:  ~~~ I love this one 🙂

The Coordinates of CGRectMake

Categories: MacOS, Programming, Video Tags: ,

Install Port on Mac

March 30, 2012 Leave a comment

Eventually, get the Port installed on my Mac. Here’s the step:

Download source of port or the dmp for your mac

For Source(this is from the official Port site, just follow the step):

  1. “cd” into the directory where you downloaded the package and run “tar xjvf MacPorts-2.0.4.tar.bz2” or “tar xzvf MacPorts-2.0.4.tar.gz”, depending on whether you downloaded the bz2 tarball or the gz one, respectively.
  2. Build and install the recently unpacked sources:
    • cd MacPorts-2.0.4
    • ./configure && make && sudo make install

Alternatively, you can also use their “dmg” disk images for Lion and Snow Leopard. It’s very simple, just double click the downloaded dmg, follow the steps 🙂

OK, then here’s my problem. When I open the terminal, my port is not there! Why? You have to update your profile.

  • Change your profile to include MacPort in the PATH, add the following

vi $HOME/.profile


# MacPort

export PATH=$PATH:/opt/local/bin

  • Don’t forget to Source your profile to include the changes, in the terminal, type:

. $HOME/.profile


Now, update the port:

sudo port -v selfupdate

and install packages with

sudo port install <package name>


By default, you port is install at

So you can do this too without update your profile:

                        sudo /opt/local/bin/port -v selfupdate

Categories: Programming

Python CGI Display Image

February 27, 2012 Leave a comment

I was trying to write a simple html using python-cgi. It’s really a powerful tool ~ However, I had some problems of displaying the image with text. Here’s what I found:

1. You should only define one type of your html file. It should be either , or .  You can’t combine them! Basically, you would like to choose text type, but use the <img> tag to include your image.

2. Using <img> tag, the src field should be the link to the image.  Your images in web page is actually a second request to the server, so it should be a reference to the image — in other words, it should be “the url to your image”.

3. So, a question is, for example for my case, my web page is actually “self-usage” ( though sounds stupid) which I want to use it to display images in my local folder as well (not only images from another web url) — how can I do this? Here’s two different ways I found.

(a) put your image (you can also try other media files) into /cgi-bin/. For me I create a subfolder /cgi-bin/images. It seems that the server can found items under cgi-bin — I mean, each item under your cgi-bin actually has a url.  such as http://localhost:8000/cgi-bin/image/001.jpg . This will provide you a valid url for your image that you want to include.

(b) Since we have define our web as ‘text’. So to display an image read from local folder, you need to format the image somehow. Here’s what may work for you:

data_uri = open(r'D:/TEMP/yourimg.jpg', 'rb').read().encode('base64').replace('\n', '')
img_tag = '<img src="data:image/jpeg;base64,{0}" alt="" />'.format(data_uri)


You can get more information from here:

A tutorial of some basic examples of using python-cgi:

Categories: Programming, Python Tags: ,

Use boto run user-data in AWS instance

January 4, 2012 Leave a comment

I am using boto to launch the instance run the user-code in the background, but find that it’s not so convenient to debug and get the error information. Here’s finally what I did. Use the traceback to get the error, use smtp to send back the error information to my email. There must be some other cleverer ways to do so, ha ~

import boto
from boto.ec2.connection import EC2Connection
import time

ami_id = '----'                                                  # ami-ubuntu-64 (settedup) use t1.micro as instance type
key_pair_name = '----'


test_script_00 = """#!/bin/bash
sudo apt-get update
sudo apt-get install imagemagick

test_script_01 = """#!/usr/bin/env python
 import boto
 from boto.s3.key import Key

AWS_ACCESS_KEY_ID = '-------'

bucket_name = 'demo-test'
conn_s3 = boto.connect_s3(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY)
bucket = conn_s3.get_bucket(bucket_name)

k.copy('demo-test', 'images/rose111105copy6.jpg')

test_script ="""#!/usr/bin/env python
import smtplib
import boto
from boto.s3.key import Key
import numpy as np
import sys

AWS_ACCESS_KEY_ID = '-----' # Your AWS_KEY
AWS_SECRET_ACCESS_KEY = '---------' # Your Secret KEY

def send_notice(msg='testing'):
    fromaddr = '******'
    toaddrs = '******'
    username = '******'
    password = '******'
    server = smtplib.SMTP('')
    server.sendmail(fromaddr, toaddrs, msg)

send_notice("start processing")

my_reservation = ec2conn.run_instances(ami_id,

instance = my_reservation.instances[0]
while not instance.update() == 'running':