Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            MnistImageStoreOptions options = Configuration.GetSection(mnistImageStoreSettingsKeyName).Get <MnistImageStoreOptions>();

            if (options.ShowDeveloperExceptionPage == true)
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                SetupExceptionHandler(app);
            }

            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Ejemplo n.º 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);
        }