Skip to content

Instantly share code, notes, and snippets.

View almeidaraul's full-sized avatar
🥗
eating my greens

Raul Almeida almeidaraul

🥗
eating my greens
View GitHub Profile
@almeidaraul
almeidaraul / howtospeak.md
Created October 6, 2023 06:25
summary of the How to Speak lecture by Patrick Winston

How to Speak - a very brief summary

This is a summary of the How to Speak lecture by Patrick Winston.

I don't necessarily agree with everything mentioned here.

How to start

Start with a promise: what they'll know at the end that they didn't know before

Samples

  • Cycle on the subject: repeat the most important things so people can catch on
@almeidaraul
almeidaraul / loss_and_errors.ipynb
Last active July 18, 2023 00:30
Loss and errors plotting with Plotly
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@almeidaraul
almeidaraul / label_smoothing.md
Created May 27, 2023 03:13
Label Smoothing, explained

Label Smoothing: what it solves and how it works

There are two explanations here: a short and a long one. I suggest you read both in this order, as the short one might provide an overview of what is going on.

This all comes from the original paper by Christian Szegedy, Vincent Vanhoucke, Sergey Ioffe, Jonathon Shlens and Zbigniew Wojna that proposed label smoothing as a regularization technique[^1].

It is also important to note I am talking exclusively about classification

@almeidaraul
almeidaraul / pytest_imports.md
Last active May 27, 2023 03:00
Making sense of pytest imports

Organizing pytest tests

Python imports can get weird, specially when dealing with tests that are to be kept separate from the application code (i.e., in sibling directories).

This is how you organize your tests with pytest.

The code

Directory structure

pkg/
@almeidaraul
almeidaraul / simple_schedule.py
Created May 16, 2023 19:36
Experiment scheduling script
import argparse
import json
import subprocess
from datetime import datetime
from itertools import starmap
def get_args() -> argparse.Namespace:
"""Parse command-line arguments"""
parser = argparse.ArgumentParser(prog="simple_schedule",

Como instalar o MongoDB (Community Edition) no Ubuntu 16.04

Passos retirados da documentação oficial

  1. Importe a chave pública GPG do MongoDB com wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
  2. Crie uma list file do MongoDB com echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
  3. Atualize a base de pacotes com sudo apt-get update
  4. Instale a versão mais recente do MongoDB com sudo apt-get install -y mongodb-org
  5. Inicialize o MongoDB com sudo systemctl start mongod (possivelmente é necessário executar sudo systemctl daemon-reload antes)
  6. Verifique o status do MongoDB com sudo systemctl status mongod
  7. Para garantir que o MongoDB seja inicializado sempre que a máquina seja reiniciada, sudo systemctl enable mongod
@almeidaraul
almeidaraul / early_stopping_aux.py
Last active January 9, 2023 18:56
Early stopping auxiliary tool; plots val vs train loss with optional results with early stopping
"""
Reads CSVs exported from TensorBoard (i.e., with a 'Value' column) to serve
as a tool for early stopping analysis (best point to stop, train/val loss
comparison, results if stopping at point X, etc)
"""
import argparse
import pandas as pd
import matplotlib.pyplot as plt
@almeidaraul
almeidaraul / post_file.md
Created July 22, 2022 19:40
How to send a file in a POST request

How to send a file from a Vue client to an Express server with a POST request

There are two steps intrinsic to a file being sent: the sender sending it off, and the receiver getting it. Let's go through that.

Vue client

Your Vue client will have a form and a function for doing something with that form. The form should look something like this:

<form v-on:submit.prevent="onSubmit" enctype="multipart/form-data">
  <input
    type="file"
    name="file"
@almeidaraul
almeidaraul / vid2img.py
Last active April 2, 2022 16:17
extract frames from videos (OpenCV)
"""
turn videos in source directory into images in target directory
"""
import sys
import os
import cv2
def save_images(cap, path, num_frames=1):
"""save frames from clip into image (equidistant frames)"""
# path should be like target/videoname
@almeidaraul
almeidaraul / depth.py
Last active April 2, 2022 16:23
extract face depth of all images in a directory with 3DDFA_V2
"""
3DDFA_V2: https://github.com/cleardusk/3DDFA_V2
most of the code comes from their example Google Colab project, some of it
was slightly altered
ran this on the 3DDFA_V2 directory, so you might have to change some paths
check original code to see other options
"""
import cv2
import yaml