Torch-rnn: Mac Install

TorchRNN_TinyShakespeare-web

Update! For El Capitan and users of newer version of OS X, you may run into issues installing Torch or Lua packages. A fix is included now.

Update number two! Zach in the comments offers a really helpful fix if you’re on Sierra.

Update three! A lot has changed since 2016, so I’ll be posting a new version of this tutorial soon. In the meantime, please see the comments for common sticking points and troubleshooting.

There have been many recent examples of neural networks making interesting content after the algorithm has been fed input data and “learned” about it. Many of these, Google’s Deep Dream being the most well-covered, use and generate images, but what about text? This tutorial will show you how to install Torch-rnn, a set of recurrent neural network tools for character-based (ie: single letter) learning and output – it’s written by Justin Johnson, who deserves a huge “thanks!” for this tool.

The details about how all this works are complex and quite technical, but in short we train our neural network character-by-character, instead of with words like a Markov chain might. It learns what letters are most likely to come after others, and the text is generated the same way. One might think this would output random character soup, but the results are startlingly coherent, even more so than more traditional Markov output.

Torch-rnn is built on Torch, a set of scientific computing tools for the programming language Lua, which lets us take advantage of the GPU, using CUDA or OpenCL to accelerate the training process. Training can take a very long time, especially with large data sets, so the GPU acceleration is a big plus.

Continue reading “Torch-rnn: Mac Install”

Visualizing Mac OS Commands

A early test for a series of images visualizing the fundamental commands (essentially tiny programs) that run the Mac OS, things like ls, cd, and zsh (above). Bits from the binary files (found in usr/bin) are shown as black or white pixels. Click on the image for a higher-res version, where you can more easily see individual bits.

Tutorial: Create A Readme-File Finder Shortcut

There are a few things I always do when starting a project: make a NotesAndIdeas.txt  and a Readme.md  file. But opening a blank text file and saving it to the right location is a pain. To the rescue: a Finder keyboard shortcut.

1. WRITE A LITTLE SCRIPT

01-web
We’ll use an AppleScript to create the files. This requires two parts: getting the current directory and creating the file using a bash script. In the notes file, I’m adding a header to the top of the file, but you could add any text you want. Newlines must be escaped with two backslash characters: \\n .

I save my scripts to a folder called Hacks to I can tweak them later, if necessary.

Continue reading “Tutorial: Create A Readme-File Finder Shortcut”

SDR/HackRF One: Mac Setup and Basics

HackRFOne-web

The HackRF One is a very nice software-defined radio (SDR). Though a good bit more expensive than other SDR hardware, it is very well made and Michael Ossmann of Great Scott Gadgets has put together an extensive set of free video tutorials. Of course, those only help if you have everything set up correctly to begin with.

It appears that most SDR work is done through Linux, which makes sense: SDR is classic hardware/software hacking. But for a Mac user, I found it somewhat difficult to get started. This short tutorial will hopefully help kickstart that process for you!

Continue reading “SDR/HackRF One: Mac Setup and Basics”

Computers I’ve Owned

While working on a piece, I made a list of every computer I’ve owned or used regularly. I thought that we be 5-6, but the list kept growing and is not at 18.

YEARMAKE/MODELNOTES
1988-96Apple IIGSUsed in elementary and middle school, mostly to play Number Munchers and Oregon Trail
1994-96486 of some kindUsed at home for DOS games (didn't really know how to do anything else)
1996-98Compaq Presario 5140Used at home, used for games, going on AOL, graphics programs - all with that distinctive power/sleep button
1998-2000Some kind of eMachines desktopUsed at home for games, going on the real internet, using a cracked version of Corel Draw that Steve gave me, building webistes using hand-written HTML and launching on Tripod
2000-2004Apple Power Macintosh G3 (Blue & White)Used at college (I'm pretty sure this is the kind we had), used mostly for Photoshop, Illustrator, and writing papers
2002-2004Toshiba Tecra 8000 laptopUsed while in college (passed down from my dad's office), recorded some crappy little songs using the built-in sound recording app and a plastic mic
2004-2006Gateway laptop (still unidentified)Also used in late college and in early grad school, used for recording music on a cracked version of Cakewalk, making art using cracked versions of all kinds of software
2006-2009Mac PowerBook 12" laptopUsed during grad school and after for EVERYTHING, mostly on cracked software, too :)
2009-11iPhone 3GSMy first smartphone, bought after I lost the charger to my crappy cellphone, played lots of Scrabble on this
2009-13MacBook Pro 15" (2x)Used at first teaching job with NO cracked software! (2 different computers of the same model)
2011-13iPhone 4Replaced my previous smartphone, donated the old one to Angeles, played lots of Angry Birds on this
2012-presentRaspberry Pi Model BBought very early on, now runs all my bots
2013-preseNexus 10 tabletBought using a grant, mostly to run Processing sketches
2013-presentMacBook Pro 15" w Retina DisplayCurrent workhorse
2014-presentMac MiniAlso bought using a grant, mostly for installations (and formerly for and running bots)
2014-presentiPhone 5sCurrent smartphone, mostly use for email and directions/maps

* A note: by computer I mean anything that can do significant processing, like a smartphone, not anything that does computation or runs programs. I’m also excluding computers that I’ve used but don’t work here, like supercomputers :)

 

Installing OpenCV on Mac

UPDATE: Mavericks users were likely frustrated for the last few weeks trying to install OpenCV. It appears the problem has been fixed, and these instructions should work without issue.

My previous post on installing OpenCV for Mac users is one of the most popular on this site (which is simultaneously surprising and fantastic). However, I recently switched from using MacPorts to Homebrew – users that need to migrate existing installs can check out this guide.

Still complicated but thoroughly do-able, here is how to install OpenCV on a Mac running Mountain Lion:

  1. Open Applications > Utilities > Terminal…
  2. Install Homebrew by typing the following into Terminal
  3. Run the command brew doctor to check for any errors
  4. While normal installations using Homebrew are very straightforward, for some reason OpenCV requires an extra step – you need to install an add-on called science:
  5. Then you can run the usual Homebrew command to install OpenCV:

    If this fails, it may be that you have ffmpeg installed – if so, try this instead:
  6. This may take several minutes, so be patient!
  7. Homebrew may tell you that you have to update  PYTHONPATH  – if so, open your favorite text editor, click File > Open… and hit command+shift+. to see hidden files
  8. Navigate up to your home folder and open the  .bash_profile  file – if it doesn’t exist, create it yourself
  9. Add the line suggested by Homebrew, probably something like:
  10. Save the file and close it – you may also have to exit Terminal and open it again
  11. Test by opening Python:

    Then try to import OpenCV:
  12. If you don’t get any errors, you’re all set! Now go enjoy a real beer!

Hope this helps! Problems, suggestions – leave them in the comments.

Installing OpenCV for Python on Mac Lion

Like previous installs of other command-line tools like FFMPEG, the frustration often does not seem worth the trouble.  Esoteric errors are near impossible to parse and files are installed in odd places (odd to me, at least).  Below are the steps I used to install the OpenCV library (blob detection, facial tracking, etc etc) for use with Python on my Mac, running 10.7.4 (Lion).

Much of this was pulled from a StackOverflow post (http://stackoverflow.com/a/6087778/1167783) but the suggestions would have been less helpful had they not be corroborated by several other posts with similar suggestions.  That said, this was the only guide I could find that worked well for me (thanks!).

  1. Install MacPorts (download here)
    If you haven’t already – this makes installation mucheasier; test the install by typing the following into the Terminal:

    If you don’t get an error, it installed correctly
  2. Check your Python version
    If you have Lion, you are likely running Python 2.7 – to double-check, type:

    And see what version comes up.  The problem installing OpenCV for Python seems to be a conflict between what version of Python MacPorts assumes and what you’re really running.  To be sure you are using 2.7, type this into the Terminal:
  3. Install NumPy
    Not sure why this is necessary, but appears to be (NumPydoes 2d array processing, so that’s likely the reason); type the following:
  4. Install OpenCV
    We’re ready!  Type the following and be prepared to wait – OpenCV is quite large and takes a while to download and get set up.  If you’ve already installed it in another location (I had) it appears that MacPorts just links it – nice!  Type:
  5. Test
    In the Terminal, type the following to enter Python:

    Then, to test OpenCV, type:

    If you don’t get an error, you’re good!  To exit Python, type:

Some of the suggestions I found say that you need to do some further profile editing and other (weird) stuff – I didn’t need to, but if you have problems it might be worth a try.

To further test the library, try this simple example that converts an image from one file format to another.  I wrote this in TextWrangler, saved the file, and ran it using the #! > Run in Terminal… command (requires the command-line tools to be installed.

The new file should be generated and you’re good to go!

Thoughts, suggestions, or problems?  Please send me an email: mail [at] jeffreythompson [dot] org