Commit 7ba702f9 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Flattening samplesets; updates

parent b34f1e01
Pipeline #53317 passed with stage
in 15 minutes and 52 seconds
import random
import numpy as np
import bob.pipelines as mario
from bob.pipelines import Sample
from bob.pipelines import SampleSet
from bob.pipelines.utils import flatten_samplesets
def test_isinstance_nested():
class A:
......@@ -22,3 +30,39 @@ def test_isinstance_nested():
assert mario.utils.isinstance_nested(o, "o", C)
assert mario.utils.isinstance_nested(o, "o", B)
assert not mario.utils.isinstance_nested(o, "o", A)
def test_break_sample_set():
samplesets = []
n_samples = 10
X = np.ones(shape=(n_samples, 2), dtype=int)
random.seed(10)
# Creating a face list of samplesets
for i in range(n_samples):
samplesets.append(
SampleSet(
[
Sample(
data,
key=str(i),
sample_random_attriute="".join(
[random.choice("abcde") for _ in range(5)]
),
)
for i, data in enumerate(X)
],
key=str(i),
sampleset_random_attriute="".join(
[random.choice("abcde") for _ in range(5)]
),
)
)
# Flatting the SSET
new_samplesets = flatten_samplesets(samplesets)
assert len(new_samplesets) == n_samples * n_samples
assert np.allclose([len(s) for s in new_samplesets], np.ones(n_samples * n_samples))
import copy
import pickle
import numpy as np
from bob.pipelines import SampleSet
def is_picklable(obj):
"""Test if an object is picklable or not."""
......@@ -96,8 +96,20 @@ def hash_string(key, bucket_size=1000):
return str(sum([ord(i) for i in (key)]) % bucket_size)
def breakdown_SampleSet(sampleset)
brokendown_list = []
for sample in sampleset:
brokendown_list.append(SampleSet(sample))
return brokendown_list
\ No newline at end of file
def flatten_samplesets(samplesets):
new_samplesets = []
# Iterating over the samplesets
for sset in samplesets:
# Iterating over the samples, and deep copying each sampleset
# for each sample
for i, s in enumerate(sset):
new_sset = copy.deepcopy(sset)
new_sset.samples = [s]
# Very important step
# We need to redo the keys
new_sset.key = f"{new_sset.key}-{i}"
new_samplesets.append(new_sset)
return new_samplesets
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