Remove similar image samples

Updated at:

This topic describes how to use the .NET SDK to remove similar image samples from an image library.

Feature description

The removal operation takes effect within 1 minute. You can remove up to 100 sample images at a time. For more information about the parameters, see the Delete Sample Image API documentation.

You must use the AI Guardrails endpoint to call the service using the SDK. For more information about API endpoints, see Endpoints.

Prerequisites

Before you begin, make sure you have:

  • Installed the .NET dependencies. See Install .NET dependencies and use the exact .NET version specified — otherwise operation calls will fail.

  • An AccessKey ID and AccessKey secret for a RAM user, stored as environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.

Remove similar image sample task

using System;
using Newtonsoft.Json;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Green.Model.V20180509;
using System.Collections.Generic;

namespace csharp_sdk_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            /**
             * Common methods to obtain environment variables:
             *     Obtain the AccessKey ID of a Resource Access Management (RAM) user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
             *     Obtain the AccessKey secret of a RAM user: Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
             */
            DefaultProfile profile = DefaultProfile.GetProfile(
                    "cn-shanghai",
                    "Get AccessKey ID from environment variable",
                    "Get AccessKey secret from environment variable");
            DefaultAcsClient client = new DefaultAcsClient(profile);

            DeleteSimilarityImageRequest request = new DeleteSimilarityImageRequest();
            request.AcceptFormat = FormatType.JSON;
            request.ContentType = FormatType.JSON;
            request.Method = MethodType.POST;
            request.Encoding = "UTF-8";

            Dictionary<string, object> httpBody = new Dictionary<string, object>();
            httpBody.Add("dataIds", new List<string> { "SampleImageID_1", "SampleImageID_2" });
            request.SetContent(System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(httpBody)), "utf-8", FormatType.JSON);
            try
            {
                DeleteSimilarityImageResponse response = client.GetAcsResponse(request);
                if (response.HttpResponse.Status != 200)
                {
                    Console.WriteLine("the request failed. status:{0}", response.HttpResponse.Status);
                }
                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
    }
}