Skip to content

Instantly share code, notes, and snippets.

@vitchyr
vitchyr / pdf2svgs.py
Last active December 18, 2023 12:31
Convert PDF to multiple SVGs with Inkscape and pyPdf
"""
Author: Vitchyr Pong
Convert a PDF to svg files. Note that this is pretty slow since it makes
subprocess calls to inkscape's PDF-to-SVG command line convert.
Requirements:
- Inkscape (https://inkscape.org/)
- pyPdf (http://pybrary.net/pyPdf/)
- A '/tmp' directory. If not, you must pass in another directory.
@vitchyr
vitchyr / layer_normalization.py
Last active June 17, 2019 08:15
Layer Norm Implementation in TensorFlow
import tensorflow as tf
LAYER_NORM_BIAS_DEFAULT_NAME = "ln_bias"
LAYER_NORM_GAIN_DEFAULT_NAME = "ln_gain"
LAYER_NORMALIZATION_DEFAULT_NAME = "layer_normalization"
def layer_normalize(
input_pre_nonlinear_activations,
input_shape,
epsilon=1e-5,
@vitchyr
vitchyr / minimal_img_display_example.py
Last active May 21, 2020 20:55
Python 3 - Minimal example for displaying an image without matplotlib in Google Colab
import PIL.Image
from io import BytesIO
from IPython.display import display, Image
import numpy as np
def show_img(a, fmt='png'):
# https://stackoverflow.com/questions/19471814/display-multiple-images-in-one-ipython-notebook-cell
a = np.uint8(a)
f = BytesIO()
PIL.Image.fromarray(a).save(f, fmt)
@vitchyr
vitchyr / git_info.py
Created May 14, 2021 23:15
Save Git Info in Python for Reproducible Experiments
"""
Helper functions to save git information every time you
Requirements:
- GitPython==2.1.12
(Probably works on other GitPython versions, but this is the version I've tested.)
Usage:
```