Skip to content

Instantly share code, notes, and snippets.

View danijar's full-sized avatar

Danijar Hafner danijar

View GitHub Profile
@danijar
danijar / tf_char_rnn.py
Last active March 21, 2024 16:55
Simple character-level recurrent language model implemented in TensorFlow.
"""Character based language modeling with multi-layer GRUs.
To train the model:
python3 tf_char_rnn.py --mode training \
--logdir path/to/logdir --corpus path/to/corpus.txt
To generate text from seed words:
python3 tf_char_rnn.py --mode sampling \
@danijar
danijar / blog_tensorflow_sequence_labelling.py
Last active January 12, 2024 15:18
TensorFlow Sequence Labelling
# Example for my blog post at:
# http://danijar.com/introduction-to-recurrent-networks-in-tensorflow/
import functools
import sets
import tensorflow as tf
def lazy_property(function):
attribute = '_' + function.__name__
@danijar
danijar / blog_tensorflow_variational_auto_encoder.py
Last active February 22, 2023 09:02
TensorFlow Variational Auto-Encoder
# Full example for my blog post at:
# https://danijar.com/building-variational-auto-encoders-in-tensorflow/
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
tfd = tf.contrib.distributions
@danijar
danijar / blog_tensorflow_scope_decorator.py
Last active January 17, 2023 01:58
TensorFlow Scope Decorator
# Working example for my blog post at:
# https://danijar.github.io/structuring-your-tensorflow-models
import functools
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
def doublewrap(function):
"""
A decorator decorator, allowing to use the decorator to be used without
@danijar
danijar / !seamless_focus_movement.md
Last active June 29, 2022 23:36
Seamless focus switching between Vim splits, Vim tabs, and Tmux panes.

No plugins needed!

@danijar
danijar / blog_tensorflow_variable_sequence_labelling.py
Last active May 15, 2022 14:28
TensorFlow Variable-Length Sequence Labelling
# Working example for my blog post at:
# http://danijar.com/variable-sequence-lengths-in-tensorflow/
import functools
import sets
import tensorflow as tf
from tensorflow.models.rnn import rnn_cell
from tensorflow.models.rnn import rnn
def lazy_property(function):
@danijar
danijar / agents_on_dm_control.py
Last active January 3, 2022 14:18
Training TensorFlow Agents PPO on dm_control environments.
import argparse
import os
import agents
import gym
import gym.spaces
import numpy as np
import tensorflow as tf
from dm_control import suite # Must be imported after TensorFlow.
@danijar
danijar / blog_tensorflow_variable_sequence_classification.py
Last active December 31, 2021 10:04
TensorFlow Variable-Length Sequence Classification
# Working example for my blog post at:
# http://danijar.com/variable-sequence-lengths-in-tensorflow/
import functools
import sets
import tensorflow as tf
from tensorflow.models.rnn import rnn_cell
from tensorflow.models.rnn import rnn
def lazy_property(function):
@danijar
danijar / blog_tensorflow_sequence_classification.py
Last active December 24, 2021 03:53
TensorFlow Sequence Classification
# Example for my blog post at:
# https://danijar.com/introduction-to-recurrent-networks-in-tensorflow/
import functools
import sets
import tensorflow as tf
def lazy_property(function):
attribute = '_' + function.__name__
@danijar
danijar / share_variables_decorator.py
Last active November 20, 2021 17:21
TensorFlow decorator to share variables between calls. Works for both functions and methods.
import functools
import tensorflow as tf
class share_variables(object):
def __init__(self, callable_):
self._callable = callable_
self._wrappers = {}