Exemple #1
0
        public async Task Handle(ReadDatasetVerb verb)
        {
            if (!StringExists(verb.Id))
            {
                logger.Log("use --id <id> to choose a dataset");
                return;
            }
            var dataset = await datasetService.Get <EmptyDataset>(verb.Id);

            if (DatasetTypes.Empty.Equals(dataset.Type))
            {
                // emtpy set
                logger.Log($"{dataset.Id} is an empty dataset");
            }
            else if (DatasetTypes.SingleClassImage.Equals(dataset.Type))
            {
                var resolved = await resolverService.ResolveSingleClassImage(dataset);

                logger.Log($"{resolved.Id} is of type {resolved.Type}");
                logger.Log($"There are {resolved.LabelledImages.Count()} images in the set");
                var labelCount = resolved.LabelledImages.Select(i => i.Label).Distinct().Count();
                logger.Log($"There are {labelCount} labels");

                if (StringExists(verb.Output))
                {
                    var json = JsonConvert.SerializeObject(resolved);
                    File.WriteAllText(verb.Output + "/" + verb.Id + ".json", json);
                }
            }
            else
            {
                logger.Log($"{dataset.Type} is an unknown type");
            }
        }
        public async Task TestTargetAsync(string target, string datasetId)
        {
            logger.Log($"Targetting {target} with dataset {datasetId}");
            var emptyset = await datasetService.Get <EmptyDataset>(datasetId);

            logger.Log($"Loaded dataset {emptyset.Id}");
            switch (target)
            {
            case Targets.CustomVision:
                var tester  = serviceProvider.GetService <ICustomVisionTester>();
                var dataset = await datasetResolver.ResolveSingleClassImage(emptyset);

                var result = await tester.Run(dataset);

                logger.Log($"Fraction passed: {result.PercentagePassed}");
                await resultStore.LogTestResultAsync(result);

                break;
            }
        }
        public async Task Handle(UpdateDatasetVerb verb)
        {
            IDataset emptySet;

            try
            {
                emptySet = await datasetService.Get <EmptyDataset>(verb.Id);
            }
            catch (FileNotFoundException)
            {
                logger.Error(null, new FileNotFoundException($"Dataset does not exist. Please use 'create-dataset --id {verb.Id}' before using 'update-dataset'."));
                return;
            }

            emptySet.Type = DatasetTypes.FromValue(verb.Type);

            if (verb.Replace)
            {
                await datasetService.Set(emptySet);
            }

            if (string.Equals(DatasetTypes.SingleClassImage.Value, verb.Type))
            {
                // will have to branch here in future based on different types of sets
                var dataset = await resolverService.ResolveSingleClassImage(emptySet);

                if (StringExists(verb.FromFile) && StringExists(verb.Label))
                {
                    // either this is an empty set, or the set exists and the user has chosen the right type
                    // depending on the type, we load the dataset
                    logger.Log($"Updating dataset {verb.Id} with file {verb.FromFile} and label {verb.Label}");
                    var urls = fileParser.LinesFromFile(verb.FromFile);
                    foreach (var url in urls)
                    {
                        logger.Log($"adding {url}");
                        // add the urls
                        dataset.AddLabelledImage(verb.Label, url);
                    }

                    await datasetService.Set(dataset);
                }
                else if (StringExists(verb.Url) && StringExists(verb.Label))
                {
                    if (!DatasetTypes.IsValid(verb.Type))
                    {
                        logger.Log($"{verb.Type} is an invalid dataset type");
                        logger.Log($"Available types are {DatasetTypes.PrintTypes()}");
                        return;
                    }
                    dataset.Type = DatasetTypes.FromValue(verb.Type);
                    logger.Log($"Adding url {verb.Url} as {verb.Label}");
                    dataset.AddLabelledImage(verb.Label, verb.Url);
                    await datasetService.Set(dataset);
                }
            }
            else if (string.Equals(verb.Type, DatasetTypes.Empty.Value))
            {
                logger.Log($"Dataset is still typed as Empty. Use --type");
            }
            else
            {
                logger.Log($"Unknown type {verb.Type}");
            }
        }