Skip to content

Instantly share code, notes, and snippets.

View nuric's full-sized avatar

nuric

View GitHub Profile
@nuric
nuric / ZeroGRU.py
Created March 27, 2018 11:24
A wrapper for Keras GRU that skips timesteps if inputs for that timestep are all zeros.
"""ZeroGRU module."""
import keras.backend as K
import keras.layers as L
class ZeroGRUCell(L.GRUCell):
"""GRU Cell that skips timestep if inputs is zero as well."""
def call(self, inputs, states, training=None):
"""Step function of the cell."""
h_tm1 = states[0] # previous output
# Check if all inputs are zero for this timestep
@nuric
nuric / statefulcheckpoint.py
Last active August 24, 2018 17:20
Stateful Checkpoint for Keras
import json
import socket
from keras.callbacks import ModelCheckpoint
class StatefulCheckpoint(ModelCheckpoint):
"""Save extra checkpoint data to resume training."""
def __init__(self, weight_file, state_file=None, **kwargs):
"""Save the state (epoch etc.) along side weights."""
super().__init__(weight_file, **kwargs)
self.state_f = state_file
"""Configuration library for experiments."""
from typing import Dict, Any
import logging
import pprint
import sys
import argparse
logger = logging.getLogger(__name__)
parser = argparse.ArgumentParser(description=__doc__, fromfile_prefix_chars="@")