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

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

How to print UFW logs

TLDR; sudo tail -f /var/log/ufw.log The following applies to an Ubuntu server. The log files are usually in /var/log, list them with: sudo ls -l /var/log/ufw* It should return a list of log files like the following. The oldest ones are compressed: -rw-r----- 1 syslog adm 1383548 May 18 12:42 /var/log/ufw.log -rw-r----- 1 syslog adm 6492572 May 17 06:24 /var/log/ufw.log.1 -rw-r----- 1 syslog adm 1270159 May 11 06:24 /var/log/ufw.log.2.gz -rw-r----- 1 syslog adm 1459552 May 3 06:25 /var/log/ufw....

May 24, 2020