Skip to content

Instantly share code, notes, and snippets.

Danijar Hafner danijar

Block or report user

Report or block danijar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View blog_tensorflow_scope_decorator.py
# 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 / agents_pybullet_example.md
Last active Nov 6, 2019
Example for using TensorFlow Agents with custom environments
View agents_pybullet_example.md

TensorFlow Agents PyBullet Usage Example

This example shows how to install TensorFlow agents and use it on custom environments, such as the environments that come with PyBullet.

It works for both Python 3 and Python 2. Just replace pip3 and python3 with pip2 and python2.

Set up the dependencies:

@danijar
danijar / blog_tensorflow_variable_sequence_labelling.py
Last active Oct 31, 2019
TensorFlow Variable-Length Sequence Labelling
View blog_tensorflow_variable_sequence_labelling.py
# 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_variational_auto_encoder.py
Last active Oct 22, 2019
TensorFlow Variational Auto-Encoder
View blog_tensorflow_variational_auto_encoder.py
# 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 / gru.py
Last active Aug 14, 2019
Gated Recurrent Unit with Layer norm and Xavier initializer
View gru.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow as tf
class GRU(tf.contrib.rnn.RNNCell):
View flask_restful_custom_error_handlers.py
import flask_restful
class Api(flask_restful.Api):
"""
Patch Flask-style custom error handling into the Flask-RESTful api class.
"""
def __init__(self, *args, **kwargs):
super(Api, self).__init__(*args, **kwargs)
@danijar
danijar / tf_char_rnn.py
Last active Jul 2, 2019
Simple character-level recurrent language model implemented in TensorFlow.
View tf_char_rnn.py
"""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 / tensorflow-agents-ppo-minitaur.py
Created Oct 23, 2017
Configuration for TensorFlow Agents PPO on MinitaurBulletEnv-v0
View tensorflow-agents-ppo-minitaur.py
def minitaur_config():
# General
algorithm = ppo.PPOAlgorithm
num_agents = 10
eval_episodes = 30
use_gpu = False
# Environment
env = 'MinitaurBulletEnv-v0'
max_length = 1000
steps = 1e7 # 10M
@danijar
danijar / blog_tensorflow_sequence_classification.py
Last active Apr 29, 2019
TensorFlow Sequence Classification
View blog_tensorflow_sequence_classification.py
# 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 / blog_tensorflow_variable_sequence_classification.py
Last active Mar 21, 2019
TensorFlow Variable-Length Sequence Classification
View blog_tensorflow_variable_sequence_classification.py
# 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):
You can’t perform that action at this time.