Skip to content

Instantly share code, notes, and snippets.

View ankitshekhawat's full-sized avatar

Ankit Shekhawat ankitshekhawat

  • Bangalore, India
View GitHub Profile
@ankitshekhawat
ankitshekhawat / swatching.py
Last active January 9, 2023 19:59
A quick python code to detect color of an item from ecommerce website using just kmeans without OpenCV. Nowhere close to accurate but good for a quick hack. Can be improved with Sobel edge detection and skin detection.
import numpy as np
from PIL import Image, ImageDraw
import colorsys, random
from pylab import plot,show
from numpy import vstack,array
from numpy.random import rand
from scipy.cluster.vq import kmeans,vq
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
@ankitshekhawat
ankitshekhawat / export_tf_models.py
Created January 10, 2017 05:50
Export models and weights are trained in Keras to be used in TensorFlow Serving library
from keras import backend as K
import tensorflow as tf
from tensorflow.contrib.session_bundle import exporter
sess = K.get_session()
export_path ="."
export_version = 1
saver = tf.train.Saver(sharded=True)
### Code if you want to only export .meta files
@ankitshekhawat
ankitshekhawat / product.js
Created January 13, 2017 16:41 — forked from cybercase/product.js
Python-like itertools.product function in javascript
function product() {
var args = Array.prototype.slice.call(arguments); // makes array from arguments
return args.reduce(function tl (accumulator, value) {
var tmp = [];
accumulator.forEach(function (a0) {
value.forEach(function (a1) {
tmp.push(a0.concat(a1));
});
});
return tmp;
@ankitshekhawat
ankitshekhawat / wifiscanner.py
Last active February 2, 2017 09:02
A simple python wifi scanner for OSX using OSX's airport command line utility. Returns Mac Addresses and RSSI
from subprocess import check_output
import re
def scan_networks():
airport = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -s'
rc = check_output(airport, shell=True).split('\n')[1:-1]
networks =[]
for i in rc:
i = i.lstrip().rstrip()
@ankitshekhawat
ankitshekhawat / moonraider.js
Last active December 11, 2017 17:56
Change gmail logo user script
// ==UserScript==
// @name Moonraider
// @namespace http://moonraft.com/
// @version 0.2
// @description Chanege the mail logo to one you want
// @author You
// @match https://mail.google.com/mail/*
// @grant none
// ==/UserScript==
Verifying that "ankitshekhawat.id" is my Blockstack ID. https://onename.com/ankitshekhawat

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.

@ankitshekhawat
ankitshekhawat / PIL_to_datauri.py
Last active December 6, 2021 05:53
Convert PIL image to DataURI
#python3
def pil2datauri(img):
#converts PIL image to datauri
data = BytesIO()
img.save(data, "JPEG")
data64 = base64.b64encode(data.getvalue())
return u'data:img/jpeg;base64,'+data64.decode('utf-8')
@ankitshekhawat
ankitshekhawat / GIF2MP4.swift
Last active August 16, 2018 06:22 — forked from powhu/GIF2MP4.swift
Swift 3.0 GIF to MP4 (MacOS)
//
// GIF2MP4.swift
//
// Created by PowHu Yang on 2017/1/24.
// Copyright © 2017 PowHu Yang. All rights reserved.
//
@ankitshekhawat
ankitshekhawat / letterbox.py
Last active May 7, 2019 12:24
Resize and place an image in a square with padding.
#PIL method
from PIL import Image
def letterbox(image, size=299, bg=(0,0,0)):
(w,h) = image.size
ratio = size / max([w,h])
image = image.resize((int(ratio*w),int(ratio*h)))
background = Image.new('RGB', (size, size), bg)
background.paste(image, [int((size-s)/2) for s in image.size])
return background