Skip to content

Instantly share code, notes, and snippets.

@davesnowdon
davesnowdon / json_serialisation.py
Last active December 13, 2015 22:49
Serialise custom python objects to/from JSON using 2 helper functions in the classes to handle the conversion for each class.
import sys
import inspect
import json
'''
Functions for clients to call to serialise/unserialise from strings and files
Idea taken from http://getpython3.com/diveintopython3/serializing.html
and generalised to allow helper functions to be part of the custom classes
and avoid case statements
@davesnowdon
davesnowdon / MeetupEventDescriptionGenerator.java
Created October 21, 2017 16:23
Complete meetup event description generator code
package com.davesnowdon.meetup;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.datavec.api.util.ClassPathResource;
import org.deeplearning4j.api.storage.StatsStorage;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.EmbeddingLayer;
@davesnowdon
davesnowdon / MeetupEventDescriptionGenerator.java
Last active October 22, 2017 07:12
Training RNN to generate text with word tokens as input and one-hot vector as output
/*
* Model
*/
private MultiLayerNetwork createModel(int vocabSize, int embeddingSize, int rnnSize) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.activation(Activation.RELU)
.learningRate(0.01)
.list()
.layer(0, new EmbeddingLayer.Builder().nIn(vocabSize).nOut(300).build())
.layer(1, new GravesLSTM.Builder().nIn(300).nOut(512).activation(Activation.SOFTSIGN).build())
@davesnowdon
davesnowdon / generator-tf.py
Created October 22, 2017 12:58
Text generator in python
def get_inputs():
"""
Create TF Placeholders for input, targets, and learning rate.
"""
# TODO: Implement Function
return tf.placeholder(tf.int32, shape=(None, None), name="input"), tf.placeholder(tf.int32, shape=(None, None)), tf.placeholder(tf.float32)
def get_init_cell(batch_size, rnn_size):
"""
@davesnowdon
davesnowdon / image-downloader2.py
Created January 27, 2018 14:15
Rewrite of the python image downloading code from https://www.pyimagesearch.com/2017/12/04/how-to-create-a-deep-learning-dataset-using-google-images/ which does not leave gaps in the numbering, allows arbitrary starting numbers and uses generators to make the code a bit more readable
from imutils import paths
import argparse
import requests
import cv2
import os
import numpy as np
# Adapted from https://www.pyimagesearch.com/2017/12/04/how-to-create-a-deep-learning-dataset-using-google-images/
# fixes the following issues with the original:
# 1 - files are always saved as .jpg even if they are not in JPEG format
@davesnowdon
davesnowdon / gist:548c87d735433d73c587210a27995b6c
Created August 12, 2018 20:10
Pi Zero cross compile pkg-config output
Wed 8 Aug 06:33:54 BST 2018 pkg-config-wrapper.sh --exists
--print-errors --short-errors harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR=/opt/software/raspberrypi/rpi-cross/rootfs
pkg-config =
Wed 8 Aug 06:33:54 BST 2018 pkg-config-wrapper.sh --modversion
harfbuzz
PKG_CONFIG_DIR=
PKG_CONFIG_LIBDIR=:/opt/software/raspberrypi/rpi-cross/rootfs/usr/lib/arm-linux-gnueabihf/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/usr/share/pkgconfig:/opt/software/raspberrypi/rpi-cross/rootfs/opt/vc/lib/pkgconfig
-- The CXX compiler identification is GNU 6.3.0
-- The C compiler identification is GNU 6.3.0
-- Check for working CXX compiler: /opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-g++
-- Check for working CXX compiler: /opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-gcc
-- Check for working C compiler: /opt/cross/x-tools/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-gcc -- works
service TheSocialRobot {
rpc EventStream(stream BodyEvent) returns (stream BodyCommand) {}
}
// event from robot (the body) containing current state
message BodyEvent {
int32 id = 1;
}
message Say {
string text = 1;
}
message Action {
// delay in milliseconds before triggering the action
int32 delay = 1;
oneof action {
Say say = 2;
}