Skip to content

Instantly share code, notes, and snippets.

View uzl's full-sized avatar

Uzzal Podder uzl

View GitHub Profile
@uzl
uzl / attn_calc_methods.py
Last active April 8, 2024 09:59
Attention Calculation Methods
import torch.nn as nn
import torch.nn.functional as F
from torch.backends.cuda import sdp_kernel, SDPBackend
import time
import torch
import torch.utils.benchmark as benchmark
# check dependency
assert torch.cuda.is_available(), 'CUDA is expected.'
@uzl
uzl / cropping_char.py
Created February 18, 2020 07:08
Cropping important part
from pathlib import Path
from pprint import pprint
import cv2
import numpy as np
import matplotlib.pyplot as plt
import concurrent
from tqdm import tqdm
# Just for visualization. By default it is inactive
def display_img(img_list):
@uzl
uzl / BCELoss_testing.py
Created January 16, 2020 17:02
BCELoss Testing with custom input
import torch
y_pred = torch.tensor([
[1, 1, 0, 1, 1, 1]
], dtype=torch.float)
y_truth_id = torch.tensor([2], dtype=torch.long)
y_truth_id_tmp = y_truth_id.unsqueeze(0)
y_truth_one_hot = torch.zeros(y_truth_id_tmp.size(0), 6).scatter_(1, y_truth_id_tmp, 1.)
@uzl
uzl / docker history
Created September 26, 2019 05:48
To generate the docker file, docker history can be used.
docker history --no-trunc c3555fec4fe6 $argv | tac | tr -s ' ' | cut -d " " -f 5- | sed 's,^/bin/sh -c #(nop) ,,g' | sed 's,^/bin/sh -c,RUN,g' | sed 's, && ,\n & ,g' | sed 's,\s*[0-9]*[\.]*[0-9]*[kMG]*B\s*$,,g' | head -n -1
@uzl
uzl / docker history.sh
Last active September 26, 2019 05:54
To generate the docker file, docker history can be used.
docker history --no-trunc c3555fec4fe6 $argv | tac | tr -s ' ' | cut -d " " -f 5- | sed 's,^/bin/sh -c #(nop) ,,g' | sed 's,^/bin/sh -c,RUN,g' | sed 's, && ,\n & ,g' | sed 's,\s*[0-9]*[\.]*[0-9]*[kMG]*B\s*$,,g' | head -n -1
@uzl
uzl / get_usb_camera_id_for_opencv.py
Created July 2, 2019 00:15
get usb camera id automatically for opencv
def get_usb_camera_id():
from subprocess import check_output
out = check_output(["ls /dev/video*"], shell=True)
out = out.decode('utf-8').strip().split('\n')
if len(out) == 0:
raise Exception('No camera Module Found')
cam_id = None
for dev in out:
@uzl
uzl / nvidia_driver_install_ubuntu_18.md
Last active April 30, 2022 13:04
Install Latest Nvidia Driver in Ubuntu 18.04

Install Latest Nvidia Driver in Ubuntu 18.04 LTS

Step: 1

Remove previous installation

sudo apt-get purge nvidia*
sudo apt-get autoremove 

@uzl
uzl / generate_distribution.py
Created May 22, 2019 00:44
Generate number array based on a range, std and mean condition
import numpy as np
import scipy.stats
from pprint import pprint
import matplotlib.pyplot as plt
import logging
logging.basicConfig(level=logging.DEBUG)
# source: https://stackoverflow.com/a/50629604/4257991
def my_distribution(min_val, max_val, mean, std):
scale = max_val - min_val
@uzl
uzl / plot_multiple_image.py
Last active February 6, 2020 05:24
Plot multiple image in Matplotlib
def my_plot(img_list):
fig = plt.figure(figsize=(8, 8))
plt.tight_layout()
sqr_arm = round(math.ceil(math.sqrt(len(img_list))))
print(sqr_arm)
columns, rows = sqr_arm, sqr_arm
for i, data in enumerate(img_list):
img, title = data if (isinstance(data, tuple) or isinstance(data, list)) else (data, '')
ax = plt.subplot(rows, columns, i+1)
@uzl
uzl / jupyter_cmds.md
Last active May 13, 2019 02:06
Jupyter Notebook commands

Run remote jupyter in localhost using ssh tunnel

in remote server

jupyter notebook --no-browser --port=8889

in local server