Skip to content

Instantly share code, notes, and snippets.

View mil-ad's full-sized avatar

Milad Alizadeh mil-ad

View GitHub Profile
# Now available here:
# Now available here:
sbarratt /
Created May 9, 2019 19:40
Get the jacobian of a vector-valued function that takes batch inputs, in pytorch.
def get_jacobian(net, x, noutputs):
x = x.squeeze()
n = x.size()[0]
x = x.repeat(noutputs, 1)
y = net(x)
import torch
def jacobian(y, x, create_graph=False):
jac = []
flat_y = y.reshape(-1)
grad_y = torch.zeros_like(flat_y)
for i in range(len(flat_y)):
grad_y[i] = 1.
grad_x, = torch.autograd.grad(flat_y, x, grad_y, retain_graph=True, create_graph=create_graph)
talkingmoose / New Daily Note.applescript
Last active April 23, 2022 02:33
Begins a new daily note for today in Bear. Adds a "Daily Notes" tag, events for today from Outlook 2016 for Mac calendar and a "Notes" header. Save this AppleScript to the Scripts folder for Bear at ~/Library/Scripts/Applications/Bear and call it using the system-wide AppleScript menu.
Written by:William Smith
Professional Services Engineer
apaszke /
Last active January 16, 2023 07:20
def Rop(y, x, v):
"""Computes an Rop.
y (Variable): output of differentiated function
x (Variable): differentiated input
v (Variable): vector to be multiplied with Jacobian from the right
w = torch.ones_like(y, requires_grad=True)
return torch.autograd.grad(torch.autograd.grad(y, x, w), w, v)

⚠️ this is now stupidly out of date


  • 13" Macbook Pro 3.3 GHz i7 (late 2016)
  • Microsoft Surface Book (2016)


dapperfu /
Last active November 28, 2019 09:49
Build .deb package for OpenCV 3 w/Python3 bindings.
#!/usr/bin/env bash
# Config
# Adapted from
apt-get install --yes libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev libavcodec-dev libavformat-dev \
libswscale-dev libxvidcore-dev libx264-dev libv4l-dev liblapacke-dev libgtk-3-dev \
libopenblas-dev libhdf5-dev libtesseract-dev libleptonica-dev \
alexlee-gk /
Last active June 21, 2024 03:40
Use integrated graphics for display and NVIDIA GPU for CUDA on Ubuntu 14.04

This was tested on a ThinkPad P70 laptop with an Intel integrated graphics and an NVIDIA GPU:

lspci | egrep 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation Device 191b (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation GM204GLM [Quadro M3000M] (rev a1)

A reason to use the integrated graphics for display is if installing the NVIDIA drivers causes the display to stop working properly. In my case, Ubuntu would get stuck in a login loop after installing the NVIDIA drivers. This happened regardless if I installed the drivers from the "Additional Drivers" tab in "System Settings" or the ppa:graphics-drivers/ppa in the command-line.

soply /
Last active January 9, 2024 14:52
Plot multiple images with matplotlib in a single figure. Titles can be given optionally as second argument.
import matplotlib.pyplot as plt
import numpy as np
def show_images(images, cols = 1, titles = None):
"""Display a list of images in a single figure with matplotlib.
images: List of np.arrays compatible with plt.imshow.