Skip to content

Instantly share code, notes, and snippets.

@thomasmooon
thomasmooon / live_loss_plot_keras.ipynb
Created May 25, 2018 10:12 — forked from stared/live_loss_plot_keras.ipynb
Live loss plot for training models in Keras (see: https://github.com/stared/livelossplot/ for a library)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thomasmooon
thomasmooon / preallocate_memory.py
Created June 6, 2018 15:10
Keras / TF: Limit and assign #GPUs and memory pre-allocated
###################################
## extra imports to set GPU options
###################################
import tensorflow as tf
from keras import backend as k
config = tf.ConfigProto() # TensorFlow wizardry
config.gpu_options.allow_growth = True # Don't pre-allocate memory; allocate as-needed
config.gpu_options.per_process_gpu_memory_fraction = 0.95 # Only allow a total fraction the GPU memory to be allocated
k.tensorflow_backend.set_session(tf.Session(config=config)) # Create a session with the above options specified.
@thomasmooon
thomasmooon / rsf_introduction.Rmd
Created June 7, 2018 06:04
random survival forest example, R, package Ranger
---
title: "Random Survival Forest example"
author: "Thomas Gerlach"
date: "2018 MAY 22"
output: html_notebook
---
# Content
This script briefly introduces training and prediction of a random survival forest
from keras.models import Sequential
from keras.layers import Dense
from keras.utils.io_utils import HDF5Matrix
import numpy as np
def create_dataset():
import h5py
X = np.random.randn(200,10).astype('float32')
y = np.random.randint(0, 2, size=(200,1))
f = h5py.File('test.h5', 'w')
@thomasmooon
thomasmooon / stopwatch.py
Created July 10, 2018 12:39 — forked from igniteflow/stopwatch.py
A simple stopwatch implemented in Python
import datetime
class Timer(object):
"""A simple timer class"""
def __init__(self):
pass
def start(self):
"""Starts the timer"""
@thomasmooon
thomasmooon / ec2-cuda-setup.bash
Created September 21, 2018 16:44 — forked from avtomaton/ec2-cuda-setup.bash
amazon AMI CUDA setup
#!/bin/bash
NVIDIA_DRIVER_VERSION=352.63
NVIDIA_CUDA_VERSION=7.5
NVIDIA_CUDA_FULL_VERSION=7.5.18
sudo yum update -y
sudo yum groupinstall -y "Development tools"
sudo yum install kernel-devel-`uname -r`
@thomasmooon
thomasmooon / tensorflow_self_check.py
Created October 15, 2018 15:09 — forked from mrry/tensorflow_self_check.py
[DEPRECATED] TensorFlow on Windows self-check
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@thomasmooon
thomasmooon / example_trials_visualization.ipynb
Last active November 9, 2018 14:10
hyperopt save and reload trials object
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thomasmooon
thomasmooon / memlog.sh
Created November 26, 2018 08:46
linux memory log
#!/bin/bash -e
echo " date time $(free -m | grep total | sed -E 's/^ (.*)/\1/g')"
while true; do
echo "$(date '+%Y-%m-%d %H:%M:%S') $(free -m | grep Mem: | sed 's/Mem://g')"
sleep 1
done
@thomasmooon
thomasmooon / tf_keras_multiGPU.py
Created January 28, 2019 15:39
keras tensorflow multi GPU assigment and limitation of GPU and GPU-memory usage
def gpu_assignment(gpus, allow_growth = True, per_process_gpu_memory_fraction = 0.95):
# GPU assignment
######################################################
# !! run this BEFORE importing TF or keras !!
# run code only on a single, particular GPU
# from http://kawahara.ca/select-single-gpu-keras/
######################################################
import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"