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
                                                  @[reducible, inline]

                                                  Parsed CIFAR dataset and fixed-sample training flags for runnable model examples.

                                                  Instances For
                                                    @[reducible, inline]

                                                    Parsed CIFAR dataset and optimizer/training flags for classifier examples.

                                                    Instances For

                                                      Parse the standard CIFAR plus fixed-step training flags and reject unused arguments.

                                                      Generative examples use the same prepared CIFAR arrays and the same loss-curve logging contract; only the model and target construction differ.

                                                      Instances For
                                                        def NN.Examples.Models.RealData.CifarModelTrainFlags.parse (exeName : String) (args : List String) (defaultLogPath : System.FilePath) (defaultSteps : := 1) (defaultLearningRate : Float := 1e-3) :

                                                        Parse the standard CIFAR plus optimizer/training flags.

                                                        Vision examples share the same CIFAR data boundary and optimizer controls; architecture files only need to provide the model constructor and logging title. Any remaining arguments are preserved so the caller can forward runtime flags such as --device cpu, --device cuda, or --execution typed-graph to the public Trainer.RunConfig parser.

                                                        Instances For
                                                          def NN.Examples.Models.RealData.ForecastWindowDataFlags.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, --report-offset, and --seed.

                                                          Instances For
                                                            @[reducible, inline]

                                                            Parsed household-power forecasting data plus optimizer/training flags.

                                                            Instances For
                                                              def NN.Examples.Models.RealData.HouseholdPowerModelTrainFlags.parse (exeName : String) (args : List String) (defaultLogPath : System.FilePath) (defaultSteps : := 100) (defaultLearningRate : Float := 1e-2) (defaultWindows : := 512) (defaultReportOffset : := 96) :

                                                              Parse the standard household-power forecasting flags plus optimizer/training flags.

                                                              The forecasting command still owns the model and reporting logic, but the shared data/runtime flag surface lives here with the other real-data code.

                                                              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

                                                                  Common training-log notes for CIFAR-backed classifier examples.

                                                                  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.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

                                                                            Load the first full ImageNet64-style minibatch from the shared ImageNet64 loader.

                                                                            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
                                                                                  @[reducible, inline]

                                                                                  Shared text-corpus CLI/data boundary for local text-model examples.

                                                                                  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