Ejemplo n.º 1
0
    def setup(self, stage=None):
        super().setup(stage=stage)
        cfg = self.cfg

        if HydraConfig.initialized():
            # Current directory changed!
            # Update paths with original_cwd
            csv_path = to_absolute_path(cfg.data.csv_path)
            root_dir = to_absolute_path(cfg.data.root_dir)
        else:
            # Keep relative paths
            csv_path = cfg.data.csv_path
            root_dir = cfg.data.root_dir

        df = pd.read_csv(csv_path)
        df[["x", "y", "x1", "y1"]] = pd.DataFrame(
            np.stack(df["box"].apply(ast.literal_eval)).astype(np.float32)
        )
        train_df = df.loc[df["fold"] != cfg.data.valid_fold].copy()
        valid_df = df.loc[df["fold"] == cfg.data.valid_fold].copy()
        self.train_dataset = PennFudanDataset(
            train_df,
            root_dir=root_dir,
            transforms=self.train_transforms,
            mode="train",
        )
        self.val_dataset = PennFudanDataset(
            valid_df, root_dir=root_dir, transforms=self.val_transforms, mode="val"
        )
Ejemplo n.º 2
0
    def __init__(self, cfg: DictConfig, train_transforms=None, val_transforms=None):
        super().__init__(
            train_transforms=train_transforms,
            val_transforms=val_transforms,
            test_transforms=val_transforms,
        )

        self.train_transforms = train_transforms
        self.val_transforms = val_transforms
        self.cfg = cfg

        if HydraConfig.initialized():
            # Current directory changed!
            # Update paths with original_cwd
            self.data_csv_path = to_absolute_path(cfg.data.csv_path)
            self.root_dir = to_absolute_path(cfg.data.root_dir)
        else:
            # Keep relative paths
            self.data_csv_path = cfg.data.csv_path
            self.root_dir = cfg.data.root_dir