Skip to content

Instantly share code, notes, and snippets.

View tldrafael's full-sized avatar

Rafael Toledo tldrafael

View GitHub Profile
$ for f in `ls *`; do nc=${#f}; nc2=$((10-$nc)); if [ $nc2 -gt 0 ]; then preffix=`printf '0%.0s' $(seq 1 $nc2)`; newf=$preffix$f; mv $f $newf; fi; done
@tldrafael
tldrafael / convert_masksize.txt
Created March 23, 2022 18:29
Generic example to convert image mask size and keep only 0, 1 values
convert $f -interpolate nearest-neighbor -interpolative-resize 352x288! $newf
@tldrafael
tldrafael / findresolution.txt
Last active March 23, 2022 18:24
Get all images' resolutions contained on a directory
for f in *; do file $f | sed 's/.*, \(.*\)x\(.*\),.*/\1x\2/'; done | sort | uniq -c
export UID=$(id -u)
export GID=$(id -g)
docker run --user $UID:$GID \
--workdir="/home/$USER" \
-v "/etc/group:/etc/group:ro" \
-v "/etc/passwd:/etc/passwd:ro" \
-v "/etc/shadow:/etc/shadow:ro" \
-it $DOCKER_IMAGE
@tldrafael
tldrafael / argparse_example
Created November 9, 2020 21:45
Simple snippet to use argparse
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-d', type=str, help='directory path', dest='dpath')
parser.add_argument('-f', type=str, help='filepath', dest='fpath')
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
if not any([args.dpath, args.fpath]):
@tldrafael
tldrafael / deltaE2000_loss.py
Created June 8, 2020 12:51
deltaE2000 loss function
# Code adapted from skimage
# https://github.com/riaanvddool/scikits-image/blob/master/skimage/color/delta_e.py#L123
import numpy as np
import tensorflow as tf
def tf_deg2rad(deg):
return (deg / 180) * np.pi
def tf_rad2deg(rad):
xgb_params = {'objective': 'multi:softmax',
'num_class': 19,
'tree_method': 'exact',
# 'max_bin': 64,
'colsample_bytree': 0.75,
'subsample': 0.75,
# 'lambda': 2,
# 'alpha': 2,
# 'min_child_weight': 10,
# 'max_delta_step': 10,
@tldrafael
tldrafael / try_except_traceback.py
Created March 5, 2020 14:39
Example to get traceback info
import traceback
import sys
try:
pass
except Exception as e:
traceback_info = ''.join(traceback.format_exception(*sys.exc_info()))
logger.info(traceback_info)
@tldrafael
tldrafael / log.py
Last active May 13, 2022 17:56
Basic python logging configuration
import logging
from logging.handlers import RotatingFileHandler
import traceback
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = RotatingFileHandler('app.log', mode='a', maxBytes=50e6, backupCount=2)
formatter = logging.Formatter('%(asctime)s,%(message)s', datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)
@tldrafael
tldrafael / CONFIGURE
Last active February 18, 2020 17:40
Configuring EC2 AWS g4 GPUs machine
# Install cuda-10.0 because the newest one (for now the version 10.2) mismatchs the tensorflow 1.14.0 requirements
wget https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd6
dpkg -i cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd6
apt-key add /var/cuda-repo-10-0-local-10.0.130-410.48/7fa2af80.pub
apt-get install cuda
# This cuda version install nvidia v410 drivers. Remove it.