Skip to content

Instantly share code, notes, and snippets.

View ndgnuh's full-sized avatar

Hùng ndgnuh

View GitHub Profile
@ndgnuh
ndgnuh / convnet_modules.py
Last active October 11, 2023 09:01
Custom torch layers, modules and utilities, ready to be copy-and-pasted
import torch
from torch import nn
from torch.autograd import Function
from torch.nn import functional as F
class BackwardGradNormFn(Function):
"""
A normalization layer that does nothing to the input, but
normalize the gradient.
@ndgnuh
ndgnuh / modelling_hourglass.py
Last active September 2, 2023 16:39
Hourglass Pytorch
"""
Hourglass network, the backbone part.
Implemented according to the CornetNet paper. The ArXiv version does not have the backbone description.
Reference:
- https://link.springer.com/article/10.1007/s11263-019-01204-1
- https://sci-hub.se/https://link.springer.com/article/10.1007/s11263-019-01204-1 (I won't use 40EUR much money *just* to read a paper. Where I live one can buy 10 books with that.)
- https://arxiv.org/abs/1808.01244 (not really related to this implementation, just in case someone is curious about CornetNet)
@ndgnuh
ndgnuh / requirements.txt
Last active August 8, 2023 05:27
requirements.txt
# Global packages to be installed in home directory
# Desktop apps
gdown
https://github.com/thenaterhood/gscreenshot/archive/refs/tags/v3.4.1.tar.gz
# Installed out of convenience
fastapi
uvicorn
pydantic>=2
lenses
@ndgnuh
ndgnuh / mkvenvapp.sh
Last active July 6, 2023 03:47
Create venv and install as app (for apps like labelme and gscreenshot)
#!/bin/sh
# Install venv first.
apppkg="$1"
appcmd="$2"
if [ -z "$apppkg" ]; then
echo "./mvenvapp.sh <apppkg> [appcmd]"
exit 1
@ndgnuh
ndgnuh / hiertext-gm.py
Created June 30, 2023 02:11
[LMDS] hiertext for detection task
import logging
import pickle
import json
import sys
from os import path, makedirs
from io import BytesIO
from argparse import ArgumentParser
from PIL import Image
from lmds import GeneratorModule, create_lmds
from argparse import ArgumentParser
from subprocess import Popen
# docker run -p 9993:80 -v ./:/usr/share/nginx/html/ nginx:stable-alpine3.17-slim
# docker run -v ./:/tmp jrottenberg/ffmpeg:snapshot-alpine -i "rtsp://..." -c copy -hls_time 2 -hls_wrap 10 "/tmp/stream.m3u8"
def main():
parser = ArgumentParser()
parser.add_argument("--port", "-p", type=int)
parser.add_argument("--rtsp", "-i", required=True)
@ndgnuh
ndgnuh / slugifile
Created May 6, 2022 02:47
Slugify file names
#!/bin/sh
if [ -z "$1" ]; then
echo "slugifile <file name> [.ext]"
fi
bn=$(basename "$1" "$2")
slug=$(echo "$bn" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z)
if [ -z "$2" ]; then
echo "$slug"
@ndgnuh
ndgnuh / image.tex
Created February 12, 2022 17:06
Beamer \Image (auto width height)
\newcommand{\Image}[1]{%
\sbox0{\includegraphics[height=0.65\paperheight]{#1}}%
\ifdim\wd0 < \textwidth
\includegraphics[height=0.65\paperheight]{#1}%
\else
\includegraphics[width=\textwidth]{#1}%
\fi%
}
@ndgnuh
ndgnuh / wine-chinese-font.sh
Last active February 8, 2022 02:26
Wine Chinese font
#!/bin/sh
#
# Reference https://askubuntu.com/questions/1019530/chinese-fonts-are-not-visible-in-programs-installed-in-wine
#
# Content of the .reg file just in case
#
# REGEDIT4
#
# [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink]
@ndgnuh
ndgnuh / l2tp-add-config
Created January 22, 2022 04:59
New L2TP Connection profile
#!/bin/sh
# https://askubuntu.com/questions/1167283/l2tp-connection-client-on-ubuntu-18-04-server
VPNDATA="
gateway = [ipv4],
ipsec-enabled = yes,
ipsec-psk = 0s"$(base64 <<<'[PSK]' | rev | cut -c2- | rev)"=,
mru = 1400,
mtu = 1400,
password-flags = 0,
refuse-chap = yes,