Skip to content

Instantly share code, notes, and snippets.

View adityaiitb's full-sized avatar

Aditya Agrawal adityaiitb

View GitHub Profile
@adityaiitb
adityaiitb / xticlabel.plt
Created August 25, 2021 05:04
gnuplot xticlabel
# Data file
# 1 10
# 2 15
# 3 50
# 4 ...
# ....
# Can replace x2ticlabel with xticlabel as well
# When column(1) modulo 8 is zero, use "2^{....}" else ""
@adityaiitb
adityaiitb / color.plt
Created June 22, 2021 05:01
GNUplot colors
# line styles for ColorBrewer Set3
# for use with qualitative/categorical data
# provides 8 colors that are more saturated than the Pastels but less so than Set2
# compatible with gnuplot >=4.2
# author: Anna Schneider
# Modified by Aditya
# line styles
set style line 1 lc rgb '#a6cee3'
set style line 2 lc rgb '#1f78b4'
@adityaiitb
adityaiitb / commands.py
Created April 8, 2021 05:38
Pandas commands
# Show all rows
pd.set_option('display.max_rows', None)
# Reset index after an operation
df.sort_values(['country', 'capital']).reset_index(drop=True)
@adityaiitb
adityaiitb / pybind11.md
Last active October 22, 2020 05:41
pybind11

Pybind11 Doc

  • Create binding for a simple function
#include<pybind11/pybind11.h>

int add(int i, int j) {
    return i + j;
}
@adityaiitb
adityaiitb / graphdef_nodes.md
Created August 27, 2020 15:07
TF GraphDef and Nodes

List of TF ops

A graph def has nodes. Every node has

  • Op: E.g. AddV2, Placeholder, Const.
  • Name (namescope): This is also the name of the output tensor(s). To refer to a specific index, you can say "name:0".
  • Inputs (optional): E.g. Const and Placeholder ops do not have any inputs.

Placeholder ops are fed from the user input? Const ops are fed from the variables folder?

@adityaiitb
adityaiitb / tf_record.md
Last active August 27, 2020 14:53
Reading a TF record file

Documentation.

import tensorflow as tf

raw_dataset = tf.data.TFRecordDataset("foo.tfrecord")

for raw_record in raw_dataset.take(1):
    example = tf.train.Example()
 example.ParseFromString(raw_record.numpy())
@adityaiitb
adityaiitb / pretty_json.md
Created August 22, 2020 17:27
Pretty print JSON from the command line

The json.tool module provides a simple command line interface to validate and pretty-print JSON objects. link

python -m json.tool foo.json
@adityaiitb
adityaiitb / client_grpc.py
Last active August 27, 2020 14:09
Tensorflow Model Server and gRPC Client
#!/usr/bin/env python3
import tensorflow as tf
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2_grpc
import numpy as np
import grpc
channel = grpc.insecure_channel("localhost:8500")
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
@adityaiitb
adityaiitb / Saved_model_aot.md
Last active April 6, 2022 14:15
Tensorflow XLA Ahead-of-Time (AOT) compilation with Saved Model (TF2)

Frozen graph is deprecated in TF2. Using Saved model is the new approach. Instead of creating a configuration file and using bazel in steps 1 and 2 described here, simply use the saved_model_cli. The final compilation step of creating a binary can be performed using a makefile instead of bazel.

  1. Create a TF saved_model using tf.saved_model.save.
  2. Use the saved_model_cli to perform XLA AOT compilation.
saved_model_cli aot_compile_cpu \
    --dir resnet/1 \
    --tag_set serve \
 --signature_def_key serving_default \
@adityaiitb
adityaiitb / tensorflow_graph.md
Last active August 27, 2020 17:30
How to obtain a Graph in TensorFlow2

tf.function compiles a function into a callable TensorFlow graph. Documentation

@tf.function
def f(x):
  return x + 1

To obtain a graph / graphdef

Use the get_concrete_function method of the callable created by tf.function. It returns a tf.Graph object.