How to enlarge images in TensorBoard

Images can be quite small on Tensorboard when the dataset has small dimensions. Instead of awkwardly zooming the whole board with ctrl +, you can actually pass the maximum number of images per row to the grid constructor on PyTorch: images, _ = batch grid = torchvision.utils.make_grid(images, nrow=2) writer.add_image("images", grid, 0) The default setting puts 8 images per row (on the left in the picture). If the zoomed images (on the right) are now too large, you can still collapse the grid to a miniature by clicking on it....

August 12, 2021

How to get all the hooks of a tensor in PyTorch

Hooks are useful to debug and tinker with your PyTorch models. But how do you debug the hooks themselves? Suppose you have a tensor with some hooks, for instance: t = torch.tensor(1.0, requires_grad=True) def hook_1(grad): return grad * 2 def hook_2(grad): return grad + 1 t.register_hook(hook_1) t.register_hook(hook_2) What if you are adding this kind of hook at different places in your code? The order matters, so you might want to print all the hooks for your tensor to check in which order they are called....

June 22, 2021

How to download Imagenet

The official Imagenet website is a pain to navigate. If you want to download the most common version of Imagenet (with about 150 gigabytes of images), you can get it from Kaggle: https://www.kaggle.com/c/imagenet-object-localization-challenge/data?select=imagenet_object_localization_patched2019.tar.gz. But if you prefer to download from the command line without logging-in through Kaggle, or if you are looking for the full version of Imagenet (with 1.5 terabytes of images), you can use AcademicTorrents. AcademicTorrents is a great way to get datasets and can be faster than a direct download!...

June 5, 2021

How to run a command with multiple arguments in GNU Parallel

GNU Parallel is incredibly useful to run the same command multiple times in parallel. However, I spent an unreasonable amount of time trying to find how to use it for commands that take an arbitrary number of arguments. The manual and online discussions explain how to pipe the output of a command into another while splitting it into chunks. If you just want to read multiple lines and feed them as space-separated arguments to a command, you can simply use the -N argument....

May 6, 2021

Stop asking for the SSH key passphrase (Git in VS Code terminal)

I am using Git from the VS Code terminal on Ubuntu. For some reason, it started to ask me to unlock my SSH key every time I wanted to push/pull. Here are a few things to try first: This is usually fixed by configuring the SSH agent, for instance as explained here in the VS Code documentation. If you are using Zsh, you can also configure the SSH agent with a plugin, such as this one for Oh My Zsh or this one for Zim....

May 2, 2021

LaTeX: left arrow to sample an element uniformly at random

Here is a command to draw a left arrow with a dollar sign. It is commonly used to denote a variable assignment uniformly at random from a given set. LaTeX notation to sample a random elementLaTeX notation to sample a random element $\alpha \overset{{\scriptscriptstyle\$}}{\leftarrow} \mathbb{G}$ Some people use the letter R instead of the dollar sign $. Here are a few variants: LaTeX notation to sample a random element (variants)LaTeX notation to sample a random element (variants)...

April 14, 2021

Scrubbing metadata and optimizing images for a static website

I like to illustrate my blog posts with my own photos, especially for my recipes. However, my phone is storing a lot of information in the EXIF metadata of the photos, such as my GPS location or the brand of my camera. This information is then visible by anyone who downloads a picture and checks its properties. I don’t want this data to be published on my website, so here is how to scrub the photos’ metadata in the command line on Ubuntu....

August 22, 2020

Running Rust tests from VS Code terminal

After installing Rust and configuring the Rust Language Server on VS Code, I wanted to run the tests directly from my IDE instead of typing cargo test in my terminal. However I was getting the following error: > Executing task: cargo test -- --nocapture test_fn < zsh:1: command not found: cargo The terminal process "/usr/bin/zsh '-c', 'cargo test -- --nocapture test_hex_to_u8'" failed to launch (exit code: 127). Terminal will be reused by tasks, press any key to close it....

July 12, 2020

How to describe a list of Kubernetes resources from a file

The usual way to describe a resource with kubectl is to call it by its name and namespace. For example, $ kubectl get pod gke-metadata-server-qqmt6 -n kube-system NAME READY STATUS RESTARTS AGE gke-metadata-server-qqmt6 1/1 Running 0 31h To get two resources, one can simply type both names at once. However for large number of resources, it is more convenient to provide a file containing a list of resources. This is the role of the option -f for describe or get....

June 23, 2020

Check your IP from the command line

TLDR; curl ifconfig.co This website, ifconfig.co, is pretty neat and useful when you play with VPNs and SSH. You can have a more detailed output with http ifconfig.co/json.

May 24, 2020