Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Menghapus proyek Label Kustom Rekognition Amazon
Anda dapat menghapus proyek dengan menggunakan konsol Amazon Rekognition atau dengan menelepon. DeleteProjectAPI Untuk menghapus proyek, Anda harus terlebih dahulu menghapus setiap model terkait. Proyek atau model yang dihapus tidak dapat dihapus.
Menghapus proyek Label Kustom Rekognition Amazon (Konsol)
Anda dapat menghapus proyek dari halaman proyek, atau Anda dapat menghapus proyek dari halaman detail proyek. Prosedur berikut menunjukkan cara menghapus proyek menggunakan halaman proyek.
Konsol Label Kustom Amazon Rekognition menghapus model dan kumpulan data terkait untuk Anda selama penghapusan proyek. Anda tidak dapat menghapus proyek jika salah satu modelnya sedang berjalan atau dilatih. Untuk menghentikan model yang sedang berjalan, lihatMenghentikan model Label Kustom Rekognition Amazon (SDK). Jika model sedang dilatih, tunggu sampai selesai sebelum Anda menghapus proyek.
Untuk menghapus proyek (konsol)
Buka konsol Amazon Rekognition di. https://console.aws.amazon.com/rekognition/
Pilih Gunakan Label Kustom.
Pilih Mulai.
Di panel navigasi kiri, pilih Proyek.
Pada halaman Proyek, pilih tombol radio untuk proyek yang ingin Anda hapus. Daftar proyek ditampilkan echo-devices-project, dengan 1 versi dibuat pada 2020-03-25, dan opsi untuk Hapus, Latih model baru, atau Buat proyek.
Pilih Hapus di bagian atas halaman. Kotak dialog Delete project ditampilkan.
Jika proyek tidak memiliki model terkait:
Masukkan hapus untuk menghapus proyek.
Pilih Hapus untuk menghapus proyek.
Jika proyek memiliki model atau kumpulan data terkait:
Masukkan hapus untuk mengonfirmasi bahwa Anda ingin menghapus model dan kumpulan data.
Pilih Hapus model terkait atau Hapus kumpulan data terkait atau Hapus kumpulan data dan model terkait, tergantung pada apakah model memiliki kumpulan data, model, atau keduanya. Penghapusan model mungkin membutuhkan waktu beberapa saat untuk diselesaikan.
Konsol tidak dapat menghapus model yang sedang dalam pelatihan atau berjalan. Coba lagi setelah menghentikan model yang sedang berjalan yang terdaftar, dan tunggu hingga model terdaftar sebagai pelatihan selesai.
Jika Anda Menutup kotak dialog selama penghapusan model, model masih dihapus. Nanti, Anda dapat menghapus proyek dengan mengulangi prosedur ini.
Panel untuk menghapus model memberi Anda instruksi eksplisit untuk menghapus model terkait.
Masukkan hapus untuk mengonfirmasi bahwa Anda ingin menghapus proyek.
Pilih Hapus untuk menghapus proyek.
Menghapus proyek Label Kustom Rekognition Amazon () SDK
Anda menghapus project Amazon Rekognition Custom Labels dengan DeleteProjectmemanggil dan memasok Amazon Resource Name ARN () dari project yang ingin Anda hapus. Untuk mendapatkan ARNs proyek di AWS akun Anda, hubungi DescribeProjects. Responsnya mencakup array ProjectDescriptionobjek. ARNProyeknya adalah ProjectArn
lapangan. Anda dapat menggunakan nama proyek untuk mengidentifikasi proyek. ARN Misalnya, arn:aws:rekognition:us-east-1:123456789010:project/project name
/1234567890123
.
Sebelum Anda dapat menghapus proyek, Anda harus terlebih dahulu menghapus semua model dan kumpulan data dalam proyek. Untuk informasi selengkapnya, silakan lihat Menghapus model Label Kustom Amazon Rekognition dan Menghapus set data.
Proyek ini mungkin membutuhkan beberapa saat untuk dihapus. Selama waktu itu, status proyek adalahDELETING
. Proyek akan dihapus jika panggilan berikutnya DescribeProjectstidak menyertakan proyek yang Anda hapus.
Untuk menghapus proyek (SDK)
-
Jika Anda belum melakukannya, instal dan konfigurasikan AWS CLI dan AWS SDKs. Untuk informasi selengkapnya, lihat Langkah 4: Mengatur AWS CLI dan AWS SDKs.
Gunakan kode berikut untuk menghapus proyek.
- AWS CLI
-
Ubah nilai project-arn
menjadi nama proyek yang ingin Anda hapus.
aws rekognition delete-project --project-arn project_arn
\
--profile custom-labels-access
- Python
-
Gunakan kode berikut. Sediakan parameter baris perintah berikut:
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Purpose
Amazon Rekognition Custom Labels project example used in the service documentation:
https://docs.aws.amazon.com/rekognition/latest/customlabels-dg/mp-delete-project.html
Shows how to delete an existing Amazon Rekognition Custom Labels project.
You must first delete any models and datasets that belong to the project.
"""
import argparse
import logging
import time
import boto3
from botocore.exceptions import ClientError
logger = logging.getLogger(__name__)
def find_forward_slash(input_string, n):
"""
Returns the location of '/' after n number of occurences.
:param input_string: The string you want to search
: n: the occurence that you want to find.
"""
position = input_string.find('/')
while position >= 0 and n > 1:
position = input_string.find('/', position + 1)
n -= 1
return position
def delete_project(rek_client, project_arn):
"""
Deletes an Amazon Rekognition Custom Labels project.
:param rek_client: The Amazon Rekognition Custom Labels Boto3 client.
:param project_arn: The ARN of the project that you want to delete.
"""
try:
# Delete the project
logger.info("Deleting project: %s", project_arn)
response = rek_client.delete_project(ProjectArn=project_arn)
logger.info("project status: %s",response['Status'])
deleted = False
logger.info("waiting for project deletion: %s", project_arn)
# Get the project name
start = find_forward_slash(project_arn, 1) + 1
end = find_forward_slash(project_arn, 2)
project_name = project_arn[start:end]
project_names = [project_name]
while deleted is False:
project_descriptions = rek_client.describe_projects(
ProjectNames=project_names)['ProjectDescriptions']
if len(project_descriptions) == 0:
deleted = True
else:
time.sleep(5)
logger.info("project deleted: %s",project_arn)
return True
except ClientError as err:
logger.exception(
"Couldn't delete project - %s: %s",
project_arn, err.response['Error']['Message'])
raise
def add_arguments(parser):
"""
Adds command line arguments to the parser.
:param parser: The command line parser.
"""
parser.add_argument(
"project_arn", help="The ARN of the project that you want to delete."
)
def main():
logging.basicConfig(level=logging.INFO,
format="%(levelname)s: %(message)s")
try:
# get command line arguments
parser = argparse.ArgumentParser(usage=argparse.SUPPRESS)
add_arguments(parser)
args = parser.parse_args()
print(f"Deleting project: {args.project_arn}")
# Delete the project.
session = boto3.Session(profile_name='custom-labels-access')
rekognition_client = session.client("rekognition")
delete_project(rekognition_client,
args.project_arn)
print(f"Finished deleting project: {args.project_arn}")
except ClientError as err:
error_message = f"Problem deleting project: {err}"
logger.exception(error_message)
print(error_message)
if __name__ == "__main__":
main()
- Java V2
-
Gunakan kode berikut. Sediakan parameter baris perintah berikut:
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package com.example.rekognition;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.rekognition.RekognitionClient;
import software.amazon.awssdk.services.rekognition.model.DeleteProjectRequest;
import software.amazon.awssdk.services.rekognition.model.DeleteProjectResponse;
import software.amazon.awssdk.services.rekognition.model.DescribeProjectsRequest;
import software.amazon.awssdk.services.rekognition.model.DescribeProjectsResponse;
import software.amazon.awssdk.services.rekognition.model.ProjectDescription;
import software.amazon.awssdk.services.rekognition.model.RekognitionException;
public class DeleteProject {
public static final Logger logger = Logger.getLogger(DeleteProject.class.getName());
public static void deleteMyProject(RekognitionClient rekClient, String projectArn) throws InterruptedException {
try {
logger.log(Level.INFO, "Deleting project: {0}", projectArn);
// Delete the project
DeleteProjectRequest deleteProjectRequest = DeleteProjectRequest.builder().projectArn(projectArn).build();
DeleteProjectResponse response = rekClient.deleteProject(deleteProjectRequest);
logger.log(Level.INFO, "Status: {0}", response.status());
// Wait until deletion finishes
Boolean deleted = false;
do {
DescribeProjectsRequest describeProjectsRequest = DescribeProjectsRequest.builder().build();
DescribeProjectsResponse describeResponse = rekClient.describeProjects(describeProjectsRequest);
List<ProjectDescription> projectDescriptions = describeResponse.projectDescriptions();
deleted = true;
for (ProjectDescription projectDescription : projectDescriptions) {
if (Objects.equals(projectDescription.projectArn(), projectArn)) {
deleted = false;
logger.log(Level.INFO, "Not deleted: {0}", projectDescription.projectArn());
Thread.sleep(5000);
break;
}
}
} while (Boolean.FALSE.equals(deleted));
logger.log(Level.INFO, "Project deleted: {0} ", projectArn);
} catch (
RekognitionException e) {
logger.log(Level.SEVERE, "Client error occurred: {0}", e.getMessage());
throw e;
}
}
public static void main(String[] args) {
final String USAGE = "\n" + "Usage: " + "<project_arn>\n\n" + "Where:\n"
+ " project_arn - The ARN of the project that you want to delete.\n\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String projectArn = args[0];
try {
RekognitionClient rekClient = RekognitionClient.builder()
.region(Region.US_WEST_2)
.credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access"))
.build();
// Delete the project.
deleteMyProject(rekClient, projectArn);
System.out.println(String.format("Project deleted: %s", projectArn));
rekClient.close();
} catch (RekognitionException rekError) {
logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage());
System.exit(1);
}
catch (InterruptedException intError) {
logger.log(Level.SEVERE, "Exception while sleeping: {0}", intError.getMessage());
System.exit(1);
}
}
}