Skip to content

Instantly share code, notes, and snippets.

Avatar
🙈
doing things

Ryan Reece rreece

🙈
doing things
View GitHub Profile
@rreece
rreece / run_shell.py
Created March 11, 2023 02:22
run a process in shell and get its output
View run_shell.py
import subprocess
def run_shell(cmd):
out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True, encoding="UTF-8")
return out
@rreece
rreece / path_of_this_file.py
Last active March 3, 2023 19:38
Get the path of this file in python
View path_of_this_file.py
import os
path_of_this_file = os.path.abspath(__file__)
dir_of_this_file = os.path.dirname(os.path.abspath(__file__))
@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.
View test_float16_tfrecord.py
"""
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
View path_is_in_git.py
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
View ubuntu_20.04_setup.txt
# 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
View train_with_print_tf_data.py
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.
View delete_git_submodule.md

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
View train_tf1.py
"""
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
View segment_mean.py
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
View print_total_parameters.py
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,