Skip to content

Instantly share code, notes, and snippets.

View jeremy-rutman's full-sized avatar

jeremy rutman jeremy-rutman

View GitHub Profile
This file has been truncated, but you can view the full file.
<html class="theme theme--mercado artdeco" lang="en"><head>
<script async="" src="https://platform.linkedin.com/js/analytics.js"></script><script type="application/javascript">!function(i,n){void 0!==i.addEventListener&&void 0!==i.hidden&&(n.liVisibilityChangeListener=function(){i.hidden&&(n.liHasWindowHidden=!0)},i.addEventListener("visibilitychange",n.liVisibilityChangeListener))}(document,window);</script>
<title>(7) Assaf Govari, Ph.D. | LinkedIn</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="asset-url" class="mercado-icons-sprite" id="artdeco-icons/static/images/sprite-asset" content="https://static-exp1.licdn.com/sc/h/brlx1tn7p1njjhu3u6kjxqodw">
<meta name="description" content="">
<meta name="google" content="notranslate">
@jeremy-rutman
jeremy-rutman / venn_diagram_with_three_circles
Last active February 14, 2021 10:34
venn diagram with three circles showing overlap order
from matplotlib_venn import venn2, venn3
import matplotlib.pyplot as plt
# venn2 subsets are a b ab (where a is n_unique_to_a, ab is intersection of a,b)
# called by venn2(subsets = (a_name,b_name,intersection_name), set_labels = (pair[0], pair[1],'both'), alpha = 0.5)
# venn3 subsets are a b ab c ca cb abc
# called by venn3(subsets = (a,b,ab,c,ca,cb,n),
# set_labels = (a_name,b_name,c_name), alpha = 0.5)
@jeremy-rutman
jeremy-rutman / pdf_color_to_gray.sh
Last active November 3, 2020 19:46
convert color pdf to grayscale
jeremy@jeremy-Blade:$ gs \
-sOutputFile=output.pdf \
-sDEVICE=pdfwrite \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
-dCompatibilityLevel=1.4 \
-dNOPAUSE \
-dBATCH \
input.pdf
Some notes on torchtext
you can read a csv and generate vocab like this
tokenize = lambda x: str(x).split() # see if this fixes float vs. string error
TEXT = data.Field(sequential=True, tokenize=tokenize, lower=True, include_lengths=True, batch_first=True,
fix_length=200)
LABEL = data.LabelField() # LABEL = data.LabelField(tensor_type=torch.FloatTensor)
fields = {'textcol': ('text', TEXT), 'real': ('label',LABEL)}
# selecting all cols except one
df = pd.DataFrame({'a':[1,2,3,4],'b':[1,2,3,4]})
df2 = df.loc[:,df.columns!='b']
print(df)
print(df2)
# split df into train, val, test with val from 0.9 to 0.95 and test from 0.95 to 1.0 of randomized data
train, validate, test = np.split(df.sample(frac=1), [int(.9*len(df)), int(.95*len(df))])
# FILTERING
# attempt at 'batch-known' learning , where positive/negative is known per batch and not per example
# in this attempt, examples are positive if there are five or more ones in the input vector which is itself six random binary digits.
# not only is this underlying truth (y=(sum(x)>=5)) hidden from the loss function , the loss func will only know per batch if there was at
# least one true example in the batch (a 'positive batch'), or none (a 'negative batch')
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import torch
tl;dr
use the package manager install (.deb or .rpm files, not .run file)
remove stuff using
sudo apt-get --purge remove 'cuda*'
sudo apt-get --purge -y remove 'nvidia*'
sudo apt-get --purge -y remove 'libnvidia*'
using
@jeremy-rutman
jeremy-rutman / geyser_gazer.py
Last active January 8, 2020 15:54
geyser data analysis
# code for https://unclejerry9466728.wordpress.com/2019/12/28/wiser-geyser/
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import torch
import numpy as np
import pandas as pd
@jeremy-rutman
jeremy-rutman / image_warp.py
Last active December 19, 2019 12:58
warp image arbitrarily (nonlinear)
import numpy as np
import cv2
def remap_test(img_arr):
H,W = img_arr.shape[0:2]
map = np.mgrid[0:H,0:W] # the map doesnt have to be same dims. as image size; it just declares what pixels in input image map to given output pixel
map_x = map[1].astype(np.float32)
map_y = map[0].astype(np.float32)
#linear warp
# for i in range(H):
@jeremy-rutman
jeremy-rutman / change_LUT.py
Created December 10, 2019 08:26
from 2d values to RGB
import cv2
import numpy as np
def get_rgb(two_d_pixels):
theta = np.arctan(two_d_pixels[1,:] / two_d_pixels[0,:])
r = np.sqrt(two_d_pixels[1,:]**2 + two_d_pixels[0,:]**2)
hue = (theta+3.14/2) * 128./(3.14) # 127 max for hue
sat = (r/np.sqrt(2)) * 255 #255 max for sat
H,W = two_d_pixels.shape[1:3]
retval = np.zeros([H,W,3],dtype = np.uint8)
retval[:,:,0] = hue