Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew AndrewBMartin

View GitHub Profile
@AndrewBMartin
AndrewBMartin / save_feature_vectors_for_tensorboard.py
Last active Jun 21, 2019
Save feature vectors for projection with Tensorboard
View save_feature_vectors_for_tensorboard.py
import tensorflow as tf
from tensorflow.contrib.tensorboard.plugins import projector
LOG_DIR = "your-tensorboard-log-dir-here"
FEATURE_VECTORS = "your-feature-vectors-as-npy"
MAX_NUMBER_SAMPLES = 8191
METADATA_FILE = os.path.join(LOG_DIR, 'metadata.tsv')
CHECKPOINT_FILE = os.path.join(LOG_DIR, 'features.ckpt')
# Create metadata
@AndrewBMartin
AndrewBMartin / transform_images_to_sprite.py
Last active Jun 21, 2019
Read in images, transform them to a sprite image
View transform_images_to_sprite.py
import os
import glob
import cv2
LOG_DIR = "your-tensorboard-log-dir-here"
IMAGES_DIR = "your-images-dir-here"
IMAGE_SIZE = (64, 64)
SPRITES_FILE = os.path.join(LOG_DIR, "sprites.png")
@AndrewBMartin
AndrewBMartin / create_sprite.py
Last active Jun 20, 2019
Create a sprite for Tensorboard from an array of images
View create_sprite.py
import numpy as np
def create_sprite(data):
"""
Tile images into sprite image.
Add any necessary padding
"""
# For B&W or greyscale images
if len(data.shape) == 3:
@AndrewBMartin
AndrewBMartin / train.py
Last active Feb 28, 2019
Example training function with tensorboardcolab
View train.py
def train(model, train_loader, device, optimizer, log_interval, epoch, globaliter, tb):
"""
Example training function for PyTorch recording to tensorboardcolab.
"""
model.train()
for batch_idx, (data, target) in enumerate(train_loader):
globaliter += 1
data, target = data.to(device), target.to(device)
@AndrewBMartin
AndrewBMartin / train.py
Last active Feb 28, 2019
Example training function with tensorboard
View train.py
def train(model, train_loader, device, optimizer, log_interval, epoch, globaliter):
"""
Example training function for PyTorch recording to TensorBoard.
"""
model.train()
for batch_idx, (data, target) in enumerate(train_loader):
globaliter += 1
data, target = data.to(device), target.to(device)
@AndrewBMartin
AndrewBMartin / gurobi.log
Created Nov 9, 2015
Gurobi Log - Barrier reset behaviour
View gurobi.log
Optimize a model with 889545 rows, 7495464 columns and 230380625 nonzeros
Coefficient statistics:
Matrix range [1e-03, 7e+02]
Objective range [8e-01, 1e+00]
Bounds range [0e+00, 0e+00]
RHS range [5e-01, 6e+06]
Concurrent LP optimizer: dual simplex and barrier
Showing barrier log only...
@AndrewBMartin
AndrewBMartin / Lp_wrapper
Created May 27, 2014
Python wrapper to store an lp file as a model object
View Lp_wrapper
""""
Try to create model, variable and constraint objects.
Try to read the lp into a model object faster.
"""
import os
from profilehooks import profile, timecall
class Model(object):
@AndrewBMartin
AndrewBMartin / main.py
Last active Dec 29, 2015
Hacker School Application: A routine that simulates the growth and yields of a list of timber stands over a 30 period planning horizon, and writes the results to 4 output files. These output files are used to supply parameter values for an AMPL generated Linear Programming model.
View main.py
import os
import csv
import pres_builder as pb
# Indicates whether prescription set A or B
# is to be generated, in the case a prescription
# set will be generated.
global model_type
model_type = 'B'
@AndrewBMartin
AndrewBMartin / application_admin.py
Created Nov 28, 2013
model.py and application_admin.py for camelot Videostore Tutorial
View application_admin.py
from camelot.view.art import Icon
from camelot.admin.application_admin import ApplicationAdmin
from camelot.admin.section import Section
from camelot.core.utils import ugettext_lazy as _
class MyApplicationAdmin(ApplicationAdmin):
name = 'Videostore'
application_url = 'http://www.python-camelot.com'