Skip to content

Instantly share code, notes, and snippets.

View iandewancker's full-sized avatar

Ian Dewancker iandewancker

View GitHub Profile
# NOTE : run within DATASET folder
# project 2D mask, 3D bounding box, and vertices from the mesh into the dataset
import glob
import json
import os
import cv2
import matplotlib.pyplot as plt
import numpy as np
# NOTE : run within DATASET folder
# project 2D mask, 3D bounding box, and vertices from the mesh into the dataset
import glob
import json
import os
import cv2
import matplotlib.pyplot as plt
import numpy as np
import glob
import skimage
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import glob
import matplotlib.pyplot as plt
import numpy as np
@iandewancker
iandewancker / gist:82305053ad8924ce97df27c438face8d
Created March 18, 2019 21:32
Interactive biz using Bokeh
def generate_interactive_plot(y_pred, y_true, gids, img_pattern):
colors=["red", "gold", "limegreen"]
projected_points = projectSimplex(y_pred)
labels = ['0', '1', '2+']
from bokeh.plotting import figure, output_file, show, ColumnDataSource
from bokeh.models import HoverTool
URLs = []
web_colors = []
import glob
images = glob.glob("*.jpg")
import re
import os
import matplotlib.pyplot as plt
import numpy as np
import cv2
from PIL import Image
import glob
import skimage
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import glob
import matplotlib.pyplot as plt
import numpy as np
import glob
images = glob.glob("*.jpg")
import re
import os
import matplotlib.pyplot as plt
def natural_sort(l):
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
return sorted(l, key = alphanum_key)
@iandewancker
iandewancker / gist:1231df22575771d8d709f00f78cb71a8
Created March 4, 2019 17:57
Fit and plot max likelihood Beta distribution to data
import scipy.stats
import numpy as np
import scipy.optimize
obs_data = [
0.08982035928143713
,0.06818181818181818
,0.012987012987012988
,0.05357142857142857
,0.045454545454545456
@iandewancker
iandewancker / gist:840748d4f9e2ff80c1dbcd57719d6bd3
Created August 23, 2018 14:24
custom weighted categorical loss for keras
def custom_cat_crossentropy(y_true, y_pred):
# negate 3x3 sub matrix of income matrix to get cost matrix
# check https://github.com/tensorflow/tensorflow/blob/r1.10/tensorflow/python/keras/backend.py#L3461
cost_m = tf.constant([[ 0.00222222, 0.01111111, 0.00222222],
[ 0.00222222, -0.05888889, 0.00222222],
[ 0.00222222, 1.51111111, 0.00222222]])
y_true = tf.matmul(y_true, cost_m)
return tf.keras.losses.categorical_crossentropy(y_true, y_pred)
@iandewancker
iandewancker / gist:0206cc059472e0839a4af5ee40d1a370
Created August 16, 2018 14:44
Convert keras model to pb file
# load keras model from disk
model_name = "GVC_IncepvtionV3_epoch_6_vanilla_vgg_chute_date_2018_07_27"
json_file = open(model_name+'.json', 'r')
model_json = json_file.read()
json_file.close()
model = tensorflow.keras.models.model_from_json(model_json)
# load weights into new model
model.load_weights(model_name+".h5")
print("Loaded model from disk")