diff --git a/advanced/databases/livedet-iris-2020/1.json b/advanced/databases/livedet-iris-2020/1.json new file mode 100644 index 0000000000000000000000000000000000000000..2ffbec62b458b8d849b7ed010e9f6190a3cc047b --- /dev/null +++ b/advanced/databases/livedet-iris-2020/1.json @@ -0,0 +1,26 @@ +{ + "description": "Livedet Iris 2020 test database", + "environment": { + "name": "db.examples", + "version": "I don't know" + }, + "protocols": [ + { + "name": "Main", + "sets": [ + { + "name": "test", + "outputs": { + "category": "system/integer/1", + "image": "system/array_2d_uint8/1", + "label": "system/boolean/1" + }, + "template": "iris_pad", + "view": "Test" + } + ], + "template": "iris_pad" + } + ], + "root_folder": "/somewhere" +} diff --git a/advanced/databases/livedet-iris-2020/1.py b/advanced/databases/livedet-iris-2020/1.py new file mode 100644 index 0000000000000000000000000000000000000000..43ef6307392ccca62b089b6fa268eb0dd114a600 --- /dev/null +++ b/advanced/databases/livedet-iris-2020/1.py @@ -0,0 +1,40 @@ +import os + +import numpy as np +import pandas as pd +from beat.backend.python.database import View +from PIL import Image + + +class Test(View): + def index(self, root_folder, parameters): + """Creates the data for the database indexation""" + + csv_path = os.path.join(root_folder, "test.csv") + df = pd.read_csv(csv_path) + + df["filename"] = df["filename"].apply(lambda x: os.path.join(root_folder, x)) + df = df.rename(columns={"filename": "image"}) + + # ------------- v1 random labels ----- + # remove this part for v2 release + num_files = len(df) + np.random.seed(0) + df["label"] = np.random.randint(0, 2, size=num_files, dtype=bool) + df["category"] = np.random.randint(1, 7, size=num_files, dtype=int) + # ------------------------------------ + + return list(df.itertuples(index=False)) + + def get(self, output, index): + """Returns the data for the output based on the index content""" + + obj = self.objs[index] + + if output == "image": + img = np.asarray(Image.open(obj.image)) + return {"value": img} + elif output == "label": + return {"value": bool(obj.label)} + elif output == "category": + return {"value": int(obj.category)}