Ejemplo n.º 1
0
        public async Task SaveClustersAsync()
        {
            var trainSamples = await _samplesService.GetTrainPhotosAsync();

            var clusters = await BuildClustersAsync(_numberOfClusters, trainSamples);

            await _clusterSamplePhotoRepository.DeleteAsync(x => true);

            await _clusterRepository.DeleteAsync(x => true);

            foreach (var cluster in clusters)
            {
                await _clusterRepository.CreateAsync(cluster);
            }

            _logger.LogInfo("Old clusters removed and new clusters added.");
        }
Ejemplo n.º 2
0
        public async Task KMeansResearchAsync()
        {
            var stepSize     = (_kmeansClustersEnd - _kmeansClustersStart) / (_kmeansStages - 1);
            var trainSamples = await _samplesService.GetTrainPhotosAsync();

            var testSamples = await _samplesService.GetTestPhotosAsync();

            var results = new List <KMeansResearchResult>();

            for (var numOfClusters = _kmeansClustersStart; numOfClusters <= _kmeansClustersEnd; numOfClusters += stepSize)
            {
                var watch = Stopwatch.StartNew();
                var clustersBuildWatch = Stopwatch.StartNew();
                var clusters           = await _clusterService.BuildClustersAsync(numOfClusters, trainSamples);

                clustersBuildWatch.Stop();

                var result           = 0d;
                var photoSearchWatch = Stopwatch.StartNew();
                foreach (var testPhoto in testSamples)
                {
                    var similarPhoto = await _photoService.FindMostSimilarPhotoAsync(testPhoto.Prediction, clusters);

                    result += CompareDescriptions(testPhoto.Description, similarPhoto.Description);
                }
                photoSearchWatch.Stop();

                result = result / testSamples.Count();
                watch.Stop();
                results.Add(new KMeansResearchResult(numOfClusters, result,
                                                     watch.ElapsedMilliseconds, clustersBuildWatch.ElapsedMilliseconds, photoSearchWatch.ElapsedMilliseconds));
            }

            await _kMeansResearchRepository.DeleteAsync(x => true);

            foreach (var kMeansResearchResult in results)
            {
                await _kMeansResearchRepository.CreateAsync(kMeansResearchResult);
            }
        }