Skip to content

Instantly share code, notes, and snippets.

View rreece's full-sized avatar
🙈
doing things

Ryan Reece rreece

🙈
doing things
View GitHub Profile
@rreece
rreece / test_float16_tfrecord.py
Created May 12, 2021 18:11
Writes float16 data to a tfrecord as raw bytes and reads it back.
"""
Writes float16 data to a tfrecord as raw bytes and reads it back.
Based on:
https://stackoverflow.com/questions/40184812/tensorflow-is-it-possible-to-store-tf-record-sequence-examples-as-float16
"""
import argparse
import numpy as np
import tensorflow as tf
@rreece
rreece / path_is_in_git.py
Last active April 20, 2021 17:31
Check if a file is tracked by git
def path_is_in_git(repo, path):
"""
Check if path is tracked by git.
"""
returncode = None
try:
cmd = 'git ls-files --error-unmatch %s' % (path)
_ = subprocess.check_output(cmd,
cwd=repo,
shell=True,
@rreece
rreece / ubuntu_20.04_setup.txt
Last active April 3, 2021 20:50
Ubuntu 20.04 setup post-install
# install chrome with .deb
# setup terminal profile
sudo apt update
sudo apt dist-upgrade
sudo apt install vim htop screen tmux
sudo apt install git
# create ssh key:
ssh-keygen -t rsa
import argparse
import numpy as np
import tensorflow as tf
from tensorflow.core.protobuf import rewriter_config_pb2
from model import model_fn
from data import input_fn
from utils import (
DEFAULT_PARAMS_FILE,
get_params,
@rreece
rreece / delete_git_submodule.md
Created March 13, 2020 18:32 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
"""
Main training script.
Call by:
python3 train.py --params=params.yaml
"""
import argparse
import numpy as np
@rreece
rreece / segment_mean.py
Created March 11, 2020 20:24
XLA-compatible version of tf.segment_mean
import tensorflow as tf
def segment_mean(x, bounds):
n = len(bounds)
segs = [
tf.reduce_mean(x[:,bounds[i]:bounds[i+1]], axis=1) for i in range(n-1)]
y = tf.stack(segs, axis=1)
return y
@rreece
rreece / print_total_parameters.py
Created February 7, 2020 19:05
print all the trainable parameters in a tensorflow model in current scope
def print_total_parameters():
total_parameters = 0
for variable in tf.trainable_variables():
# shape is an array of tf.Dimension
shape = variable.get_shape()
variable_parameters = 1
for dim in shape:
variable_parameters *= dim.value
print('%s dim=%i shape=%s params=%i' % (
variable.name,
import tensorflow as tf
from google.protobuf.json_format import MessageToJson
filename = 'myfile.tfrecords'
for record_str in tf.python_io.tf_record_iterator(filename):
example = tf.train.Example.FromString(record_str)
json = MessageToJson(example)
print(json)
@rreece
rreece / pool.py
Created March 19, 2019 01:10 — forked from nfaggian/pool.py
Multiprocessing example
from __future__ import print_function
import multiprocessing
import ctypes
import numpy as np
def shared_array(shape):
"""
Form a shared memory numpy array.