This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def crop(image, mask, min_size= 128): | |
# Determine New Size on Y axis | |
max_size_y = image.shape[0] | |
mask_y = np.where(np.sum(mask, axis=1)) | |
min_size_y = np.max(mask_y) - np.min(mask_y) | |
new_size_y = np.random.rand() * (max_size_y - min_size_y) | |
new_size_y = np.maximum(new_size_y, min_size).astype('uint16') | |
# Determine New Size on X axis | |
max_size_x = image.shape[1] | |
mask_x = np.where(np.sum(mask, axis=0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def triplet_loss(_, y_pred, triplet_margin=1): | |
''' | |
Assume: y_pred shape is (batch_size, 2) | |
Example for how to construct such a corresponding triplet network: | |
def euclidean_distance(vects): | |
x, y = vects | |
return K.sqrt(K.maximum(K.sum(K.square(x - y), axis=1, keepdims=True), K.epsilon())) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tensorflow as tf | |
sess = tf.Session() | |
from keras import backend as K | |
K.set_session(sess) | |
from keras.objectives import mean_squared_error | |
from keras.layers import Dense | |
def load_dummy_data(n = 1000): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
class VolumeViz: | |
def __init__(self, fig, volume): | |
self.volume = volume | |
self.figure = fig | |
self.ax1 = fig.add_subplot(121) | |
self.ax2 = fig.add_subplot(122) | |
self.ax1.set_title('click') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from volume_viz import VolumeViz | |
class CostVolumeViz: | |
def __init__(self, left, right, disparity): | |
self.left = left | |
self.right = right | |
self.disparity = self.StandardizeDisparity(disparity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def l2_distance_matrix(x, exact=True): | |
""" | |
Calculate an L2 distance matrix from embedding vectors) | |
:param | |
x: embedding tensor size (batch_size, embedding_length) | |
exact: if False, skip the final sqrt | |
:return: l2 distance matrix tensor tensor size (batch_size, batch_size) | |
""" | |
r = K.sum(x*x, 1) | |
r = K.reshape(r, [-1, 1]) # turn r into column vector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.stats import skew | |
def k_occurrences(nbrs_indices): | |
""" | |
Calculate k-occurrences distribution | |
Miloš Radovanovi´c et al, | |
Hubs in space: Popular nearest neighbors in high-dimensional data. | |
Journal of Machine Learning Research, 11(Sep):2487–2531, 2010 |