gae python – importerror: no module named webapp2

Scenario:
– Google app engine with Python on Ubuntu
– Running the local development server.

If you start getting this error:

"importerror: no module named webapp2"

after running,
$ dev_appserver.py helloworld/

You might want to go back to an earlier version for local development.

After downloading “google_appengine_1.9.37.zip

I got errors with import webapp2

Luckily, I had a previous version “google_appengine_1.9.34.zip”

So I deleted 1.9.37. And used 1.9.34 instead.

Maybe this will work for you.

How to run an IPython/Jupyter Notebook on a remote machine

Here’s how to run an IPython/Jupyter Notebook on a remote Linux machine without using VNC. I expanded on these instructions.

Let’s assume you have two machines:
local-machine that you are physically working on
remote-machine that you want to run code on.

And you want to work in the browser on your local-machine, but execute the code on the remote-machine.

Here are the important lines you’re probably looking for:

jupyter notebook --no-browser --port=8898
ssh -N -f -L 127.0.0.1:8898:127.0.0.1:8898 jer@remote-machine
http://127.0.0.1:8898/

If you want complete and detailed steps, keep reading below!

Continue reading “How to run an IPython/Jupyter Notebook on a remote machine”

CAFFE – how to specify which GPU to use in PyCaffe

You are using PyCaffe (Python interface for Caffe) and training a deep neural network directly within Python (although I think the same command holds for MATLAB).

You are on a machine with 2 GPUs and you want to specify which GPU to use for training. This is useful so you can train two different models at the same time on each GPU. Note that here we refer to training two different models on two different GPUs on the same machine, not a single model on two GPUs.

(side note: it seems to me that running two different jobs on the same GPU drastically slows GPU training. It’s so much slower that I only train a single model on a single GPU at a time. Running two different jobs on two different GPUs seems to be okay though)
Continue reading “CAFFE – how to specify which GPU to use in PyCaffe”

How to display an IPython notebook in a WordPress blog

So I wanted to to add an IPython notebook within a WordPress blog post. The first thing I tried was exporting directly to HTML, and copying the HTML directly within the WordPress post. This sort of worked. However, it was very slow to copy all the HTML into the post and the formatting looked terrible.

Then I came across a way to do so, which you can read about here.

The basic idea from above is to export the IPython notebook to HTML, upload it somewhere on your site, and then use an “iframe” to embed the IPython notebook HTML within the WordPress blog post. The author of the above then wrote some javascript to handle sizing issues.

However, I did not want people to be able to directly access the IPython notebook HTML page (if say google indexed it). Rather I want to direct people to the actual WordPress post.

So in the end, I simply add some javascript to the IPython notebook to redirect to the WordPress blog post.

Here are the steps to add an IPython notebook to a WordPress blog post:
Continue reading “How to display an IPython notebook in a WordPress blog”

Notes on a Conversation with Donald Knuth

Donald Knuth chatting at UBC
Donald Knuth chatting at UBC

So I had the privilege of seeing Donald Knuth speak at UBC a few days ago. I was excited to see one of the eccentric Computing Science legends in real life.

The talk was in an interesting format. Knuth was in front of a relatively small theater, and simply answered any questions that were presented to him from the crowd. It was thus a spread of different questions and topics presented to him.

I took a few notes during the talk and I summarize the topics and Knuth’s responses here.

Knuth on writing:

  • translate to have less jargon
  • pays people to find errors in his books
  • write to have errors, that is, be precise and falsifiable (e.g. “13% improvement”, where this 13% can be verified)
  • have the history of discoveries with references
  • write about things that will be important 50 years from now
  • –> e.g. methods that are useful for many different applications
  • –> e.g. data structures, satisfiability problems

Continue reading “Notes on a Conversation with Donald Knuth”

theano – how to get the gpu to work

I have been working with Theano and it has been a bit of a journey getting the GPU to work. Here are a few notes to remind myself how to do so…

Start Python and check if Theano recognizes the GPU

$ python
Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Aug 21 2014, 18:22:21)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2

>>> import theano
Using gpu device 0: GeForce GTX 760 Ti OEM

You should see something like the above line showing that Theano finds your GPU.

If you do not see something like the above, then Theano probably is probably not configured to work with your GPU. But let’s check some more just to be sure.
Continue reading “theano – how to get the gpu to work”

Anaconda IPython Notebook – error: [Errno 99] Cannot assign requested address

So you want to run the IPython Notebook… and you’re using Anaconda 2.1.0 on some version of Linux.

You are already able to run ipython successfully…

$ ipython
IPython 2.2.0 -- An enhanced Interactive Python
[1]: exit()

But from the command line, when you try to run the IPython Notebook:

$ ipython notebook

You get a bunch of errors… something about sockets. The last error sticks out…

...
    return getattr(self._sock,name)(*args
error: [Errno 99] Cannot assign requested address

A bit of googling shows you some relevant links:

We summarize the two steps needed to get the Anaconda IPython Notebook working here.
Continue reading “Anaconda IPython Notebook – error: [Errno 99] Cannot assign requested address”

MATLAB – how to highlight select pixels in an image

You have an image, and you would like to highlight certain select pixels in the image a different color, say green.

Here’s how to draw and highlight specific pixels on an image while leaving the background intact.

orig
Before highlighting/blending pixels
blended
After selecting and highlighting pixels

Continue reading “MATLAB – how to highlight select pixels in an image”

MATLAB – TreeBagger example

Did you know that Decision Forests (or Random Forests, I think they are pretty much the same thing) are implemented in MATLAB? In MATLAB, Decision Forests go under the rather deceiving name of TreeBagger.

Here’s a quick tutorial on how to do classification with the TreeBagger class in MATLAB.

Continue reading “MATLAB – TreeBagger example”

Mean absolute error tutorial MATLAB

Here’s how to calculate the mean-absolute-error by hand in MATLAB

Basic idea: You have a set of numbers,

Actual = [1 2 3 4];

Then you have some method that tries to predict these numbers and returns some predicted values,

Predicted = [1 3 1 4];

You might now ask, “How do I evaluate how close the Predicted values are to the Actual values?”

Well one way is to take the mean absolute error (MAE) and report that.
Continue reading “Mean absolute error tutorial MATLAB”