Skip to content

Instantly share code, notes, and snippets.

View mbsariyildiz's full-sized avatar

Mert Bulent Sariyildiz mbsariyildiz

  • NAVER LABS Europe
  • Grenoble, France
View GitHub Profile
@mbsariyildiz
mbsariyildiz / .py
Created November 18, 2017 18:46
Simple example of using tf.data.Dataset to create a data input pipeline from RAM to GPU.
import numpy as np
import tensorflow as tf
print 'tf_version: ', tf.__version__ # it is 1.4.0 right now
np.set_printoptions(linewidth=150, precision=3, suppress=True)
M = 10
d = 2
# samples
X = tf.constant(np.random.randn(M, d), 'float32')
@mbsariyildiz
mbsariyildiz / .py
Last active May 8, 2018 14:20
Iterator for list of arrays/matrices whose first dimension match
class Iterator(object):
"""
Iterator for list of tensors whose first dimension match.
"""
def __init__(self, tensors, batch_size, allow_smaller=True, shuffle=True):
self.tensors = tensors
self.batch_size = batch_size
self.allow_smaller = allow_smaller
self.shuffle = shuffle
@mbsariyildiz
mbsariyildiz / .py
Last active March 8, 2024 20:44
Pairwise Euclidean distance computation of elements in 2 tensors, in TensorFlow.
def pairwise_dist (A, B):
"""
Computes pairwise distances between each elements of A and each elements of B.
Args:
A, [m,d] matrix
B, [n,d] matrix
Returns:
D, [m,n] matrix of pairwise distances