Skip to content
Snippets Groups Projects
Select Git revision
  • 4d28ad16234b8293eaab7bbf59340cd1c13976be
  • master default protected
  • fix_macos_arm_build
  • 74-parameter-schemas
  • interactive
  • 76-cleanup-schemas
  • test-74-parameter-schemas
  • run_arguments
  • v1.13.5
  • v1.13.4
  • v1.13.3
  • v1.13.2
  • v1.13.1
  • v1.13.0
  • v1.12.0
  • v1.11.1
  • v1.11.0
  • v1.10.7
  • v1.10.6
  • v1.10.5
  • v1.10.4
  • v1.10.3
  • v1.10.2
  • v1.10.1
  • v1.10.0
  • v1.9.2
  • v1.9.1
  • v1.9.0
28 results

bootstrap-buildout.py

Blame
  • 1.py 1.27 KiB
    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": np.cast["int32"](obj.category)}