Skip to content

Instantly share code, notes, and snippets.

View AndrewBMartin's full-sized avatar

Andrew AndrewBMartin

View GitHub Profile
@AndrewBMartin
AndrewBMartin / application_admin.py
Created November 28, 2013 21:13
model.py and application_admin.py for camelot Videostore Tutorial
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'
@AndrewBMartin
AndrewBMartin / main.py
Last active December 29, 2015 23:39
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.
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 / Lp_wrapper
Created May 27, 2014 21:49
Python wrapper to store an lp file as a model object
""""
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 / gurobi.log
Created November 9, 2015 16:10
Gurobi Log - Barrier reset behaviour
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 / train.py
Last active February 28, 2019 16:51
Example training function with tensorboard
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 / train.py
Last active February 28, 2019 16:52
Example training function with tensorboardcolab
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 / create_sprite.py
Last active June 20, 2019 15:35
Create a sprite for Tensorboard from an array of images
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 / transform_images_to_sprite.py
Last active June 21, 2019 16:18
Read in images, transform them to a sprite image
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 / save_feature_vectors_for_tensorboard.py
Last active June 21, 2019 17:44
Save feature vectors for projection with Tensorboard
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