ชุดเครื่องมือที่มีประโยชน์ที่ฉันใช้ตลอดรหัสของฉัน
ในการติดตั้ง:
git clone [email protected]:Shamdan17/skit.git
pip install -e .
DataSetPreloader เป็น wrapper รอบ torch.utils.data.Dataset ซึ่งแคชชุดข้อมูลไปยังดิสก์ สิ่งนี้ทำได้ในการสร้างอินสแตนซ์หรือความเกียจคร้านเมื่อมีการร้องขอแบทช์ นี่คือการหลีกเลี่ยงค่าใช้จ่ายในการโหลดจากดิสก์ทุกครั้งโดยเฉพาะอย่างยิ่งหากมีการโหลดอินสแตนซ์เดียวจากหลายไฟล์ ที่สำคัญสิ่งนี้ช่วยให้เราข้ามขั้นตอนการประมวลผลล่วงหน้าที่มีราคาแพงโดยทำเพียงครั้งเดียวเท่านั้น
คำเตือน: ปัจจุบันรองรับชุดข้อมูลที่ส่งคืน DICT หรือ TUPLE of TENSORS เท่านั้น
การใช้งาน:
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 เป็น wrapper ที่ด้านบนของ DataSetPreloader ซึ่งโหลดชุดข้อมูลทั้งหมดลงในหน่วยความจำ สิ่งนี้มีประโยชน์หากคุณมีชุดข้อมูลขนาดเล็กและต้องการหลีกเลี่ยงค่าใช้จ่ายในการโหลดจากดิสก์ทุกครั้ง มี API ที่แน่นอนเช่นเดียวกับ DataSetPreloader