Skip to content

Instantly share code, notes, and snippets.

@rsepassi
rsepassi / data_stack.py
Created May 8, 2014 19:23
Import sci stack
import numpy as np
import scipy as sp
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
# Countdown
function countdown(){
echo "Countdown started: $1 minutes"
background_countdown $1 &
}
function background_countdown(){
date1=$((`date +%s` + $1 * 60));
while [ "$date1" -ge `date +%s` ]; do
:
done
@rsepassi
rsepassi / example.py
Last active October 11, 2018 15:23
tensorflow/datasets
import tensorflow as tf
import tensorflow_datasets as tfds
# tfds works with Eager and Graph modes
tf.enable_eager_execution()
# 0. Select the dataset you'd like to use
print(tfds.list_builders())
# 1. Construct the DatasetBuilder
@rsepassi
rsepassi / tf-repeat.ipynb
Created February 22, 2019 04:24
tf.repeat
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import tensorflow_datasets as tfds
# Download the dataset and create a tf.data.Dataset
ds, info = tfds.load("mnist", split="train", with_info=True)
# Access relevant metadata with DatasetInfo
print(info.splits["train"].num_examples)
print(info.features["label"].num_classes)
# Build your input pipeline
# Install: pip install tensorflow-datasets
import tensorflow_datasets as tfds
mnist_data = tfds.load("mnist")
mnist_train, mnist_test = mnist_data["train"], mnist_data["test"]
assert isinstance(mnist_train, tf.data.Dataset)
import tensorflow_datasets as tfds
# Fetch the dataset directly
mnist = tfds.image.MNIST()
# or by string name
mnist = tfds.builder('mnist')
# Describe the dataset with DatasetInfo
assert mnist.info.features['image'].shape == (28, 28, 1)
assert mnist.info.features['label'].num_classes == 10
import tensorflow_datasets as tfds
datasets = tfds.load("mnist")
train_dataset, test_dataset = datasets["train"], datasets["test"]
assert isinstance(train_dataset, tf.data.Dataset)
# See the built-in configs
configs = tfds.text.IMDBReviews.builder_configs
assert "bytes" in configs
# Address a built-in config with tfds.builder
imdb = tfds.builder("imdb_reviews/bytes")
# or when constructing the builder directly
imdb = tfds.text.IMDBReviews(config="bytes")
# or use your own custom configuration
my_encoder = tfds.features.text.ByteTextEncoder(additional_tokens=['hello'])
imdb = tfds.builder("imdb_reviews/subwords8k")
# Get the TextEncoder from DatasetInfo
encoder = imdb.info.features["text"].encoder
assert isinstance(encoder, tfds.features.text.SubwordTextEncoder)
# Encode, decode
ids = encoder.encode("Hello world")
assert encoder.decode(ids) == "Hello world"