Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <memory>
#include <string>
#include <vector>
// Forward declarations
class NoAnnotation;
template<typename A = NoAnnotation>
@neworderofjamie
neworderofjamie / numeric_type_value.cc
Created August 7, 2023 11:05
First attempt at NumericTypeValue class
class NumericTypeValue
{
public:
NumericTypeValue(float value) : m_Value(double{value}){}
NumericTypeValue(double value) : m_Value(value){}
NumericTypeValue(int value): m_Value(int64_t{value}){}
NumericTypeValue(unsigned int value): m_Value(uint64_t{value}){}
NumericTypeValue(uint64_t value): m_Value(value){}
NumericTypeValue(int64_t value): m_Value(value){}
@neworderofjamie
neworderofjamie / tracker.py
Created July 20, 2023 16:14
Better tracker with dynamic tracking of trapezium reference points
import cv2
import numpy as np
import os
import sys
import csv
def get_box_centre(box):
return (int(box[0] + (box[2] / 2)), int(box[1] + (box[3] / 2)))
def draw_box(frame, box, colour):
@neworderofjamie
neworderofjamie / tracker.py
Created July 20, 2023 11:46
simple OpenCV video tracker
import cv2
import numpy as np
import os
import sys
import csv
def draw_box(frame, box, colour):
(x, y, w, h) = (int(v) for v in box)
cv2.rectangle(frame, (x, y), (x + w, y + h), colour, 2)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@neworderofjamie
neworderofjamie / strategy.py
Created March 16, 2022 14:02
strategy pattern for output layers
# Create sequential model
model = SequentialModel()
with model:
input = InputLayer(IntegrateFireInput(v_thresh=5.0), 784)
Layer(Dense(weight=weights[0]), IntegrateFire(v_thresh=5.0))
Layer(Dense(weight=weights[1]), IntegrateFire(v_thresh=5.0, output=SpikeCount()))
import numpy as np
from os import path
from ml_genn import InputLayer, Layer, SequentialModel
from ml_genn.compilers import Compiler
from ml_genn.neurons import IntegrateFire, IntegrateFireInput
from ml_genn.connectivity import Dense
# Load weights
weights = []
import numpy as np
import matplotlib.pyplot as plt
spikes = np.loadtxt("spikes.csv", delimiter=",")
voltages = np.loadtxt("voltages.csv", delimiter=",")
fig, axes = plt.subplots(5, sharex=True)
for i in range(4):
axes[i].plot(voltages[:,0], voltages[:,i+1])
@neworderofjamie
neworderofjamie / izhikevich.cu
Created March 7, 2022 15:28
Sample GeNN-like CUDA code for simulating Izhikevich neurons
// C++ includes
#include <algorithm>
#include <fstream>
// ------------------------------------------------------------------------
// Helper macro for error-checking CUDA calls
#define CHECK_CUDA_ERRORS(call) {\
cudaError_t error = call;\
if (error != cudaSuccess) {\
throw std::runtime_error(__FILE__": " + std::to_string(__LINE__) + ": cuda error " + std::to_string(error) + ": " + cudaGetErrorString(error));\
import os, pathlib
import tensorflow as tf
from tensorflow.keras import (models, layers, datasets, callbacks, optimizers,
initializers, regularizers)
from tensorflow.keras.utils import CustomObjectScope
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from glob import glob
import numpy as np
# Learning rate schedule