Skip to content

Instantly share code, notes, and snippets.

View adityaiitb's full-sized avatar

Aditya Agrawal adityaiitb

View GitHub Profile
@adityaiitb
adityaiitb / saved_model.md
Last active August 27, 2020 14:41
Save & Load a TF saved model. Get TF graph (GraphDef) from a saved model.

TF Saved Model

Save a saved_model

#!/usr/bin/env python3

import tensorflow as tf
import numpy as np
@adityaiitb
adityaiitb / install_cuda_cudnn.md
Last active August 5, 2020 23:15
Install CUDA (10.1 or newer) and cuDNN
  1. Download the CUDA toolkit i.e. runfile(local) from Nvidia.
  2. Download the cuDNN .tgz file from Nvidia. You can use this hack from Nvidia Developer Forum to wget a cuDNN file.
  3. Install CUDA toolkit (includes cuBLAS).
export CUDA_ROOT=/where/to/install/cuda
bash cuda_<version>.run --silent \
  --toolkit --toolkitpath=$CUDA_ROOT \
  --samples --samplespath=$CUDA_ROOT/samples 
  --tmpdir=$HOME/tmp
@adityaiitb
adityaiitb / inspect_checkpoint.sh
Last active July 30, 2021 19:01
Inspect the weights of TF saved model / checkpoint
# Tensor names, shape and dtype of each shard
python -m tensorflow.python.tools.inspect_checkpoint --file_name path/variables/variables
# Tensor names, shape and dtype
python -m tensorflow.python.tools.inspect_checkpoint --file_name path/variables/variables --all_tensor_names
# Tensor names, shapes, dtype and value
python -m tensorflow.python.tools.inspect_checkpoint --file_name path/variables/variables --all_tensors
@adityaiitb
adityaiitb / numpy_npz.md
Last active July 30, 2020 15:13
Create a numpy npz file

The .npz file format is used to save several numpy arrays into a single zipped file. Documentation.

import numpy as np

a = np.array([42])
b = np.array([2, 3, 5, 7, 9]) 

with open("foo.npz", "wb") as f:
@adityaiitb
adityaiitb / saved_model_cli.md
Last active October 27, 2021 20:32
TensorFlow Saved Model CLI

Saved Model CLI

Saved Model CLI (show)

saved_model_cli show --dir resnet/1
saved_model_cli show --dir resnet/1 --tag_set serve
@adityaiitb
adityaiitb / onmt.py
Last active July 26, 2020 00:48
OMNT toolkit example
#!/usr/bin/env python
# python train.py -train_steps 1 -data data/demo -gpu_ranks 0
import subprocess
from itertools import product
src_emb = [128, 1024]
dst_emb = [128, 1024]
hidden = [128, 1024]
@adityaiitb
adityaiitb / aten.md
Last active July 26, 2020 00:19
How to use PyTorch ATen

A simple example of how to use PyTorch ATen directly using C++.

@adityaiitb
adityaiitb / embed_fonts_pdf.md
Created July 26, 2020 00:06
Embed Post Script fonts and create a PDF
ps2epsi foo.ps
#ps2pdf14 -dEPSCrop -dAutoRotatePages=/None -dPDFSETTINGS=/prepress -dEmbedAllFonts=true foo.epsi foo.pdf
ps2pdf14 -dEPSCrop -dAutoRotatePages=/All -dPDFSETTINGS=/prepress -dEmbedAllFonts=true foo.epsi foo.pdf

Using pdftk

touch out.pdf
pdftk foo.pdf cat 1E output out.pdf

Using pdf270

pdf270 --suffix 'turned' foo.pdf
mv foo-turned.pdf foo.pdf
@adityaiitb
adityaiitb / debian_package.md
Created July 25, 2020 23:50
Extract a Debian package

DEB files are ar archives, which contain three files:

  • debian-binary
  • control.tar.gz
  • data.tar.gz

Unpacking this file is a two step process.

ar vx mypackage.deb
tar -xzvf data.tar.gz