Skip to content

Instantly share code, notes, and snippets.

View krosaen's full-sized avatar

Karl Rosaen krosaen

View GitHub Profile
@krosaen
krosaen / feed_tf_graph.py
Created May 17, 2017 15:00
exploring feeding values into a graph with and without queues
import tensorflow as tf
def test_feed_independent_graph():
"""
Example of a computation graph that depends on a placeholder.
How can we feed in values from a queue? As it turns out, you need separate
sess.run calls to deq and then feed the graph.
"""
@krosaen
krosaen / poly_contains.py
Created December 22, 2017 19:41
how to count number of points within a polygon
def count_kps_within_poly(polygon, keypoints):
from matplotlib.collections import PolyCollection
path = PolyCollection([polygon]).get_paths()[0]
return np.sum(path.contains_points(keypoints))
assert 2 == count_kps_within_poly(
[(0, 0), (100, 0), (200, 100), (100, 100), (0, 100)],
[(50, 50), (200, 0), (1, 1)]
)
def summarize_data_shape(example):
"""
Given some (json serializeable) example, provide a concise summary of its structure
by pruning it down to e.g one item per list.
like https://github.com/krosaen/data-shapy/blob/master/data_shapy/data_shape.py
but handles a best effort summary of class objects and tuples too
"""
def is_ground(item):
@krosaen
krosaen / s3m.py
Created June 8, 2018 20:46
sync s3 object to local cache using aws cli. pretty dumb, but provides some useful validation
#!/usr/bin/python3
import argparse
import os
import subprocess
import sys
def main():
parser = argparse.ArgumentParser('mirrors an s3 object to local root (~/local-data/s3)')
"""
Utilities for printing out a nice looking file tree, e.g
pretty_tree(('root', [
('a', [
'file1.txt',
'file2.txt',
]),
('b', [
'file1.json',
#include <math.h>
#include <iostream>
#include <vector>
template <class Part>
struct PartScorer {
struct PartAdapter {
double PartArea(const Part& part) = delete;
};
def pretty_data(d):
return '\n'.join(data_lines(d))
def data_lines(d, prefix='', last=True, add_bookends=True):
def ground(d):
return isinstance(d, (str, float, int)) or ground_list(d) or ground_dict(d)
def ground_list(d):
return isinstance(d, list) and len(d) < 6 and all([isinstance(el, (str, float, int)) for el in d])