Skip to content

Instantly share code, notes, and snippets.

@venuktan
venuktan / load_tf_graph_bytes.py
Created February 12, 2019 21:06
tf load graph from bytes
def load_ascii_bytes(model):
graph_def = tf.GraphDef()
graph_def.ParseFromString(model)
with tf.Graph().as_default() as graph:
tf.import_graph_def(
graph_def,
input_map=None,
return_elements=None,
name="",
# This file is useful for reading the contents of the ops generated by ruby.
# You can read any graph defination in pb/pbtxt format generated by ruby
# or by python and then convert it back and forth from human readable to binary format.
import tensorflow as tf
from google.protobuf import text_format
from tensorflow.python.platform import gfile
def pbtxt_to_graphdef(filename):
with open(filename, 'r') as f:
import os
os.environ["PYTHONPATH"]="/Users/vtangirala/spark-2.4.0/python/lib/py4j-0.10.7-src.zip:"+os.environ["PYTHONPATH"]
os.environ["PYTHONPATH"]
from pyspark import SparkConf
from pyspark import SparkContext
conf = SparkConf()
conf.setMaster("spark://vtangirala-mac.adaptiveplanning.com:7077").setAppName("venu")
conf.set("spark.cores.max", "1")
def minArea(x, y, k):
# def eucledian_dist(a,b):
# return sqrt(sum( (a - b)**2 for a, b in zip(a, b)))
# d = eucledian_dist(x,y)
def avg(l):
return sum (l) / float (len (l))
def stats(x, y):
x_min = min (x)
x_max = max (x)
@venuktan
venuktan / increase_swap_size.txt
Created December 2, 2017 07:11
increase swap size
1. Create empty file:
This file will contain virtual memory contents so make file big enough for your needs. This one will create 1Gb file which means +1Gb swap space for your system:
dd if=/dev/zero of=/media/fasthdd/swapfile.img bs=1024 count=1M
If you want to make 3Gb file then change count value to count=3M. See man dd for more information.
2. Bake swap file:
Following command is going to make "swap filesystem" inside your fresh swap file.
mkswap /media/fasthdd/swapfile.img
@venuktan
venuktan / keras_use_onlycpu_tensorflow.py
Last active December 1, 2017 06:23
keras use only cpu; tensorflow config Proto
import tensorflow as tf
from keras import backend as K
num_cores = 4
if GPU:
num_GPU = 1
num_CPU = 1
if CPU:
num_CPU = 1
import requests
import ast
url="https://gist.githubusercontent.com/yrevar/942d3a0ac09ec9e5eb3a/raw/c2c91c8e767d04621020c30ed31192724b863041/imagenet1000_clsid_to_human.txt"
data=requests.get(url).text
class_num_label = ast.literal_eval(data)
@venuktan
venuktan / my_sql_get_table_usage.sh
Created June 25, 2017 06:43
get memory occupied by each table in MySQL
SELECT
table_schema as `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;
@venuktan
venuktan / linux list number of files in each subdirectory.sh
Created June 17, 2017 05:58
linux list number of files in each subdirectory
find -type d -readable -exec sh -c 'printf "%s " "$1"; ls -1UA "$1" | wc -l' sh {} ';'