Commit 6cdb2f73 authored by Tiago Pereira's avatar Tiago Pereira
Browse files

Fixed dtypes

parent 76b877b3
......@@ -50,7 +50,7 @@ class Base(object):
def __init__(self, data, labels,
input_shape=[None, 28, 28, 1],
input_dtype="float64",
input_dtype="float32",
batch_size=32,
seed=10,
data_augmentation=None,
......
......@@ -49,7 +49,7 @@ class Disk(Base):
def __init__(self, data, labels,
input_shape,
input_dtype="float64",
input_dtype="float32",
batch_size=1,
seed=10,
data_augmentation=None,
......
......@@ -43,7 +43,7 @@ class Memory(Base):
def __init__(self, data, labels,
input_shape,
input_dtype="float64",
input_dtype="float32",
batch_size=1,
seed=10,
data_augmentation=None,
......
......@@ -47,7 +47,7 @@ class SiameseDisk(Siamese, Disk):
"""
def __init__(self, data, labels,
input_shape,
input_dtype="float64",
input_dtype="float32",
batch_size=1,
seed=10,
data_augmentation=None,
......@@ -86,9 +86,9 @@ class SiameseDisk(Siamese, Disk):
"""
shape = [self.batch_size] + list(self.input_shape[1:])
sample_l = numpy.zeros(shape=shape, dtype='float32')
sample_r = numpy.zeros(shape=shape, dtype='float32')
labels_siamese = numpy.zeros(shape=shape[0], dtype='float32')
sample_l = numpy.zeros(shape=shape, dtype=self.input_dtype)
sample_r = numpy.zeros(shape=shape, dtype=self.input_dtype)
labels_siamese = numpy.zeros(shape=shape[0], dtype=self.input_dtype)
genuine = True
for i in range(shape[0]):
......
......@@ -79,9 +79,9 @@ class SiameseMemory(Siamese, Memory):
shape = [self.batch_size] + list(self.input_shape[1:])
sample_l = numpy.zeros(shape=shape, dtype='float32')
sample_r = numpy.zeros(shape=shape, dtype='float32')
labels_siamese = numpy.zeros(shape=shape[0], dtype='float32')
sample_l = numpy.zeros(shape=shape, dtype=self.input_dtype)
sample_r = numpy.zeros(shape=shape, dtype=self.input_dtype)
labels_siamese = numpy.zeros(shape=shape[0], dtype=self.input_dtype)
genuine = True
for i in range(shape[0]):
......@@ -104,4 +104,4 @@ class SiameseMemory(Siamese, Memory):
sample_l = self.normalize_sample(sample_l)
sample_r = self.normalize_sample(sample_r)
return [sample_l.astype("float32"), sample_r.astype("float32"), labels_siamese]
return [sample_l.astype(self.input_dtype), sample_r.astype(self.input_dtype), labels_siamese]
......@@ -52,7 +52,7 @@ class TripletDisk(Triplet, Disk):
def __init__(self, data, labels,
input_shape,
input_dtype="float64",
input_dtype="float32",
batch_size=1,
seed=10,
data_augmentation=None,
......@@ -91,9 +91,9 @@ class TripletDisk(Triplet, Disk):
shape = [self.batch_size] + list(self.input_shape[1:])
sample_a = numpy.zeros(shape=shape, dtype='float32')
sample_p = numpy.zeros(shape=shape, dtype='float32')
sample_n = numpy.zeros(shape=shape, dtype='float32')
sample_a = numpy.zeros(shape=shape, dtype=self.input_dtype)
sample_p = numpy.zeros(shape=shape, dtype=self.input_dtype)
sample_n = numpy.zeros(shape=shape, dtype=self.input_dtype)
for i in range(shape[0]):
file_name_a, file_name_p, file_name_n = self.get_one_triplet(self.data, self.labels)
......
......@@ -79,9 +79,9 @@ class TripletMemory(Triplet, Memory):
shape = [self.batch_size] + list(self.input_shape[1:])
sample_a = numpy.zeros(shape=shape, dtype='float32')
sample_p = numpy.zeros(shape=shape, dtype='float32')
sample_n = numpy.zeros(shape=shape, dtype='float32')
sample_a = numpy.zeros(shape=shape, dtype=self.input_dtype)
sample_p = numpy.zeros(shape=shape, dtype=self.input_dtype)
sample_n = numpy.zeros(shape=shape, dtype=self.input_dtype)
for i in range(shape[0]):
sample_a[i, ...], sample_p[i, ...], sample_n[i, ...] = self.get_one_triplet(self.data, self.labels)
......@@ -103,4 +103,4 @@ class TripletMemory(Triplet, Memory):
sample_p = self.normalize_sample(sample_p)
sample_n = self.normalize_sample(sample_n)
return [sample_a.astype("float32"), sample_p.astype("float32"), sample_n.astype("float32")]
return [sample_a.astype(self.input_dtype), sample_p.astype(self.input_dtype), sample_n.astype(self.input_dtype)]
......@@ -62,7 +62,7 @@ class TripletWithFastSelectionDisk(Triplet, Disk, OnlineSampling):
def __init__(self, data, labels,
input_shape,
input_dtype="float64",
input_dtype="float32",
batch_size=1,
seed=10,
data_augmentation=None,
......@@ -101,9 +101,9 @@ class TripletWithFastSelectionDisk(Triplet, Disk, OnlineSampling):
shape = [self.batch_size] + list(self.input_shape[1:])
sample_a = numpy.zeros(shape=shape, dtype='float32')
sample_p = numpy.zeros(shape=shape, dtype='float32')
sample_n = numpy.zeros(shape=shape, dtype='float32')
sample_a = numpy.zeros(shape=shape, dtype=self.input_dtype)
sample_p = numpy.zeros(shape=shape, dtype=self.input_dtype)
sample_n = numpy.zeros(shape=shape, dtype=self.input_dtype)
for i in range(shape[0]):
file_name_a, file_name_p, file_name_n = self.get_one_triplet(self.data, self.labels)
......@@ -133,10 +133,10 @@ class TripletWithFastSelectionDisk(Triplet, Disk, OnlineSampling):
anchor_labels = numpy.ones(samples_per_identity) * self.possible_labels[indexes[0]]
for i in range(1, self.total_identities):
anchor_labels = numpy.hstack((anchor_labels,numpy.ones(samples_per_identity) * self.possible_labels[indexes[i]]))
anchor_labels = numpy.hstack((anchor_labels, numpy.ones(samples_per_identity) * self.possible_labels[indexes[i]]))
anchor_labels = anchor_labels[0:self.batch_size]
samples_a = numpy.zeros(shape=self.shape, dtype='float32')
samples_a = numpy.zeros(shape=self.shape, dtype=self.input_dtype)
# Computing the embedding
for i in range(self.shape[0]):
......@@ -169,7 +169,7 @@ class TripletWithFastSelectionDisk(Triplet, Disk, OnlineSampling):
"""
Get the a random set of positive pairs
"""
samples_p = numpy.zeros(shape=self.shape, dtype='float32')
samples_p = numpy.zeros(shape=self.shape, dtype=self.input_dtype)
for i in range(self.shape[0]):
l = anchor_labels[i]
indexes = numpy.where(self.labels == l)[0]
......@@ -202,8 +202,8 @@ class TripletWithFastSelectionDisk(Triplet, Disk, OnlineSampling):
# Loading samples for the semi-hard search
shape = tuple([len(indexes)] + list(self.shape[1:]))
temp_samples_n = numpy.zeros(shape=shape, dtype='float32')
samples_n = numpy.zeros(shape=self.shape, dtype='float32')
temp_samples_n = numpy.zeros(shape=shape, dtype=self.input_dtype)
samples_n = numpy.zeros(shape=self.shape, dtype=self.input_dtype)
for i in range(shape[0]):
file_name = self.data[indexes[i], ...]
temp_samples_n[i, ...] = self.normalize_sample(self.load_from_file(str(file_name)))
......
......@@ -52,7 +52,7 @@ class TripletWithSelectionDisk(Triplet, Disk, OnlineSampling):
def __init__(self, data, labels,
input_shape,
input_dtype="float64",
input_dtype="float32",
batch_size=1,
seed=10,
data_augmentation=None,
......@@ -88,9 +88,9 @@ class TripletWithSelectionDisk(Triplet, Disk, OnlineSampling):
shape = [self.batch_size] + list(self.input_shape[1:])
sample_a = numpy.zeros(shape=shape, dtype='float32')
sample_p = numpy.zeros(shape=shape, dtype='float32')
sample_n = numpy.zeros(shape=shape, dtype='float32')
sample_a = numpy.zeros(shape=shape, dtype=self.input_dtype)
sample_p = numpy.zeros(shape=shape, dtype=self.input_dtype)
sample_n = numpy.zeros(shape=shape, dtype=self.input_dtype)
for i in range(shape[0]):
file_name_a, file_name_p, file_name_n = self.get_one_triplet(self.data, self.labels)
......@@ -123,9 +123,9 @@ class TripletWithSelectionDisk(Triplet, Disk, OnlineSampling):
anchor_labels = numpy.hstack((anchor_labels,numpy.ones(samples_per_identity) * self.possible_labels[indexes[i]]))
anchor_labels = anchor_labels[0:self.batch_size]
data_a = numpy.zeros(shape=self.shape, dtype='float32')
data_p = numpy.zeros(shape=self.shape, dtype='float32')
data_n = numpy.zeros(shape=self.shape, dtype='float32')
data_a = numpy.zeros(shape=self.shape, dtype=self.input_dtype)
data_p = numpy.zeros(shape=self.shape, dtype=self.input_dtype)
data_n = numpy.zeros(shape=self.shape, dtype=self.input_dtype)
#logger.info("Fetching anchor")
# Fetching the anchors
......@@ -185,7 +185,7 @@ class TripletWithSelectionDisk(Triplet, Disk, OnlineSampling):
0:self.batch_size] # Limiting to the batch size, otherwise the number of comparisons will explode
distances = []
shape = tuple([len(indexes)] + list(self.shape[1:]))
sample_p = numpy.zeros(shape=shape, dtype='float32')
sample_p = numpy.zeros(shape=shape, dtype=self.input_dtype)
for i in range(shape[0]):
file_name = self.data[indexes[i], ...]
......@@ -215,7 +215,7 @@ class TripletWithSelectionDisk(Triplet, Disk, OnlineSampling):
0:self.batch_size*3] # Limiting to the batch size, otherwise the number of comparisons will explode
shape = tuple([len(indexes)] + list(self.shape[1:]))
sample_n = numpy.zeros(shape=shape, dtype='float32')
sample_n = numpy.zeros(shape=shape, dtype=self.input_dtype)
for i in range(shape[0]):
file_name = self.data[indexes[i], ...]
sample_n[i, ...] = self.normalize_sample(self.load_from_file(str(file_name)))
......
......@@ -63,7 +63,7 @@ class TripletWithSelectionMemory(Triplet, Memory, OnlineSampling):
def __init__(self, data, labels,
input_shape,
input_dtype="float64",
input_dtype="float32",
batch_size=1,
seed=10,
data_augmentation=None,
......@@ -110,7 +110,7 @@ class TripletWithSelectionMemory(Triplet, Memory, OnlineSampling):
anchor_labels = numpy.hstack((anchor_labels,numpy.ones(samples_per_identity) * self.possible_labels[indexes[i]]))
anchor_labels = anchor_labels[0:self.batch_size]
samples_a = numpy.zeros(shape=shape, dtype='float32')
samples_a = numpy.zeros(shape=shape, dtype=self.input_dtype)
# Computing the embedding
for i in range(shape[0]):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment