Skip to content

Instantly share code, notes, and snippets.

View random-forests's full-sized avatar

Josh Gordon random-forests

View GitHub Profile
const imageElement = document.getElementById('image');
// load the BodyPix model from a checkpoint
const net = await bodyPix.load();
// arguments for estimating person segmentation.
const outputStride = 16;
const segmentationThreshold = 0.5;
const personSegmentation = await net.estimatePersonSegmentation(imageElement, outputStride, segmentationThreshold);
class RandomAgent:
"""Random Agent that will play the specified game
Arguments:
env_name: Name of the environment to be played
max_eps: Maximum number of episodes to run agent for.
"""
def __init__(self, env_name, max_eps):
self.env = gym.make(env_name)
self.max_episodes = max_eps
# Use pre-trained universal sentence encoder to build text vector
review = hub.text_embedding_column(
“review”, “https://tfhub.dev/google/universal-sentence-encoder/1")
features = {
“review”: np.array([“this movie is a masterpiece”, “this movie was terrible”, …])
}
labels = np.array([[1], [0], …])
input_fn = tf.estimator.input.numpy_input_fn(features, labels, shuffle=True)
estimator = tf.estimator.DNNClassifier(hidden_units, [review])
estimator.train(input_fn, max_steps=100)
@random-forests
random-forests / an_embedding_module.py
Last active March 30, 2018 19:06
Snippet for the TF blog
# Download a module and use it to retrieve word embeddings.
embed = hub.Module(“https://tfhub.dev/google/nnlm-en-dim50/1")
embeddings = embed([“The movie was great!”])
@random-forests
random-forests / download_a_module.py
Created March 30, 2018 19:04
Code snippets for the TF blog
# Download and use NASNet feature vector module.
module = hub.Module(
“https://tfhub.dev/google/imagenet/nasnet_large/feature_vector/1")
features = module(my_images)
logits = tf.layers.dense(features, NUM_CLASSES)
probabilities = tf.nn.softmax(logits)
PClass Sex Age Survived
3rd male 22 no
1st female 38 yes
3rd female 26 yes
1st female 35 yes
3rd male 35 no
1st male 54 no
3rd male 2 no
3rd female 27 yes
2nd female 14 yes