Satu set alat berguna yang saya gunakan di seluruh basis kode saya.
Untuk menginstal:
git clone [email protected]:Shamdan17/skit.git
pip install -e .
DatasetPreloader adalah pembungkus di sekitar torch.utils.data.Dataset yang menyimpan dataset ke disk. Ini dilakukan pada instantiasi atau malas ketika batch diminta. Ini untuk menghindari overhead pemuatan dari disk setiap kali, terutama jika satu contoh dimuat dari beberapa file. Lebih penting lagi, ini memungkinkan kita melewatkan langkah -langkah preprocessing yang mungkin mahal dengan hanya melakukannya sekali.
PERINGATAN: Saat ini hanya mendukung kumpulan data yang mengembalikan dikt atau tuple tensor.
Penggunaan:
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 adalah pembungkus di atas DatasetPreloader yang memuat seluruh dataset ke dalam memori. Ini berguna jika Anda memiliki dataset kecil dan ingin menghindari overhead memuat dari disk setiap saat. Memiliki API yang sama persis dengan DatasetPreloader.