organoid_tracker.neural_network.image_preloading module
Image preloading, for the case where you need to sequentially load all images in an experiment.
- class organoid_tracker.neural_network.image_preloading.ImagePreloader
Bases:
ABCAbstract class for preloading images. Implementations of this class can load images in the background and keep them in memory, with a certain window of time points. This can speed up loading images when you need to load multiple time points in a row, for example when predicting positions over time.
- get_image(time_point: TimePoint) Image | None
Returns the image for the given time point, or None if there is no image for this time point. Also preloads images for future time points in the background.
The first time you call this method, you can call it with any time point. You can thereafter call it with a time point in the past (up to older_time_points_to_keep time points in the past), the same time point, or one time point in the future. In that case, the time window shifts one forward. The oldest image is unloaded, and a new image is loaded in the background.
You cannot skip time points, so you cannot call it with a time point that is more than one time point in the future compared to the then-latest requested time point.
Raises RuntimeError if you call this method before entering the context manager (before __enter__ was called).
- organoid_tracker.neural_network.image_preloading.create_image_preloader(images: Images, channel: ImageChannel, *, preload_window_size: int = 1, older_time_points_to_keep: int = 0, use_threading: bool = True) ImagePreloader
Creates an image preloader. If use_threading is True, it will load images in the background using a separate thread. If use_threading is False, it will not load images in the background, but it will still keep track of the latest requested time point and enforce the allowed time point window. (So essentially, it just makes sure your code is ready for threading.)