Saturday, January 28, 2017

Bicycle Threat or Treat Image Classification Using TensorFlow and Inception

.996 Bike Threat

The result of my experiment #3 in Machine Learning (ML) using TensorFlow was, according to rule #1, success, because I had fun, learned something, and the code ran. Beyond that, I was surprised at how good the program was at classifying images as either "bicycle threat" or "bicycle treat".

.997 Bike Treat

I've been diving into ML for the past couple of weeks, so my experiments are getting easier to setup and run. For this one, I picked over 100 images from this blog that said "bicycle threat" to me, pictures of onrushing cars, crashes, construction, bad road conditions, etc, and another 100+ images that said "bicycle treat," like flowers, art, pretty girls on bikes, cups of coffee, and peaceful open roads, and put them into folders labelled appropriately. Then I downloaded sample python code for retraining Google's deep learning model, inception-v3 on my images, goofed around with it until it was running the way I wanted it to, and let her rip.

Inception v3 looks like this, I'm told

After retraining the deep learning model to grok bike threats and treats, I got to try it out on random images to see what it came up with. After I tried out the images above and got the categorization I hoped for, I was giddy with ML power! I started trying random pix from various search engine image searches, and overall was happy with the results. Lone bike riders almost always score as treats. Ditto open roads and pictures of trees. Head-on photos of cars, large groups of cars, and nasty traffic jams, almost always got classified >95% as bike threats. All examples of Robert Indiana's "LOVE" sculpture that I tried rated very high as bike treats. Coffee and hot dogs also are solidly in the treat category. Girls on bikes scored strongly and consistently as treats. Most lone guys on bikes did, too.

Not everything was a screaming success, however. I took some low-rez screen grabs from this post that has a clip I shot of one of my more threatening encounters on the road, imagining results that I might get if I had enough hardware and the right software running on the back of my bicycle to alert me of what was about to happen. 

The first one scored high as a .997 threat. The second one, taken just before the actual close pass, got a more ambiguous .69 threat rating. The third one, taken just moments before #2, got a much stronger .93 threat rating. When I do this again, I will think more about close passes and real traffic situations, which I had a limited supply of photos of for this first experiment.

What's next for OSGIML? More image classification, I bet. First, more playing around with this experiment, to see what else I can learn. 

Add to backlog: the follower-drone should provide data to enhance threat detection, and to attract to bicycle treats on or near the intended navigation route. 

.997 Bike Threat

.692 Bike Threat (doh!)

.93 Bike Threat (yay!)
ADDENDUM: Saturday afternoon shots

bikethreat (score = 0.96360)
bikethreat (score = 0.99636)
biketreat (score = 0.54084) (confusing shadow is confusing)

bikethreat (score = 0.91335)

Thursday, January 26, 2017

There Should Be Bicycles in It

The video above is from experiment #2 with machine learning (ML): use a python script to process a video clip through TensorFlow / Deepdream. Experiment #1, my previous post, was to do that with a still photo. This is the next step in the continuing efforts of the OSG Institute for Machine Learning (OSGIML) to do something with it for bicycles. 

To that end, I've put together the following set of guiding rules that I sort of follow:


1. Experiments are successful when I learn something new, and the code runs.

2. There should be bicycles in it.

3. Experiments should prove out the software prior to me buying new hardware to run it, to minimize waste.

4. Set the bar low to ensure stepwise daily progress, to nurture new habits and have fun.

5. Exploit the virtues of developer laziness: reuse, adapt, recycle, refactor. Don't create tools you can download. Solve the heart of the problem, and don't expend cycles on problems that others have already solved.

6. Add flashes and insights to the backlog, for when tools, time, and technique might render them feasible.


Experiment #1. Use TensorFlow and Python to process bicycle images with Deepdream.
    learning: python, TF, ML, tensors

Experiment #2. Use TensorFlow and Python to process video clips which include bicycles with Deepdream.
    learning: more TF, more py, more ML, tensors and usage, hardware requirements, Siraj Raval videos for learning stuff about this (he's great)

Experiment #3. Try out Jupyter while using TF and Py to classify images that include bicycles.
    learning: basic TF usage, tensors, matrix math, Jupyter

According to rule #1, experiments #1 and #2 were resounding successes! On to experiment #3, classifying images with bicycles in them.

Add to backlog: bike-threat (classification). 1-shot, 1-hot, 1/10th second, fire alert with sound, LED, haptic, indicate direction and intensity.
Video note: I uploaded to Blogger, Youtube, and Vimeo, but the first two thought the flower effects were noise, and mainly took them out during processing, while Vimeo left them in, so that's why I used Vimeo in this post.

Monday, January 23, 2017

Getting to Yes! on the Bicycle

Photo processed thru Deepdream python script, with TensorFlow

Once I posted on this blog about a strategy of firmly yelling back at anyone who suggested that I and my bicycle don't belong on the road: "NO!" I suggested, yelled firmly and assertively back, would state the case clearly and effectively. It felt satisfying the few times I tried it out, but deep down it felt wrong. In its negativity, in its reactiveness, in its simple negation, it doesn't really work in the moment. Furthermore, it is unsatisfying in the moments and hours in the aftermath of such encounters, amounting to a visceral denial of something that actually occurred, in addition to a burial or repression of the feelings that go along with it.

While currently reading Tara Brach's "Radical Acceptance", it dawned on me that being open to the experience, recognizing it for what it is, then welcoming the feelings that accompany it with honest compassion, is potentially a more effective method for responding to road insults. If he's angry and I'm afraid, then that is what it is. It's about looking at reality openly, possibly differently, with less processing, rationalization, and denial, with more awareness, mindfulness, if you will. Too see what's there, be in the moment, and alive. Even when the moment itself has previously held strong negative potential. This, too, as Tara Brach might observe.

The photo above is an example of some recent forays I've taken into learning about Machine Learning (ML). So far, the math is about 80% over my head, but I'm chipping away at it through playful learning, which keeps me engaged. Instead of beating myself up for not really deeply understanding tensors or softmax so far, I play with the code and accept myself hack by hack and have fun with it. In my experience, the light usually goes on eventually, perhaps without me consciously willing it, or fighting against the setbacks, but just enjoying the act of creating trippy photos like the one above. Perhaps I will sneak up on understanding TensorFlow that way. Perhaps if part of our vision imagines sneaky weasel lurking beneath the share the road signs, we can get to "Yes" on our bicycles.

Why ML? I have this fantasy of programming and soldering something for bicycles, for cyclists. Raspberry Pi, Android, Python scripts, data overages, processing my commute through TensorFlow, I'm just saying yes, yes, yes, even if that's all crazy.

Sunday, January 8, 2017

Sunset Bikerise


On my evening commute, I grabbed the shot above looking west along the Arizona Canal path. It was just as quiet and stunning as it looks.


Next day, looking east, I grabbed another shot of bikes rising along the canal. The guy in black near the back is in the spot where I took the first shot.