Download clean/video/fakestormer/datasets/df40.py from deepsafe/model-code: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/deepsafe/model-code/resolve/main/clean/video/fakestormer/datasets/df40.py
- Command line
-
hf download hf://deepsafe/model-code/clean/video/fakestormer/datasets/df40.py
-
curl -L -o df40.py https://huggingface.co/deepsafe/model-code/resolve/main/clean/video/fakestormer/datasets/df40.py
1.75 kB
| # -*- coding: utf-8 -*- | |
| import os | |
| from glob import glob | |
| import numpy as np | |
| from .builder import DATASETS | |
| from .common import CommonDataset | |
| class DF40(CommonDataset): | |
| def __init__(self, cfg, **kwargs): | |
| super().__init__(cfg, **kwargs) | |
| def _load_from_path(self, split): | |
| # Check if the root directory exists. | |
| root_dir = self._cfg.DATA[self.split.upper()].ROOT | |
| assert os.path.exists(root_dir), "Root path to dataset cannot be None!" | |
| data = self._cfg["DATA"] | |
| data_type = data.TYPE | |
| fake_types = self._cfg.DATA[split.upper()]["FAKETYPE"] | |
| img_paths, labels, mask_paths, ot_props = [], [], [], [] | |
| # Load image data for each type of fake technique. | |
| for ft in fake_types: | |
| # Construct path: ROOT/split/fake_type (skipping data_type) | |
| data_dir = os.path.join(root_dir, self.split, data_type, ft) | |
| if not os.path.exists(data_dir): | |
| raise ValueError("Data Directory is invalid!") | |
| # Define common image extensions. | |
| extensions = ["jpg", "jpeg", "png", "tif", "webp"] | |
| img_paths_ = [] | |
| # Recursively search for images in the fake type directory. | |
| for ext in extensions: | |
| pattern = os.path.join(data_dir, "**", f"*.{ext}") | |
| img_paths_.extend(glob(pattern, recursive=True)) | |
| # Extend the main lists with the images and corresponding labels. | |
| img_paths.extend(img_paths_) | |
| labels.extend(np.full(len(img_paths_), int(ft != "real_videos"))) | |
| print("{} image paths have been loaded from DF40!".format(len(img_paths))) | |
| return img_paths, labels, mask_paths, ot_props | |