Eine Reihe nützlicher Tools, die ich in meinen Codebasen verwende.
Zu installieren:
git clone [email protected]:Shamdan17/skit.git
pip install -e .
DataSeTPreloader ist ein Wrapper um torch.utils.data.Dataset . Dies geschieht entweder bei der Instanziierung oder träge, wenn eine Charge angefordert wird. Dies soll jedes Mal den Laden des Ladens von der Festplatte vermeiden, insbesondere wenn eine einzelne Instanz aus mehreren Dateien geladen wird. Noch wichtiger ist, dass wir möglicherweise teure Vorverarbeitungsschritte überspringen, indem wir dies nur einmal ausführen.
WARNUNG: Derzeit unterstützt nur Datensätze, die ein Diktat oder ein Tupel von Tensoren zurückgeben.
Verwendung:
from skit . data import DatasetPreloader
dataset = myTorchDataset ()
cache_path = 'path/to/cache'
# Wrap the dataset
dataset = DatasetPreloader (
dataset ,
cache_path = cache_path ,
wipe_cache = False , # If the cache exists, use it. Otherwise, create it. If true, delete the cache if it exists.
lazy_loading = True , # Load the entire dataset into memory on instantiation or lazily when a batch is requested
compress = True , # Compress the cache. This can save a lot of disk space. However, it can be slower to load.
block_size = 2000 , # The number of samples to store in a single folder. This is to avoid having too many files in a single directory, which can cause performance issues. Set to 0 to disable.
preloading_workers = 10 , # The number of workers to use when preloading the dataset. Does not affect lazy loading.
samples_to_confirm_cache = 100 # The number of samples to check when confirming the cache. If your dataset has many instances, increase the number of samples to confirm the cache. Please note this process is only a heuristic and is not 100% accurate. If in doubt, wipe the cache.
)
# Access the dataset as normalInmemoryDatasetPreloader ist ein Wrapper auf DataSeTPreloader, der den gesamten Datensatz in den Speicher lädt. Dies ist nützlich, wenn Sie einen kleinen Datensatz haben und den Aufwand des Ladens von Scheiben jedes Mal vermeiden möchten. Hat genau die gleiche API wie DataSetPreloader.