Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking for missing files in parallel #224

Merged
merged 2 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ install_requires =
openpyxl
pandas>1.2.0
pandas_path
pqdm
pydantic
python-dotenv
pytorch-lightning>=1.6.0
Expand Down
24 changes: 19 additions & 5 deletions zamba/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import appdirs
import ffmpeg
from loguru import logger
import numpy as np
import pandas as pd
from pydantic import BaseModel
from pydantic import DirectoryPath, FilePath, validator, root_validator
from pqdm.threads import pqdm
import torch
from tqdm import tqdm
import yaml
Expand Down Expand Up @@ -100,11 +102,23 @@ def check_files_exist_and_load(
# we can have multiple rows per file with labels so limit just to one row per file for these checks
files_df = df[["filepath"]].drop_duplicates()

# check data exists
logger.info(
f"Checking all {len(files_df):,} filepaths exist. Can take up to a minute for every couple thousand files."
)
exists = files_df["filepath"].path.exists()
# check for missing files
logger.info(f"Checking all {len(files_df):,} filepaths exist. Trying fast file checking...")

# try to check files in parallel
paths = files_df["filepath"].apply(Path)
exists = pqdm(paths, Path.exists, n_jobs=16)
exists = np.array(exists)

# if fast checking fails, fall back to slow checking
# if an I/O error is in `exists`, the array has dtype `object`
if exists.dtype != bool:
logger.info(
"Fast file checking failed. Running slower check, which can take 30 seconds per thousand files."
)
exists = files_df["filepath"].path.exists()

# select the missing files
invalid_files = files_df[~exists]

# if no files exist
Expand Down