Skip to content

Instantly share code, notes, and snippets.

@davesnowdon
davesnowdon / json_serialisation.py
Last active Dec 13, 2015
Serialise custom python objects to/from JSON using 2 helper functions in the classes to handle the conversion for each class.
View json_serialisation.py
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 Oct 21, 2017
Complete meetup event description generator code
View MeetupEventDescriptionGenerator.java
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 Oct 22, 2017
Training RNN to generate text with word tokens as input and one-hot vector as output
View MeetupEventDescriptionGenerator.java
/*
* 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 Oct 22, 2017
Text generator in python
View generator-tf.py
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 Jan 27, 2018
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
View image-downloader2.py
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 Aug 12, 2018
Pi Zero cross compile pkg-config output
View gist:548c87d735433d73c587210a27995b6c
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
View gist:c9904c315c84863ea8840f2752145126
-- 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