Skip to content

Instantly share code, notes, and snippets.

View saravanabalagi's full-sized avatar

Saravanabalagi Ramachandran saravanabalagi

  • Ireland
View GitHub Profile
@saravanabalagi
saravanabalagi / react_native_release_apk.md
Last active November 15, 2019 21:01
How to generate Standalone Release APK in React Native

Generate keystore file

keytool -genkey -v -keystore some_filename.keystore -alias your_alias -keyalg RSA -keysize 2048 -validity 10000

This should prompt

  • Keystore Password
  • Name
  • Organizational Unit
  • Organization Name
@saravanabalagi
saravanabalagi / tf2_tracing_estimators.md
Created January 16, 2020 11:20
Profiling Tensorflow Estimator in tf2

Based on Summary Trace API,

device_name = tf.test.gpu_device_name()
if not tf.test.is_gpu_available():
    raise SystemError('GPU device not found')
print('Found GPU at: {}'.format(device_name))
os.makedirs(os.path.join(args.exp_dir, 'plugins/profile'), exist_ok=True)
tf.summary.trace_on(graph=True, profiler=True)
tracing_params = params.copy()
@saravanabalagi
saravanabalagi / image_plt.md
Created January 17, 2020 11:36
Get image from Matplotlib plt as numpy array

If you want to get the image plot from plt as numpy array,

def _retrieve_image(fig):
    fig.canvas.draw()
    width, height = fig.get_size_inches() * fig.get_dpi()
    image = np.frombuffer(fig.canvas.tostring_argb(), dtype='uint8').reshape(int(height), int(width), 4)
    image = image[:, :, [1, 2, 3, 0]]          # convert from argb to rgba
    plt.close(fig)
    return image
@saravanabalagi
saravanabalagi / matplotlib.md
Created January 17, 2020 16:39
Converting Grayscale (1 Channel) to RGB (3 Channel)

Converting from RGB (3 Channel) to Grayscale (1 Channel) involves [0.2989, 0.5870, 0.1140] weighted averaging. So when converting Grayscale (1 Channel) to RGB (3 Channel), is it okay to repeat the single channel thrice?

image_rgb = np.full([28, 28, 3], fill_value=1.0)

image_bw_cv = cv2.cvtColor(image_rgb, cv2.COLOR_BGR2GRAY)
image_bw = np.dot(image_rgb[..., :3], [0.2989, 0.5870, 0.1140])
image_bw = np.array(image_bw, dtype='uint8')
image_rgb_converted = np.stack([image_bw]*3, axis=-1)

Instruction for Installing TensorRT

  1. Download .deb from https://developer.nvidia.com/nvidia-tensorrt-6x-download
  2. Run sudo dpkg -i nv-tensorrt-repo-ubuntu1x04-cudax.x-trt6.x.x.x-ga-yyyymmdd_1–1_amd64.deb
  3. Add public key using curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
  4. Update sources sudo apt-get update
  5. Install TensorRT sudo apt-get install tensorrt
  6. Verify Installation dpkg -l | grep TensorRT
@saravanabalagi
saravanabalagi / estimator_eval_callback.md
Last active April 15, 2020 09:42
Tensorflow Estimator additional evaluations using hooks/callbacks

Estimator Evaluation Callback/Hook

Estimator Setup

Build estimator

config = tf.estimator.RunConfig(save_summary_steps=100, keep_checkpoint_every_n_hours=1, keep_checkpoint_max=1, model_dir=params.model_dir, save_checkpoints_steps=500)
estimator = tf.estimator.Estimator(model_fn, params=params, config=config)
@saravanabalagi
saravanabalagi / estimator_summary_writer_v2_hack.md
Last active February 13, 2020 14:42
Hack for using Summary Writer V2 with estimator summary writers (when calling outside of estimators)

Modify

def log_all_losses(embeddings, labels, params):
    for (func_name, func) in loss_funcs.items():
        func(embeddings, labels, params)

to

Installation

Create the following shell file

#!/usr/bin/env bash

sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt update
@saravanabalagi
saravanabalagi / installing_vl_matconvnet.md
Last active September 29, 2021 16:01
How to install vl_matconvnet with GPU Support

Prerequisites

  1. MATLAB 2017a
  2. gcc 4.9 and g++ 4.9

Installation

Clone MatConvNet repo or download MATLAB Addon Matconvnet and it usually gets downloaded to /home/saravanabalagi/MATLAB Add-Ons/Collections/vlfeat_matconvnet/vlfeat-matconvnet-1e5ae7b on a Linux machine. From here it will be called matconvnet_root.

@saravanabalagi
saravanabalagi / oxford_robotcar_parse_tags.md
Created March 20, 2020 19:34
Parse Oxford Robotcar Tags

Use the following script on Oxford Robotcar Downloads

jQuery('.row.listing.listing-link > .large-6:nth-child(2)').each((i,e) => {
  children = e.childNodes;
  date = children[1].children[0].innerHTML;
  timestamp = children[2].nodeValue.substring(6, 15);
  tags = []
  jQuery(e).find('.icon-price-tag.pr10').each((i, e) => {
 tags.push(e.innerHTML);