Skip to content

Instantly share code, notes, and snippets.

View hollance's full-sized avatar

Matthijs Hollemans hollance

View GitHub Profile
@hollance
hollance / CoreML+Combine.swift
Created November 12, 2019 16:28
Using Core ML with Combine
import CoreML
import Combine
extension Publisher where Self.Output: MLFeatureProvider {
/**
Operator that lets you run a Core ML model as part of a Combine chain.
It accepts an MLFeatureProvider object as input, and, if all goes well,
returns another MLFeatureProvider with the model outputs.
@hollance
hollance / convert_weights.py
Created October 7, 2017 20:43
SE-ResNet-50 in Keras
# Convert SE-ResNet-50 from Caffe to Keras
# Using the model from https://github.com/shicai/SENet-Caffe
import os
import numpy as np
# The caffe module needs to be on the Python path; we'll add it here explicitly.
import sys
caffe_root = "/path/to/caffe"
sys.path.insert(0, caffe_root + "python")
@hollance
hollance / Compressing-MobileNet.ipynb
Created September 26, 2017 12:47
Jupyter notebook for compressing MobileNet (work in progress)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hollance
hollance / Shaders.metal
Created July 19, 2017 11:54
Relu6 in Metal
#include <metal_stdlib>
using namespace metal;
struct Relu6Params {
float a;
};
kernel void relu6(
texture2d_array<half, access::read> inTexture [[texture(0)]],
texture2d_array<half, access::write> outTexture [[texture(1)]],
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hollance
hollance / deconv.py
Created May 13, 2017 20:47
Playing with "deconvolution"
import numpy as np
i = np.array(list(range(1, 50)), dtype=np.float).reshape((7, 7))
k = np.array(list(range(1, 10)), dtype=np.float).reshape((3, 3))
print("Input:"); print(i)
print("Kernel:"); print(k)
# Forward convolution. We need to pad the input so that we can read from
# its borders. (Not doing stride etc here.)
@hollance
hollance / XOR.swift
Created January 11, 2017 18:05
Playing with BNNS (Swift version). The "hello world" of neural networks.
/*
The "hello world" of neural networks: a simple 3-layer feed-forward
network that implements an XOR logic gate.
The first layer is the input layer. It has two neurons a and b, which
are the two inputs to the XOR gate.
The middle layer is the hidden layer. This has two neurons h1, h2 that
will learn what it means to be an XOR gate.
@hollance
hollance / recursive-descent.swift
Created December 28, 2016 19:00
Simple recursive descent parser
import Cocoa
let input = "15,7, 3 ,, [1,2,[3, 4, 5], 6],8"
//let input = "5,7,[1]"
var index = input.characters.startIndex
var lookahead = input[index]
var done = false
func eat() {
@hollance
hollance / eliza.swift
Last active February 17, 2023 15:50
The classic ELIZA chat bot in Swift.
/*
Joseph Weizenbaum's classic ELIZA chat bot in Swift.
Based on the IBM PC BASIC program from CREATIVE COMPUTING by Patricia
Danielson and Paul Hashfield, and the Java adaptation by Jesper Juul.
Run this script from Terminal:
$ swift eliza.swift
Press Ctrl-C or Ctrl-D to quit. (Or type "shut up".)
@hollance
hollance / ZeroGravity.asm
Created November 23, 2016 19:50
Zero Gravity source code (Amiga 1200)
; *****************************************************************************
;
; $VER: ZeroGravity Source 1.0 (C) 1997 Matthijs Hollemans
;
; *****************************************************************************
;
; This is the full source code to Zero Gravity. I used the very cool ASM-One
; V1.29 assembler from T.F.A. but that doesn't matter anyway because you won't
; be able to reassemble this without the required binary includes...
;