Skip to content

Instantly share code, notes, and snippets.

@TimSC
TimSC / conv2d_simplified.py
Created September 10, 2024 03:43
This is an implemention of torch's conv2d using scipy correlate2d.
import numpy as np
from scipy import signal
def conv2d_simplified(input, weight, bias=None, padding=0):
# This is an implemention of torch's conv2d using scipy correlate2d. Only
# limited options are supported for simplicity.
# Inspired by https://github.com/99991/NumPyConv2D/
c_out, c_in_by_groups, kh, kw = weight.shape
if not isinstance(padding, int):
raise NotImplementedError()
import csv
def MergeUpdate(dataDict, update):
for li in update:
#print (li['ElectorNumber'], li['ElectorCreatedMonth'], li['ElectorChangedMonth'], li['ElectorDeletedMonth'])
electNum = li['ElectorNumber'].strip()
if int(li['ElectorCreatedMonth']) or int(li['ElectorChangedMonth']):
@TimSC
TimSC / clusteraddress.py
Last active February 22, 2023 20:59
A script to group delivery areas into routes of roughly similar size.
# A script to group delivery areas into routes of roughly similar size.
import csv
from sklearn import cluster
from pyproj import Proj, transform
import numpy as np
from matplotlib import pyplot as plt
class EqualWeightClustering(object):
@TimSC
TimSC / install-nvidia-gl32.py
Created November 3, 2021 02:53
Install 32 bit nvidia gl driver
# https://askubuntu.com/a/1337205/294281
import os
import stat
import glob
from pathlib import Path
import shutil
if __name__=="__main__":
ver = "495.29.05"
@TimSC
TimSC / pyellipse.py
Last active March 31, 2023 17:45
Calculate circumference of an ellipse in python (both exact and approximate approaches)
#pyellipse by Tim Sheerman-Chase (C) 2021
#Calculate circumference of an ellipse in python (both exact and approximate approaches)
#This source code may be used under the CC0 license https://creativecommons.org/publicdomain/zero/1.0/
#
#For the best exact circumference, use EllipseCircumAdlaj2012
#
#For good approximations that are faster to compute, see EllipseCircumRamanujan2ndApprox and EllipseCircumJacobsenWaadeland1985
#
#Incidentally, scipy has a function to exactly calculate it:
# C = 4.0*a*special.ellipe(e*e)
@TimSC
TimSC / keras_aerialimagelabeling.py
Last active April 22, 2020 00:56
Using Keras to tackle the Inria aerial image labeling dataset
#Using Keras to tackle the Inria aerial image labeling dataset
# https://project.inria.fr/aerialimagelabeling/
import os
#Work around for https://github.com/tensorflow/tensorflow/issues/24496
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
# Work around for https://github.com/tensorflow/tensorflow/issues/33024
import tensorflow.compat as compat
compat.v1.disable_eager_execution()
@TimSC
TimSC / coil100-deeplearning.py
Created April 17, 2020 03:56
Classification of coil100 images using keras
import os
#Work around for https://github.com/tensorflow/tensorflow/issues/24496
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
# Work around for https://github.com/tensorflow/tensorflow/issues/33024
import tensorflow.compat as compat
compat.v1.disable_eager_execution()
import imageio
from sklearn.model_selection import KFold, train_test_split
@TimSC
TimSC / nmist_original.py
Created April 16, 2020 23:45
Classification of nmist digits
#Based on https://machinelearningmastery.com/how-to-develop-a-convolutional-neural-network-from-scratch-for-mnist-handwritten-digit-classification/
import os
#Work around for https://github.com/tensorflow/tensorflow/issues/24496
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
# baseline cnn model for mnist
from numpy import mean
from numpy import std
from matplotlib import pyplot
@TimSC
TimSC / nmist_with_generator.py
Last active April 16, 2020 23:43
Convert nmist digit example to use generator
import os
#Work around for https://github.com/tensorflow/tensorflow/issues/24496
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
# Work around for https://github.com/tensorflow/tensorflow/issues/33024
import tensorflow.compat as compat
compat.v1.disable_eager_execution()
# baseline cnn model for mnist
import numpy as np
@TimSC
TimSC / tensorflow-gpu-environment.md
Last active April 15, 2020 21:47
Working tensorflow GPU environments (Ubuntu 18.04 with Geforce RTX 2060 super)

Working environments (Ubuntu 18.04 with Geforce RTX 2060 super)

tensorflow-gpu-1.13 and after require TF_FORCE_GPU_ALLOW_GROWTH work around tensorflow/tensorflow#24496

Keras-2.2.5
tensorflow-gpu-1.12.0 
libcudnn7 7.6.5.32-1+cuda10.0
cuda-libraries-10-0