liveBook · Manning

Caching

As explained in Deep Learning with PyTorch, Second Edition

The practice of storing preprocessed data temporarily so it can be reused efficiently later instead of recomputing it.

Caching stores expensive preprocessing results temporarily so later requests can reuse them instead of repeatedly reading and transforming raw data. For CT samples, this can make a data-loading pipeline dramatically faster. section 12.5.1 section 12.8

A practical caching setup can use several layers:

  • Keep a recently requested CT object in memory, accepting frequent misses when access order changes. section 12.5.1
  • Persist extracted candidate arrays on disk so later requests read compact float32 values rather than reload, convert, and crop the full scan. section 12.5.1
  • Cache before augmentation; otherwise, an augmented sample may be persisted and reused instead of generating fresh transformations. section 14.6.1
  • Remove stale cache files when cached function definitions materially change, or old outputs may no longer match their inputs. section 12.5.1
@functools.lru_cache(1, typed=True)
def getCt(series_uid):
  return Ct(series_uid)

@raw_cache.memoize(typed=True)
def getCtRawCandidate(series_uid, center_xyz, width_irc):
  ct = getCt(series_uid)
  ct_chunk, center_irc = ct.getRawCandidate(center_xyz, width_irc)
  return ct_chunk, center_irc

A one-entry in-memory cache retains CT objects, while a disk-backed memoized function stores extracted candidate chunks and centers for reuse. section 12.5.1

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Explains memory and disk layers, memoization, invalidation, and augmentation ordering, but defers the full rationale for the setup.
Examples
Uses cached CT objects and extracted candidate arrays, then places caching before affine image augmentation.
What it assumes
Assumes familiarity with loading raw CT data and introduces caching within that pipeline rather than requiring advanced deep-learning knowledge.
What you can do after
Operate/configure memory and disk caches around CT-loading functions while preserving correct augmentation and invalidating stale results.
How it connects
Connects caching to CT data loading, PyTorch Dataset pipelines, disk I/O, memoization, and data augmentation.

Also explained in

Compare how 38 books explain caching →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.