Skip to content

Instantly share code, notes, and snippets.

View miracleyoo's full-sized avatar

Miracleyoo miracleyoo

  • University of California San Diego
  • San Diego, USA
  • 05:13 (UTC -07:00)
View GitHub Profile
@miracleyoo
miracleyoo / replace-bash-with-zsh-no-root.sh
Created February 2, 2023 18:12 — forked from afurculita/replace-bash-with-zsh-no-root.sh
Making zsh default shell without root access
# Create .bash_profile in your home directory and add these lines:
export SHELL=/bin/zsh
exec /bin/zsh -l
@miracleyoo
miracleyoo / video_frame_count.py
Created June 16, 2020 00:12
[Video Frame Count] #python #video
import cv2
def frame_count(video_path, manual=False):
def manual_count(handler):
frames = 0
while True:
status, frame = handler.read()
if not status:
break
frames += 1
@miracleyoo
miracleyoo / freeze_until.py
Created March 12, 2020 23:46
[Freeze Until] #python #pytorch
# freezing layers !!!
#-------------------------------------------------------------------------------
def freeze_until(net, param_name):
found_name = False
for name, params in net.named_parameters():
if name == param_name:
found_name = True
params.requires_grad = found_name
# freeze_until(net, "layer3.0.conv1.weight")
@miracleyoo
miracleyoo / generate_images_pack_matrix.py
Created March 12, 2020 19:46
[Generate the images pack tensor with the same random transform pattern] #python #pytorch
import numpy as np
import torch
def generate_images_pack_matrix(in_root, train=False):
# make a seed with numpy generator
seed = np.random.randint(2147483647)
in_root = Path(in_root)
img_paths = [i for i in list(in_root.iterdir()) if i.is_file() and not i.name.startswith(".")]
img_paths.sort(key=lambda x:int(x.stem))
@miracleyoo
miracleyoo / Serializer.py
Created March 5, 2020 16:54
[Serializer] #python
#!/usr/bin/env python3
"""
Library providing convenient classes and methods for writing data to files.
"""
import sys
import json
import pickle
try:
import yaml
@miracleyoo
miracleyoo / plot_facial_landmark.py
Created March 5, 2020 16:39
[Plot Facial Landmark] #python #plot #face #landmark
import collections
pred_type = collections.namedtuple('prediction_type', ['slice', 'color'])
pred_types = {'face': pred_type(slice(0, 17), (0.682, 0.780, 0.909, 0.5)),
'eyebrow1': pred_type(slice(17, 22), (1.0, 0.498, 0.055, 0.4)),
'eyebrow2': pred_type(slice(22, 27), (1.0, 0.498, 0.055, 0.4)),
'nose': pred_type(slice(27, 31), (0.345, 0.239, 0.443, 0.4)),
'nostril': pred_type(slice(31, 36), (0.345, 0.239, 0.443, 0.4)),
'eye1': pred_type(slice(36, 42), (0.596, 0.875, 0.541, 0.3)),
'eye2': pred_type(slice(42, 48), (0.596, 0.875, 0.541, 0.3)),
@miracleyoo
miracleyoo / Matplotlib_python_draw_2D_and_bar.py
Last active March 5, 2020 16:55
[Matplotlib_Python_Draw_2D_and_Bar] #python #matplotlib #draw
import matplotlib
matplotlib.use('Agg') # Call in python file
# %matplotlib inline # Call in Jupyter Notebook
# Draw line plot
def draw2D(X, Y, order, xname, yname, params, xlim=None, ylim=None, rcparams=None, legend_loc=0, show=False):
title = params['title']
colors = params['colors']
markers = params['markers']
@miracleyoo
miracleyoo / reload_python_module.py
Last active March 5, 2020 16:55
[Reload Python Module] #python #jn
#For Python 2.x
reload(foo)
#For Python 3.x
import importlib
import foo #import the module here, so that it can be reloaded.
importlib.reload(foo)
@miracleyoo
miracleyoo / parse_video.py
Last active March 5, 2020 16:55
[OpenCV Parse Video]#python #OpenCV #video
import cv2, os
import numpy as np
# Only opencv3 is supported!
if not (cv2.__version__).startswith('3.'):
raise ValueError('Only opencv 3. is supported!')
def crop_video(pathIn, pathOut, pos, size):
"""
@miracleyoo
miracleyoo / Android_Snackbar.java
Last active January 23, 2020 20:26
[Android Snackbar w/o View]#Java #Android #GUI
// 3 ways to start a snackbar without pass in a view.
Snackbar.make(mapFragment.getView(), "Click the pin for more options", Snackbar.LENGTH_LONG).show();
getWindow().getDecorView().getRootView();
Snackbar.make(getWindow().getDecorView().getRootView(), "Click the pin for more options", Snackbar.LENGTH_LONG).show();