Skip to content

Instantly share code, notes, and snippets.

View david-macleod's full-sized avatar

David MacLeod david-macleod

View GitHub Profile
@david-macleod
david-macleod / plot_timings.py
Created January 10, 2020 07:41
plot_timings
def plot_timings(loader, n_batches, model_time=0.2, max_time=2.5):
fig, ax = plt.subplots()
ax.set_axisbelow(True)
ax.yaxis.grid(which="major", color='black', linewidth=1)
zero_time = time.time()
worker_ids = {}
worker_count = count()
@david-macleod
david-macleod / callbacks.py
Created September 9, 2019 20:41
bokeh callbacks
from bokeh.models import CustomJS, ColumnDataSource
source = ColumnDataSource(data=dict(x=[0,0], y=[0, 80]))
# Javascript
callback = CustomJS(args=dict(source=source), code="""
var data = source.data;
var f = cb_obj.value
data['x'] = [f, f]
@david-macleod
david-macleod / bokeh_audio_player.py
Last active February 18, 2023 17:39 — forked from nathanielatom/bokeh_audio_player.py
Custom Bokeh Model for audio playback (not so useful on its own; meant to be integrated with plot interactions).
# Forked from nathanielatom, updated to work with typescript and bokeh==1.3.4
from bokeh.layouts import column, layout
from bokeh.models import CustomJS, Model, LayoutDOM
from bokeh.document import Document
from bokeh.models.widgets import Button, Slider, Toggle
from bokeh.core.properties import Instance, String
from bokeh.io import save, output_file, show
from bokeh.util.compiler import TypeScript
from fontawesome.fontawesome_icon import FontAwesomeIcon as Icon
# Requires https://github.com/bokeh/bokeh/tree/master/examples/custom/font-awesome
@david-macleod
david-macleod / register_hook.py
Last active April 21, 2020 15:45
pytorch hook
layer_dict = {}
def inspect_layer(module, input, output):
global layer_dict
layer_dict[module] = (input, output)
handles = [layer.register_forward_hook(inspect_layer) for layer in output_layers]
# handles[0].remove()
@david-macleod
david-macleod / vscode-settings
Created July 19, 2019 10:41
vscode-settings
x
@david-macleod
david-macleod / google-colab-drive-auth.py
Created October 12, 2018 20:42
Google drive authentication in colab notebook
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
@david-macleod
david-macleod / tf-anchor-box-visualize.py
Last active August 19, 2020 11:39
TensorFlow Object Detection Anchor Box Visualizer
import tensorflow as tf
from object_detection.anchor_generators.multiple_grid_anchor_generator import create_ssd_anchors
from object_detection.models.ssd_mobilenet_v2_feature_extractor_test import SsdMobilenetV2FeatureExtractorTest
import matplotlib.pyplot as plt
from matplotlib import patches
import numpy as np
def get_feature_map_shapes(image_height, image_width):
"""
@david-macleod
david-macleod / tensorflow-cli
Created August 31, 2018 22:01
Tensorflow CLI
# Examples of calls to various tensorflow features from CLI
# Load graph to tensorboard
python -m tensorflow.python.tools.import_pb_to_tensorboard
@david-macleod
david-macleod / tmux.conf
Last active July 10, 2018 20:19
tmux config
set-option -g prefix C-a
set -g mouse on
# remember to run tmux source-file ~/.tmux.conf
if [[ -z "$TMUX" ]]; then
tmux new -d -s jn
tmux send -t jn "jupyter notebook" ENTER
fi