TorchLean API

NN.Examples.Models.Common.RealData

Shared Real-Data Helpers for Model Examples #

The model examples should exercise real data paths. We keep the shared pieces here:

The data files are prepared by scripts/datasets/download_example_data.py; examples report missing inputs explicitly instead of silently falling back to synthetic tensors.

Number of channels in the prepared CIFAR-10 image tensors.

Instances For

    Height of the prepared CIFAR-10 image tensors.

    Instances For

      Width of the prepared CIFAR-10 image tensors.

      Instances For

        Number of CIFAR-10 classes, hence the width of one-hot targets.

        Instances For

          Default row budget for CIFAR-10 model example commands.

          Instances For

            Number of channels in converted ImageNet-style image tensors.

            Instances For

              Height of converted ImageNet-style image tensors.

              Instances For

                Width of converted ImageNet-style image tensors.

                Instances For

                  Number of ImageNet-style classes expected by the converted label path.

                  Instances For

                    Default row budget for ImageNet64 model example runs.

                    Instances For
                      @[reducible, inline]

                      Shape of one CIFAR-10 image after conversion to channel-first layout.

                      Instances For
                        @[reducible, inline]

                        One-hot CIFAR-10 target shape.

                        Instances For
                          def NN.Examples.Models.RealData.Internal.cropCifarImages (batchSize cropHeight cropWidth : ℕ) (heightFits : cropHeight ≤ cifarHeight) (widthFits : cropWidth ≤ cifarWidth) (x : TorchLean.Tensor Float [batchSize, cifarChannels, cifarHeight, cifarWidth]) :
                          TorchLean.Tensor Float [batchSize, cifarChannels, cropHeight, cropWidth]

                          Take the top-left cropHeight × cropWidth view of a CIFAR image batch.

                          Instances For

                            Take the top-left cropHeight × cropWidth view of a CIFAR image batch.

                            Invalid crop sizes are reported at the executable boundary.

                            Instances For
                              def NN.Examples.Models.RealData.cropCifarBatch (batchSize cropHeight cropWidth : ℕ) (sample : TorchLean.Sample.Batch Float batchSize CifarImage CifarTarget) :

                              Crop a CIFAR minibatch while leaving the one-hot class labels unchanged.

                              Instances For
                                @[reducible, inline]

                                ImageNet-style converted image shape used by the higher-resolution diffusion example.

                                Instances For
                                  @[reducible, inline]

                                  One-hot target shape for ImageNet-style folders.

                                  The diffusion example ignores labels, but reusing Data.LabeledSource keeps the data path identical to the supervised examples and lets class-directory conversion catch malformed labels early.

                                  Instances For

                                    Error message shown when a CIFAR-backed example cannot find the prepared arrays.

                                    Instances For

                                      Error message shown when an ImageNet64-backed example cannot find the prepared arrays.

                                      Instances For

                                        Error message shown when a text-model example cannot find a corpus.

                                        Instances For

                                          Error message shown when the Auto MPG CSV is missing.

                                          Instances For

                                            Error message shown when the household-power forecasting dataset is missing.

                                            Instances For

                                              Parse the shared NPY data flags with CIFAR-10's default paths and row count filled in.

                                              Instances For

                                                Parse the shared flags for an ImageNet-style 64x64 NPY dataset.

                                                The expected input is produced by scripts/datasets/torchlean_data_convert.py image-folder; that converter handles JPEG/PNG decoding, RGB conversion, resizing, class-directory labels, and the final NCHW layout. Lean then reads only the simple .npy tensors.

                                                Instances For
                                                  def NN.Examples.Models.RealData.Forecast.Options.parse (exeName : String) (args : List String) (defaultWindows : ℕ := 512) (defaultReportOffset : ℕ := 96) :

                                                  Parse the shared flags for household-power forecasting windows.

                                                  Forecasting commands share --data-dir, --x, --y, --windows, and --report-offset.

                                                  Instances For
                                                    def NN.Examples.Models.RealData.Internal.loadImageLoader (imageShape : Spec.Shape) (classes : ℕ) (datasetName missingHint recoveryHint exeName : String) (batchSize rowCount seed : ℕ) (xPath yPath : System.FilePath) :
                                                    IO (TorchLean.Data.Loader Float batchSize imageShape [classes])

                                                    Load prepared labeled images with dataset-specific preparation and recovery hints.

                                                    Instances For
                                                      def NN.Examples.Models.RealData.loadCifarLoader (exeName : String) (batchSize rowCount seed : ℕ) (xPath yPath : System.FilePath) :

                                                      Build a batched CIFAR-10 loader from the image and label .npy files.

                                                      Both files are required up front, with a hint pointing at the converter script, so a missing dataset fails with something actionable rather than a decode error halfway through the first epoch.

                                                      Instances For

                                                        Dataset and optimizer metadata for training on prepared NPY tensors.

                                                        Instances For
                                                          def NN.Examples.Models.RealData.loadCifarBatches (exeName : String) (batchSize rowCount seed : ℕ) (xPath yPath : System.FilePath) :

                                                          Load one shuffled epoch of full CIFAR-10 minibatches from prepared .npy arrays.

                                                          Instances For
                                                            def NN.Examples.Models.RealData.trainCifarClassifier (batchSize cropHeight cropWidth : ℕ) (exeName logTitle : String) (model : TorchLean.nn.Builder (TorchLean.nn.Sequential [batchSize, cifarChannels, cropHeight, cropWidth] [batchSize, cifarClasses])) (runtime : TorchLean.Runtime.Config) (flags : Support.Training.Options Support.Npy.Options) (extraNotes : Array String := #[]) :

                                                            Train a cropped CIFAR classifier with the examples' shared Adam and cross-entropy policy.

                                                            Instances For
                                                              def NN.Examples.Models.RealData.loadCifarBatch (exeName : String) (batchSize rowCount seed : ℕ) (xPath yPath : System.FilePath) :

                                                              Load the first full CIFAR-10 minibatch from the shared CIFAR loader.

                                                              Instances For

                                                                Load a user-prepared ImageNet-style 64x64 minibatch.

                                                                This loader reads prepared .npy arrays rather than JPEG files. The Python converter is the trust boundary for filesystem image decoding and resizing; this Lean path checks the resulting tensor shape and class range before handing the batch to examples.

                                                                Instances For

                                                                  Load one shuffled epoch of full ImageNet64-style minibatches from prepared .npy arrays.

                                                                  Instances For
                                                                    def NN.Examples.Models.RealData.loadCifarFeatureBatch (batchSize : ℕ) (config : TorchLean.nn.models.Generative.Config) (exeName : String) (xPath yPath : System.FilePath) (rowCount seed : ℕ) :
                                                                    IO (TorchLean.Tensor Float (config.dataShape [batchSize]))

                                                                    Load a CIFAR minibatch, flatten each channel-first image, and retain its first config.dataWidth values. This is a prefix of the image buffer, not a spatial resize or learned feature extraction. Widths larger than the full image are rejected.

                                                                    Instances For
                                                                      def NN.Examples.Models.RealData.cifarFeatureDataset {τ : Spec.Shape} (batchSize : ℕ) (config : TorchLean.nn.models.Generative.Config) (exeName : String) (sampleOfFeatures : TorchLean.Tensor Float (config.dataShape [batchSize]) → TorchLean.Sample.Supervised Float (config.dataShape [batchSize]) τ) (xPath yPath : System.FilePath) (rowCount seed : ℕ) :

                                                                      Public singleton dataset for compact vector generative examples over flattened CIFAR batches.

                                                                      Autoencoder and supervised latent-bottleneck examples load one real CIFAR batch, flatten it to the compact vector boundary, build one supervised sample, and hand that sample to the public trainer API. The sample itself may be Float-specific; this dataset constructor casts it into the runtime-selected arithmetic representation so the command still works across the ordinary public runtime backends.

                                                                      Instances For

                                                                        Command-line options shared by local text-corpus examples.

                                                                        Instances For

                                                                          Parse the shared --data-file flag used by local text-model examples.

                                                                          --tiny-shakespeare is accepted as an explicit shortcut for the default corpus path.

                                                                          Instances For

                                                                            Read the selected text corpus and fail with a shared preparation hint when it is missing.

                                                                            Instances For

                                                                              Text corpus selection plus the number of causal training windows to expose.

                                                                              • Selected UTF-8 corpus.

                                                                              • windows : ℕ

                                                                                Number of approximately evenly spaced windows in the finite training dataset.

                                                                              Instances For

                                                                                Command-line options shared by finite-window text examples.

                                                                                Instances For

                                                                                  Parse a text corpus and a positive --windows count.

                                                                                  Instances For

                                                                                    Read the selected text corpus.

                                                                                    Instances For