public void LabelIndexer_LabelOutOfRange()
        {
            var testMnistImageLabelIndex = new MnistImageLabelIndex(Enumerable.Empty <MnistImage>());

            var e = Assert.Throws <IndexOutOfRangeException>(delegate
            {
                var result = testMnistImageLabelIndex[-1];
            });

            Assert.That(e.Message, Does.StartWith("Invalid index -1.  Indexer 'label' must be between 0 and 9 inclusive."));


            e = Assert.Throws <IndexOutOfRangeException>(delegate
            {
                var result = testMnistImageLabelIndex[10];
            });

            Assert.That(e.Message, Does.StartWith("Invalid index 10.  Indexer 'label' must be between 0 and 9 inclusive."));
        }
예제 #2
0
        /// <summary>
        /// Sets up objects storing and indexing MNIST image data, and adds them to the specified services collection.
        /// </summary>
        /// <param name="services">The services collection to add the objects to.</param>
        protected void SetupMnistImageDataStructures(IServiceCollection services)
        {
            MnistImageStoreOptions options = Configuration.GetSection(mnistImageStoreSettingsKeyName).Get <MnistImageStoreOptions>();
            // Read the MNIST data
            var mnistImageReader             = new MnistImageNativeFormatFileReader(options.MnistImageDataFileUri, options.MnistLabelFileUri);
            List <MnistImage> allMnistImages = null;
            // This stores the images grouped by label.
            MnistImageLabelIndex mnistImagesByLabel = null;

            try
            {
                IEnumerable <MnistImage> allImages = mnistImageReader.Read();
                allMnistImages     = new List <MnistImage>(allImages);
                allImages          = mnistImageReader.Read();
                mnistImagesByLabel = new MnistImageLabelIndex(allMnistImages);
            }
            catch (Exception e)
            {
                throw new Exception("Failed to read MNIST images.", e);
            }

            services.AddSingleton <List <MnistImage> >(allMnistImages);
            services.AddSingleton <MnistImageLabelIndex>(mnistImagesByLabel);
        }
예제 #3
0
 /// <summary>
 /// Initialises a new instance of the MnistImageStore.Controllers.MnistImageController class.
 /// </summary>
 /// <param name="allMnistImages">Holds all MNIST images.</param>
 /// <param name="mnistImagesByLabel">Holds MNIST images keyed by the image label.</param>
 public MnistImageController(List <MnistImage> allMnistImages, MnistImageLabelIndex mnistImagesByLabel)
 {
     this.allMnistImages     = allMnistImages;
     this.mnistImagesByLabel = mnistImagesByLabel;
 }