public static async Task SubmitAutoMLImageObjectDetectionAsync()

in sdk/dotnet/AzureML-Samples-CSharp/Jobs/AutomlJob/AutoMLJobOperations.cs [498:610]


    public static async Task<MachineLearningJobResource> SubmitAutoMLImageObjectDetectionAsync(
        ResourceGroupResource resourceGroup,
        string workspaceName,
        string id,
        string experimentName,
        string environmentId,
        string computeId)
    {
        Console.WriteLine("Creating an AutoML ImageObjectDetection job...");
        MachineLearningWorkspaceResource ws = await resourceGroup.GetMachineLearningWorkspaces().GetAsync(workspaceName);

        // Upload the MLTable in the default workspaceblobstore.
        var trainData = new MLTableJobInput(new Uri("azureml://datastores/workspaceblobstore/paths/training-mltable-folder-od"))
        {
            Mode = InputDeliveryMode.ReadOnlyMount,
            Description = "Train data",
        };
        var validationData = new MLTableJobInput(new Uri("azureml://datastores/workspaceblobstore/paths/validation-mltable-folder-od"))
        {
            Mode = InputDeliveryMode.ReadOnlyMount,
            Description = "Validation data",
        };
        var trainingData = new TrainingDataSettings(trainData);

        ImageVerticalDataSettings dataSettings = new ImageVerticalDataSettings("label", trainingData)
        {
            // TargetColumnName = "Label",
            //TestData = new TestDataSettings()
            //{
            //    Data = testData,
            //    TestDataSize = .20,
            //},
            ValidationData = new ImageVerticalValidationDataSettings()
            {
                Data = validationData,
                // Validation size must be between 0.01 and 0.99 inclusive when specified. Test size must be between 0 and 0.99 inclusive when specified. Test split is not supported for task type: text-ner
                ValidationDataSize = 0.20,
            },
        };
        ImageLimitSettings limitSettings = new ImageLimitSettings()
        {
            MaxConcurrentTrials = 1,
            MaxTrials = 2,
            Timeout = TimeSpan.FromHours(2)
        };

        ImageSweepLimitSettings sweepLimits = new ImageSweepLimitSettings() { MaxConcurrentTrials = 2, MaxTrials = 10 };
        SamplingAlgorithmType samplingAlgorithm = SamplingAlgorithmType.Random;
        List<ImageModelDistributionSettingsObjectDetection> searchSpaceList = new List<ImageModelDistributionSettingsObjectDetection>()
            {
                new ImageModelDistributionSettingsObjectDetection()
                {
                    ModelName = "yolov5",
                    EarlyStopping = "true",
                    LearningRate = "uniform(0.0001, 0.01)",
                    ModelSize = "choice('small', 'medium')",

                },
                new ImageModelDistributionSettingsObjectDetection()
                {
                    ModelName = "fasterrcnn_resnet50_fpn",
                    LearningRate = "uniform(0.0001, 0.001)",
                    Optimizer = "choice('sgd', 'adam', 'adamw')",
                    ModelSize = "choice('small', 'medium')",
                    MinSize = "choice(600, 800)",

                },
            };

        AutoMLVertical taskDetails = new ImageObjectDetection(dataSettings, limitSettings)
        {
            LogVerbosity = LogVerbosity.Info,
            PrimaryMetric = ObjectDetectionPrimaryMetrics.MeanAveragePrecision,
            SweepSettings = new ImageSweepSettings(sweepLimits, samplingAlgorithm)
            {
                EarlyTermination = new BanditPolicy() { SlackFactor = 0.2f, EvaluationInterval = 2, DelayEvaluation = 6 },
            },
            SearchSpace = searchSpaceList,
            // ModelSettings = modelSettings,
        };

        var autoMLJob = new AutoMLJob(taskDetails)
        {
            ExperimentName = experimentName,
            DisplayName = "AutoMLJob ImageObjectDetection-" + Guid.NewGuid().ToString("n").Substring(0, 6),
            EnvironmentId = environmentId,
            IsArchived = false,
            ComputeId = computeId,
            Resources = new ResourceConfiguration
            {
                InstanceCount = 3,
            },
            Properties = new Dictionary<string, string>
                {
                    { "property-name", "property-value" },
                },
            Tags = new Dictionary<string, string>
                {
                    { "tag-name", "tag-value" },
                },
            EnvironmentVariables = new Dictionary<string, string>()
                {
                    { "env-var", "env-var-value" }
                },
            Description = "This is a description of test AutoMLJob for ImageObjectDetection",
        };

        MachineLearningJobData MachineLearningJobData = new MachineLearningJobData(autoMLJob);
        ArmOperation<MachineLearningJobResource> jobOperation = await ws.GetMachineLearningJobs().CreateOrUpdateAsync(WaitUntil.Completed, id, MachineLearningJobData);
        MachineLearningJobResource jobResource = jobOperation.Value;
        Console.WriteLine($"JobCreateOrUpdateOperation {jobResource.Data.Id} created.");
        return jobResource;
    }