Skip to content

Instantly share code, notes, and snippets.

View levimcclenny's full-sized avatar
⏱️
Fighting the clock

Levi D McClenny levimcclenny

⏱️
Fighting the clock
View GitHub Profile
@levimcclenny
levimcclenny / tf-dataset-training-large.py
Created January 25, 2021 18:32
Build and train a large dataset using tf.Data and tf.Keras
import tensorflow as tf
import numpy as np
from tensorflow.keras.applications.vgg16 import VGG16
# generate 10k random 224x224x3 tensors (to simulate images)
dataset = tf.random.normal((10000, 224, 224,3))
# generate 10k one-hot labels for categorical cross entropy loss
labels = tf.constant(np.eye(1000)[np.random.choice(1000, 10000)])
@levimcclenny
levimcclenny / multimesh.py
Last active January 12, 2021 20:32
multidimensional meshgrid, can be used for 3D meshgrids or beyond. Takes a list of linspaces as input, one for each desired dimension, then creates an array of all possible combinations of those points. Useful for plotting functions or, when reshaped, inputting all points on a grid into a neural network
# Higher order meshgrid that takes a list of np.linspace type object and greates an output array
# Created to generate meshes of input points for PINN training
# Adopted from https://stackoverflow.com/questions/1827489/numpy-meshgrid-in-3d
# and modified to work in N dimensions, as well as fixed for python3
def multimesh(arrs):
lens = list(map(len, arrs))
dim = len(arrs)