Skip to content

Instantly share code, notes, and snippets.

View BinRoot's full-sized avatar

Nishant Shukla BinRoot

View GitHub Profile
@BinRoot
BinRoot / xmonad.hs
Created December 28, 2013 00:45
My current xmonad config. Made with love.
-- Author: BinRoot
-- Todo: dmenu, animations
import XMonad
import XMonad.Config.Gnome
import XMonad.Layout.NoBorders (smartBorders)
import XMonad.Hooks.FadeInactive (fadeInactiveLogHook)
import XMonad.Hooks.ManageDocks (manageDocks)
import XMonad.Hooks.SetWMName (setWMName)
import XMonad.Layout.Spacing (smartSpacing)
But even if TextMate 2 drops from the sky fully-formed and marveled
at by all, Emacs will still be there, waiting. It will be there when
the icecaps melt and the cities drown, when humanity destroys itself
in fire and zombies, when the roaches finally achieve sentience, take
over, and begin using computers themselves — at which point its
various Ctrl-Meta key-chords will seem not merely satisfyingly
ergonomic for the typical arthropod, but also direct evidence for the
universe’s Intelligent Design by some six-legged, multi-jointed
God.
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
import os
from six.moves import urllib
import zipfile
import tensorflow as tf
import collections
import csv
class DatasetLoader:
def __init__(self):
self.url = 'http://mattmahoney.net/dc/'
import tensorflow as tf
x = tf.Variable(2, name='x', dtype=tf.float32)
log_x = tf.log(x)
y = tf.square(log_x) + 1
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(y)
init = tf.global_variables_initializer()

TensorFlow Serving in 10 minutes!

TensorFlow SERVING is Googles' recommended way to deploy TensorFlow models. Without proper computer engineering background, it can be quite intimidating, even for people who feel comfortable with TensorFlow itself. Few things that I've found particularly hard were:

  • Tutorial examples have C++ code (which I don't know)
  • Tutorials have Kubernetes, gRPG, Bezel (some of which I saw for the first time)
  • It needs to be compiled. That process takes forever!

After all, it worked just fine. Here I present an easiest possible way to deploy your models with TensorFlow Serving. You will have your self-built model running inside TF-Serving by the end of this tutorial. It will be scalable, and you will be able to query it via REST.

import tensorflow as tf
# Define a matrix and negate it
matrix = tf.constant([[1., 2.]])
negMatrix = tf.neg(matrix)
# Start the session with a special config passed into the constructor to enable logging
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
# Evaluate negMatrix
result = sess.run(negMatrix)
import tensorflow as tf
# Define an arbitrary matrix
matrix = tf.constant([[1., 2.]])
# Run the negation operator on it
neg_matrix = tf.neg(matrix)
# Start a session to be able to run operations
with tf.Session() as sess:
import tensorflow as tf
# Define an arbitrary tensor
x = tf.constant([[1, 2]])
# Negate the tensor
neg_x = tf.neg(x)
# Print the object
print(neg_x)
import tensorflow as tf
# Define a 2x1 matrix
matrix1 = tf.constant([[1., 2.]])
# Define a 1x2 matrix
matrix2 = tf.constant([[1],
[2]])
# Define a rank 3 tensor