Skip to content

Instantly share code, notes, and snippets.

View jeremy-rutman's full-sized avatar

jeremy rutman jeremy-rutman

View GitHub Profile
@jeremy-rutman
jeremy-rutman / yolo_v3_notes.txt
Last active January 30, 2020 10:50
setting .cfg for yolov3
https://pjreddie.com/darknet/yolo/
https://gist.github.com/jeremy-rutman/74c03f4c9a15492227ca22164890d68a
https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects
also see https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects for opencv reading yolo dnn
1. make train.txt with paths to training jpgs
2. label files either in parallel dir or same dir (not sure ))
3. edit cfg/voc.data (locations of train/test files, class names etc)
4. set to train vs test in .cfg
5. n_filters in last conv. layer =
@jeremy-rutman
jeremy-rutman / filter_by_condition.py
Created December 6, 2019 14:05
change a column based on other column values, possibly using other column values as result
import pandas as pd
df = pd.read_excel('soxl.xlsx')
df=df[df['IDs of phase known'].notnull() | df['Ids of distance known'].notnull()]
#If you wanted to remove any row with any missing data you can use the builtin :
df = df.dropna()
#which removes any row with missing values (which otherwise get imported as Nan values).
@jeremy-rutman
jeremy-rutman / mask_bbox.py
Created December 5, 2019 10:05
find outermost points of mask
import cv2
import numpy as np
img_arr1 = cv2.imread('test.png')
img_arr = cv2.cvtColor(img_arr1,cv2.COLOR_BGR2GRAY)
ret,mask = cv2.threshold(img_arr,100,200,cv2.THRESH_BINARY)
H,W = mask.shape
left_edges = np.where(mask.any(axis=1),mask.argmax(axis=1),W+1)
flip_lr = cv2.flip(thresh,1) #1 horz vert 0
right_edges = W-np.where(flip_lr.any(axis=1),flip_lr.argmax(axis=1),W+1)
top_edges = np.where(thresh.any(axis=0),thresh.argmax(axis=0),H+1)
@jeremy-rutman
jeremy-rutman / frames_to_vid.py
Created December 2, 2019 21:57
convert sreies of images to video
import cv2
#MJPG , DIVX , and H264
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (W, H))
for img_arr in img_arr_list:
out.write(img_arr)
@jeremy-rutman
jeremy-rutman / regex_matchgroups.py
Created December 2, 2019 18:07
simple example of using named match groups in regex
def get_domain_from_email(email):
pattern = r'(?P<name>\w*)@(?P<subdomain>\w*)\.(?P<domain>\w*)'
match_found = match(pattern, email, flags=IGNORECASE)
print(match_found.group('name'))
print(match_found.group('subdomain'))
print(match_found.group('domain'))
get_domain_from_email('joe_shlabotnik@purple.com')
@jeremy-rutman
jeremy-rutman / startup_script_locations.txt
Last active November 26, 2019 08:27
where to put startup scripts
/etc/profile - scripts here will run for every new shell/terminal opened
/etc/rc.local - scripts here will run on startup
ffmpeg -loop 1 -i pic.png -i whoosh.wav -c:a aac -ab 112k -c:v libx264 -shortest -strict -2 whoosh.mp4
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf request_fax.pdf aia0067.pdf
pdfunite request_fax.pdf aia0067.pdf combined.pdf
@jeremy-rutman
jeremy-rutman / get_short_git_hash.py
Created October 28, 2019 10:18
get the short git hash of current repo
import git
repo = git.Repo(search_parent_directories=True)
sha = repo.head.object.hexsha
short_sha = repo.git.rev_parse(sha, short=1)
@jeremy-rutman
jeremy-rutman / read_csv_multiformat.py
Created October 9, 2019 10:37
pandas read csv of multiple formats
# Uses chardet if encoding is not specified, reading the first kB to determine encoding.
# This obviates the unfortunate situation wherein reading a utf-16 as utf-8 does not generally throw an error,
# but will munge up the data.
import chardet
import pandas as pd
def read_csv_multiformat(f,**kwargs):
if not 'encoding' in kwargs:
with open(f, 'rb') as fp: