Thursday, December 13, 2018

A (failed) attempt to recognise the postie with machine learning

I've tinkered with machine learning in the past using TensorFlow but wanted to try Apple's tools which are extremely simple to use by comparison.

We have a low quality webcam pointing out into the street in front of the house that writes a file to a NAS every time it detects motion near the letter box. I often check these images to see if the postie has come. The project's objective is to automate looking at the images and recognise the postie.

Following Apple's documentation, I created an Xcode storyboard and trained it with a folder containing two sub-folders named "Postie" and "No Postie".

The storyboard is just this:

import CreateMLUI

let builder = MLImageClassifierBuilder()

builder.showInLiveView()

And it puts up a nice little UX where you drag your training folder.


I did try all of the augmentations shown above, it took a lot longer but wasn't more accurate in my case.

After saving the model, I created a simple macOS application with an ImageWell in it. You drag in an image and it shows the most likely tag like this:


Here's the main bit of the code to look at the image and display the classification.

    @IBAction func droppedImage(_ sender: NSImageView) {
        if let image = sender.image {
            if let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil) {
                let imageRequestHandler = VNImageRequestHandler(cgImage: cgImage, options: [:])
                do {
                    try imageRequestHandler.perform(self.requests)
                } catch {
                    print(error)
                }
            } else {
                print("Couldn't convert image")
            }
        }
    }
    
    private var requests = [VNRequest]()
    
    func setupVision() -> NSError? {
        // Setup Vision parts
        let error: NSError! = nil
        
        do {
            let visionModel = try VNCoreMLModel(for: PostieClassifier().model)
            let objectRecognition = VNCoreMLRequest(model: visionModel, completionHandler: { (request, error) in
                DispatchQueue.main.async(execute: {
                    // perform all the UI updates on the main queue
                    if let results = request.results {
                        let prediction = results[0] as! VNClassificationObservation
                        let classification = prediction.identifier
                        let confidence = prediction.confidence
                        self.predictionTextField.stringValue = "\(classification) \(confidence)"
                    }
                })
            })
            self.requests = [objectRecognition]
        } catch let error as NSError {
            print("Model loading went wrong: \(error)")
        }
        
        return error

    }

Not much code is there.

While this all works, in my case, recognition of the postie in my low quality webcam image is very unreliable. Testing did show this, to be fair.


I suspect the issue is that the postie is a very small part of the image and, due to weather and the position of the sun, the images do vary quite widely.

As mentioned above, I tried training with all of the augmentations available but accuracy didn't improve. Also I tried cropping training images to just include the postie.

In summary, I'm impressed with how super easy it is to create and use ML models on Apple's platforms but I have a great deal to learn about how to train a model to get good results.

Sunday, December 02, 2018

Beautiful Don Dorrigo Gazette

After visiting Dorrigo several times I finally remembered to drop in and purchase (for $1) a copy of the hot-metal typeset "Don Dorrigo and Guy Fawkes Advocate".

The paper has been published since January 8, 1910 and is the last known newspaper in Australia to still be printed this way.

The paper has no photographs and the small type is somewhat wonky but it has a charm of its own.

Mostly local advertising but with a few interesting stories. Click on the images here and view up close to really enjoy it.



There's a Wikipedia page and an ABC story with video showing the production process.

New van configuration working well

After re-building the inside of the van to replace the double bed with a single bed/couch facing a long bench with shelves, I've taken the opportunity to travel north for a few days and try living in it.

The new arrangement is much better than before. Along the way I stopped at very pleasant spots and could enjoy the view while still being able to make cups of coffee and access everything with ease.

The woodwork on the bench isn't great and if I do it again there are things I'd change but in the end it was built with straight timber in a curving van interior.

The sink and manual pump tap is fantastic and makes me feel much more at home when doing things like cleaning my teeth.

Another change is that I've mounted an antenna base on the roof rack and reception on 20m is pretty good although I do get noise from the solar charge controller and fridge.


Once again my destination was a farm stay in Eden near Dorrigo and it really is beautiful countryside. The morning view from the side of the van.


Lovely rivers are all over the place. (Click photos to enlarge).


I'm still figuring out where to put things and even in a "tiny house" it's amazing how things can be hard to find.


The bed, which is slats supporting a medium density single camp mattress from Clark Rubber is very comfortable and I quite like going to sleep when the sun goes down.


I've purchased a battery monitor with a current shunt that displays voltage, current and then figures out power use. This is being trialled in the shed and will be installed in the van in due course.

Sunday, November 25, 2018

An all "show n tell" home brew group meeting

This week we dispensed with a lecture format at the ARNSW Home Brew Group meeting and just went with show and tell.

Actually it worked out well. Normally the show and tell tends to be a delay before we get to the lecture but this time it was nice to take it all at a relaxed pace. Of particular interest (to me) was Peter R Jensen, VK2AQJ (author of "Wireless at War") who brought along a compact HF radio that used to be used by the CIA and SAS called an AN/PRC-64.

Great to see everyone, some had travelled great distances to attend.

Clifford Heath demonstrated the HackRF One and got me motivated to go home and fire mine up. Last time I tried it there was no operation but it turned out I'd mistakenly grabbed a USB cable that was charge only.

As always, Tim was working to keep everything running smoothly. A national treasure.


Saturday, November 17, 2018

Transcribe Helper macOS App soon for the app store

In recent years I've worked on and submitted many iOS apps to the Apple app store, but today, I've submitted my first app to the macOS app store.

My wife, Phillipa, is doing a PhD and interviewed numerous people. I was roped in to help transcribe those recordings. She had some software that worked with a dictation recorder and used a foot pedal to control pause/play and rewind but it was old and dreadful.

I've also been transcribing interviews of past winners of GovHack, so this was an application I needed. Searching the app store turned up nothing.

The app is a simple text editor but it lets you drag in an audio file and then control the playback with some keys that are not normally used in transcribing speech.

  • ] is play pause
  • [ backs up 5 seconds
  • \ plays at half speed without changing the pitch
The keys, and the number of seconds and slowness are all configurable. 

In the main window you see how far though you are, the number of words typed (one of my transcriptions was 10,000 words from a very fast speaker), and how far to go.

While writing software in Swift is a joy, compared to developing for iOS, the macOS AppKit framework is very dated and overcomplicated. Some tasks, like making the help bundle, are poorly documented and it was only some small clues in StackOverflow that helped me get through it.

I wrote this utility for myself, but I've had valuable feedback from Terry and Jill Brett and encouragement and a wonderful icon from Apple's Peter Watling - thanks to you all!

While it's a simple utility, I've decided to ask for a small amount of money, AU$10, as I think it brings great value to those who need it. My thinking is that this is cheap enough to avoid purchase hesitation and just enough to encourage me to continue working on it.

SDR software on macOS survey

This morning I thought I'd listen to the ARNSW Sunday broadcast on a Mac using an RTL-SDR dongle, just for a change.

First I tried my old favourite, CubicSDR.


I like CubicSDR largely because of the nice keyboard commands for tuning around and zooming.

Next I ran GQRX 2.5, which works well. I noticed I could also receive the broadcast on 1273.5MHz.


Finally I stumbled across waveSDR in source code format by Justin England or getoffmyhack.


This is a wonderful piece of source code in modern Swift, very clearly written. Thanks Justin! It seems to have a memory leak and there's a runtime warning about reading a view's bounds off the main thread.

I had a bit of trouble figuring how how to tune it, the secret is to choose Tuner from the popup in the left panel. You can also click on the spectrum but dragging doesn't seem to work.

Saturday, November 03, 2018

QRP By the Harbour November 2018

Yesterday we held another QRP By the Harbour meetup in Sydney at McIlwaine Park, Rhodes. A small friendly group turned up and happily the weather was kind. (Yesterday was 36C and a previous event was hailed out).

I set up a simple end fed antenna with a counterpoise. The end was held up on a 6m squid pole tied to a steel garden stake. I had a contact on 40m. Peter, VK2EMU, hung a giant dipole out to two trees and operated on 80m.


The most interesting station was Colin, VK2JCC, who put up a magnificent squid pole supported vertical. The rig was a wonderful military radio called a Clansman PRC320 that seemed to work very well.





Wednesday, October 31, 2018

Micro Men - docu-drama about the early PC industry in the UK

Just watched an entertaining 2009 TV program called "Micro Men" that tells the story of the early days of personal computers in the UK. Clive Sinclair is portrayed in competition with Acorn in the battle to produce the computer to be used in a BBC show.

The program is available for free viewing and even download here at the internet archive. I found it fascinating and it includes a soundtrack with the highlights of the 1970s - 80s.

Acorn went on to produce the ARM CPU that we find in almost every mobile device. I still have a ZX80 computer here in the shed.

Tuesday, October 30, 2018

Labor backs a revival of Asia Pacific broadcasting

Great news!

In a foreign policy speech yesterday opposition leader Bill Shorten gave the Pacific a priority it hasn't had in decades and today Penny Wong has backed it up making explicit Labor's desire to see a revival of Australia broadcasting in Asia and the Pacific.

Bill Shorten's speech is here. Penny Wong's here.

Regular readers (and listeners) know that I've long called for a re-vitalisation of Radio Australia in the Asia Pacific region and this is a hopeful sign. I personally think that rather than being a relic, shortwave can continue to play an important role in reaching audiences and is particularly important when there are disasters or censorship. But shortwave is just one technology that should be used today including FM relays, podcasts and live streaming.

For more info there is a Facebook group for supporters.