Weird blur/glitching when zoomed in really close on the cursor in Mac OS X.
Torch-rnn: Mac Install
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.
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
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 .
tell application "Finder"
select the front Finder window
set targetFolder to insertion location as alias
set folderPath to POSIX path of targetFolder
set makeNoteFile to "echo '\\nNOTES && IDEAS:\\n' >> " & quoted form of folderPath & "/NotesAndIdeas.txt"
do shell script makeNoteFile
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
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!
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.
|1988-96||Apple IIGS||Used in elementary and middle school, mostly to play Number Munchers and Oregon Trail|
|1994-96||486 of some kind||Used at home for DOS games (didn't really know how to do anything else)|
|1996-98||Compaq Presario 5140||Used at home, used for games, going on AOL, graphics programs - all with that distinctive power/sleep button|
|1998-2000||Some kind of eMachines desktop||Used 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-2004||Apple 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-2004||Toshiba Tecra 8000 laptop||Used 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-2006||Gateway 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-2009||Mac PowerBook 12" laptop||Used during grad school and after for EVERYTHING, mostly on cracked software, too :)|
|2009-11||iPhone 3GS||My first smartphone, bought after I lost the charger to my crappy cellphone, played lots of Scrabble on this|
|2009-13||MacBook Pro 15" (2x)||Used at first teaching job with NO cracked software! (2 different computers of the same model)|
|2011-13||iPhone 4||Replaced my previous smartphone, donated the old one to Angeles, played lots of Angry Birds on this|
|2012-present||Raspberry Pi Model B||Bought very early on, now runs all my bots|
|2013-prese||Nexus 10 tablet||Bought using a grant, mostly to run Processing sketches|
|2013-present||MacBook Pro 15" w Retina Display||Current workhorse|
|2014-present||Mac Mini||Also bought using a grant, mostly for installations (and formerly for and running bots)|
|2014-present||iPhone 5s||Current 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 :)
Virtual Memory Icon
A puffy monitor, representing virtual memory in Mac OS 8 settings, enlarged and cleaned up via Vectronic’s Apple World.
Found: File System List
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:
- Open Applications > Utilities > Terminal…
- Install Homebrew by typing the following into Terminal
1ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)
- Run the command brew doctor to check for any errors
- While normal installations using Homebrew are very straightforward, for some reason OpenCV requires an extra step – you need to install an add-on called
1brew tap homebrew/science
- Then you can run the usual Homebrew command to install OpenCV:
1brew install opencv
If this fails, it may be that you have ffmpeg installed – if so, try this instead:
1brew install opencv --env=std
- This may take several minutes, so be patient!
- 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
- Navigate up to your home folder and open the .bash_profile file – if it doesn’t exist, create it yourself
- Add the line suggested by Homebrew, probably something like:
- Save the file and close it – you may also have to exit Terminal and open it again
- Test by opening Python:
Then try to import OpenCV:
- 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!).
- 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
- 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:
1sudo port select --set python python27
- 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:
1sudo port install py27-numpy
- 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:
1sudo port install opencv +python27
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.
im = cv.LoadImageM("test.jpg")
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