12/25/2020
12/23/2020
delete over than specific megabyte in git history using bfg
firstly, install bfg
on mac
> brew install bfg
delete object if over than 50m in git commit history
> bfg --strip-blobs-bigger-than 50M
make sure & apply .gitignore
First, to check what files are you actually tracking
> git ls-tree --name-only --full-tree -r HEAD
Let say that you found unwanted files in a directory like cache/ so, it's safer to target that directory instead of all of your files.
So instead of:
> git rm -r --cached .
It's safer to target the unwanted file or directory:
> git rm -r --cached cache/
Then proceed to add all changes:
> git add .
and commit
> git commit -m ".gitignore is now working"
list up and sorting file(object) size in git / command
use following cmd:
> git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | sed -n 's/^blob //p' | sort --numeric-sort --key=2 | cut -c 1-12,41- | $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
12/22/2020
get YouTube video url from channel name, python youtube-dl library
install youtube-dl package first.
pip install YouTube-dl
<code>
</code>
Thank you.
Download or streaming YouTube video through cv2, python sample code
firstly, install pafy python package
> pip install pafyok then everything will be work using following code:
Thank you.
12/21/2020
python notebook clear output
from IPython.display import clear_output
for i in range(10):
clear_output(wait=True)
print("Hello World!")
12/17/2020
generate .spec file with onefile option for pyinstaller
Use
pyi-makespec --onefile yourprogram.py
to generate a sample spec file for onefile mode.
reference :
https://stackoverflow.com/questions/47143315/using-onefile-with-a-spec-in-pyinstaller
12/14/2020
rsync exclude file and folder
command is like that:
rsync -avz --progress ./source ./destination --exclude-from './exclude-list.txt'
you can make ignore file and folder like this:
exclude-list.txt
*.txt
*.jpg
*.jpeg
*.zip
*.ipynb
.git
*.json
*.done
*.png
*.xml
*.pyc
*/build
*/dist
*/experiment
*/grapher_outputs
*.pkl
*/system_evaluation
12/10/2020
linux screen command list in summary
screen -S name
*leave with alive
Ctrl a, d
*enter screen
*kill specific screen
screen -S name -X quit
*show screen list
screen -ls
*detach specific screen
screen -d name
killall screen
12/07/2020
shuffle dict in python
code
result
{'b': [2, 4], 'd': [2, 4], 'a': [1, 2], 'c': [3, 5]}
12/01/2020
torch.nan_to_num not found error
torch.nan_to_num
This is for 1.8 version.
so use it instead of this.
temp[torch.isnan(temp)] = 0
temp is tensor
11/29/2020
11/27/2020
get parameter from parameter store of aws system manager, python example code
firstly create parameter in parameter store of AWS system manager
Then get the key from this code.
code
.
s3 bucket copy object to another bucket, python example
code
.
aws s3 get all object more than 1000 python example code
simply to use paginator instance
example code
.
11/02/2020
sci sparse -> tuple list -> sci sparse
refer to below source code
source code start
source code end
10/31/2020
VS code SSH fails to connect: Connecting was canceled
Type this one in server side.
rm -rf ~/.vscode-server/
10/09/2020
draw roc curve using python sklearn, Matplotlib
10/08/2020
print gpu memory status in python
*install pynvml
https://pypi.org/project/pynvml/
pip install pynvml
*use below code in python code
from pynvml import *
nvmlInit()
h = nvmlDeviceGetHandleByIndex(0)
info = nvmlDeviceGetMemoryInfo(h)
print(f'total : {info.total}')
print(f'free : {info.free}')
print(f'used : {info.used}')
10/06/2020
remove duplicated tuple item in list (python code)
before:
[(0, 0), (0, 1), (0, 3), (1, 0), (1, 1), (1, 2), (2, 1), (2, 2), (2, 3), (3, 0), (3, 2), (3, 3)]
After: [(0, 1), (1, 2), (0, 0), (3, 3), (2, 3), (2, 2), (0, 3), (1, 1)]
10/02/2020
No module named 'PIL'
pip install --upgrade pip
pip install pillow
9/23/2020
Pytorch, Infinite DataLoader using iter & next
python argparse example
9/21/2020
find best (optimal) threshold using roc curve
def plot_roc_curve(fpr, tpr):
plt.plot(fpr, tpr, color='orange', label='ROC')
plt.plot([0, 1], [0, 1], color='darkblue', linestyle='--')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver Operating Characteristic (ROC) Curve')
plt.legend()
plt.show()
y_true = np.array([0,0, 1, 1,1])
y_scores = np.array([0.0,0.09, .05, .75,1])
fpr, tpr, thresholds = roc_curve(y_true, y_scores)
print(tpr)
print(fpr)
print(thresholds)
print(roc_auc_score(y_true, y_scores))
optimal_idx = np.argmax(tpr - fpr)
optimal_threshold = thresholds[optimal_idx]
print("Threshold value is:", optimal_threshold)
plot_roc_curve(fpr, tpr)
What AUC(area under curve) value is better ?
What AUC(area under curve) value is better ?
0.9 ~ 1 : excellent
0.8 ~ 0.9: good
0.7 ~ 0.8 : normal
0.6 ~ 0.7 : poor
0.5 ~ 0.6 : fail
python measure processing time
9/20/2020
split train test dataset
show image in jupyter notebook
fix hangul separating issue in mac
normalize('ใท ใ ')
-> ๋
python change file name, get file name, dir, ext, check file exist in source code using os package
get file name and ext
get dir
change file name
check file exist
9/18/2020
sparse tensor to csr_matrix
let's image
val_data.x is node features ex) 13x1000
val_data.edge_index is sparse edge index stored by torch tensor
now we want to convert it to csr_matrix
The above code is example for this case.
The print out is like this:
tensor([[ 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12], [ 1, 3, 10, 0, 2, 3, 10, 11, 1, 3, 11, 12, 0, 1, 2, 11, 12, 5, 6, 8, 9, 11, 12, 4, 6, 7, 8, 9, 4, 5, 7, 9, 10, 5, 6, 8, 4, 5, 7, 4, 5, 6, 10, 11, 0, 1, 6, 9, 11, 1, 2, 3, 4, 9, 10, 12, 2, 3, 4, 11]]) [[0. 1. 0. 1. 0. 0. 0. 0. 0. 0. 1. 0. 0.] [1. 0. 1. 1. 0. 0. 0. 0. 0. 0. 1. 1. 0.] [0. 1. 0. 1. 0. 0. 0. 0. 0. 0. 0. 1. 1.] [1. 1. 1. 0. 0. 0. 0. 0. 0. 0. 0. 1. 1.] [0. 0. 0. 0. 0. 1. 1. 0. 1. 1. 0. 1. 1.] [0. 0. 0. 0. 1. 0. 1. 1. 1. 1. 0. 0. 0.] [0. 0. 0. 0. 1. 1. 0. 1. 0. 1. 1. 0. 0.] [0. 0. 0. 0. 0. 1. 1. 0. 1. 0. 0. 0. 0.] [0. 0. 0. 0. 1. 1. 0. 1. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 1. 1. 1. 0. 0. 0. 1. 1. 0.] [1. 1. 0. 0. 0. 0. 1. 0. 0. 1. 0. 1. 0.] [0. 1. 1. 1. 1. 0. 0. 0. 0. 1. 1. 0. 1.] [0. 0. 1. 1. 1. 0. 0. 0. 0. 0. 0. 1. 0.]] <class 'numpy.ndarray'> (13, 13)
Thank you
Enjoy Pytorch!
9/17/2020
error : Bad config encountered during initialization, when you run jupyter
type this
jupyter notebook --generate-config
run juypter again
good luck!
9/07/2020
image augmentation by python
github : https://github.com/aleju/imgaug
9/06/2020
Fix indention in VS code
- On Windows Shift + Alt + F
- On Mac Shift + Option + F
- On Linux Ctrl + Shift + I
8/20/2020
RuntimeError: set_sizes_contiguous is not allowed on Tensor created from .data or .detach(), in Pytorch 1.1.0
change old -> new
old
NEW
8/18/2020
How to fix Python SSL CERTIFICATE_VERIFY_FAILED
put this code on the top of code line:
Get list from dir and separate train and test (python function)
7/29/2020
ROC & AUC example code in face detector model case
..
#https://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_curve.html import numpy as np from sklearn import metrics import matplotlib.pyplot as plt #model #1 y = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) scores = np.array([0.64, 0.47, 0.46, 0.77, 0.72, 0.9, 0.85, 0.7, 0.87, 0.92, 0.89, 0.93, 0.85, 0.81, 0.88, 0.48, 0.1, 0.35, 0.68, 0.47]) fpr, tpr, thresholds = metrics.roc_curve(y, scores) roc_auc = metrics.auc(fpr, tpr) # plot plt.title('Receiver Operating Characteristic') plt.plot(fpr, tpr, 'b', label = 'AUC = %0.2f' % roc_auc) plt.legend(loc = 'lower right') plt.plot([0, 1], [0, 1],'r--') plt.ylabel('True Positive Rate') plt.xlabel('False Positive Rate') plt.show()
..
7/28/2020
Example model metrics using sklearn in face detector case
from sklearn.metrics import classification_report #model 1 y_true = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0] y_pred = [0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0] target_names = ['Non Face', 'Face'] print(classification_report(y_true, y_pred, target_names=target_names, digits=3))
..
#model 2 y_true = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0] y_pred = [0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0] target_names = ['Non Face', 'Face'] print(classification_report(y_true, y_pred, target_names=target_names, digits=3))
7/07/2020
extract year, month, day from file on Ubuntu, python example
7/06/2020
how to merge two csr_matrix, example python source code
..
result
1st (0, 0) 1 (0, 2) 1 (1, 2) 1 (2, 0) 1 (2, 1) 1 (2, 2) 1 2nd (0, 0) 1 (0, 1) 1 (1, 2) 1 (2, 0) 1 (2, 1) 1 (2, 2) 1 merge (0, 0) 2.0 (0, 1) 1.0 (0, 2) 1.0 (1, 2) 2.0 (2, 0) 2.0 (2, 1) 2.0 (2, 2) 2.0
How to convert a scipy csr_matrix back into lists of row, col and data?
..
Define matrix & check values
>
(0, 0) 1 (0, 1) 1 (1, 2) 1 (2, 0) 1 (2, 1) 1 (2, 2) 1
>
[[1 1 0] [0 0 1] [1 1 1]]..
...
get back the row, col and data value from matrix
>
[0 0 1 2 2 2] [0 1 2 0 1 2] [1 1 1 1 1 1]...
6/09/2020
sentence embedding, sentence to vector using bert
.
result is like this:
5/25/2020
install poppler in ubuntu
5/19/2020
Ways to sort list of dictionaries by values in Python – Using lambda function
.
5/15/2020
multi-thread example python source code
If you have look the pid in result, thread is finished by quickly proceeded.
..
result
{'index': 1, 'result': 1000000}
{'index': 3, 'result': 1000000}
{'index': 2, 'result': 1000000}
{'index': 0, 'result': 1000000}
{'index': 5, 'result': 1000000}
{'index': 4, 'result': 1000000}
{'index': 8, 'result': 1000000}
{'index': 6, 'result': 1000000}
{'index': 9, 'result': 1000000}
{'index': 7, 'result': 1000000}
-
* Introduction - The solution shows panorama image from multi images. The panorama images is processing by real-time stitching algorithm...
-
Image size of origin is 320*240. Processing time is 30.96 second took. The result of stitching The resul...
-
In past, I wrote an articel about YUV 444, 422, 411 introduction and yuv rgb converting example code. refer to this page -> http://feel...
-
Logistic Classifier The logistic classifier is similar to equation of the plane. W is weight vector, X is input vector and y is output...
-
Created Date : 2007.8 Language : Matlab / C++(MFC) Tool : Matlab / Visual C++ 6.0 Library & Utilized : - / OpenGL Reference : ...
-
fig 1. Left: set 4 points (Left Top, Right Top, Right Bottom, Left Bottom), right:warped image to (0,0) (300,0), (300,300), (0,300) Fi...
-
The MNIST dataset is a dataset of handwritten digits, comprising 60 000 training examples and 10 000 test examples. The dataset can be downl...
-
Created Date : 2009.10. Language : C++ Tool : Visual Studio C++ 2008 Library & Utilized : Point Grey-FlyCapture, Triclops, OpenCV...
-
In the YUV color format, Y is bright information, U is blue color area, V is red color area. Show the below picture. The picture is u-v col...
-
Created Date : 2011.8 Language : Matlab Tool : Matlab 2010 Library & Utilized : - Reference : Multiple View Geometry (Hartly and Z...