Siirrä oppimista TensorFlow-objektien tunnistusmalleille Amazon SageMakerissa

Amazon Sage Maker tarjoaa sviitin sisäänrakennetut algoritmit, valmiiksi koulutetut mallitja valmiiksi rakennetut ratkaisumallit auttaa datatieteilijöitä ja koneoppimisen (ML) harjoittajia pääsemään nopeasti alkuun ML-mallien koulutuksessa ja käyttöönotossa. Voit käyttää näitä algoritmeja ja malleja sekä ohjattuun että ohjaamattomaan oppimiseen. Ne voivat käsitellä erityyppisiä syöttötietoja, mukaan lukien taulukko, kuva ja teksti.

This post is the second in a series on the new built-in algorithms in SageMaker. In the ensimmäinen viesti, we showed how SageMaker provides a built-in algorithm for image classification. Today, we announce that SageMaker provides a new built-in algorithm for object detection using TensorFlow. This supervised learning algorithm supports transfer learning for many pre-trained models available in TensorFlow. It takes an image as input and outputs the objects present in the image along with the bounding boxes. You can fine-tune these pre-trained models using transfer learning even when a large number of training images aren’t available. It’s available through the SageMaker sisäänrakennetut algoritmit samoin kuin SageMaker JumpStart UI in Amazon SageMaker Studio. Lisätietoja on kohdassa Object Detection Tensorflow ja esimerkkimuistikirja Introduction to SageMaker Tensorflow – Object Detection.

Object detection with TensorFlow in SageMaker provides transfer learning on many pre-trained models available in TensorFlow Hub. According to the number of class labels in the training data, a new randomly initialized object detection head replaces the existing head of the TensorFlow model. Either the whole network, including the pre-trained model, or only the top layer (object detection head) can be fine-tuned on the new training data. In this transfer learning mode, you can achieve training even with a smaller dataset.

How to use the new TensorFlow object detection algorithm

This section describes how to use the TensorFlow object detection algorithm with the SageMaker Python SDK. Katso lisätietoja sen käyttämisestä Studion käyttöliittymästä SageMaker JumpStart.

Algoritmi tukee siirtooppimista kohdassa luetelluille esikoulutetuille malleille TensorFlow mallit. Jokainen malli tunnistetaan yksilöllisesti model_id. The following code shows how to fine-tune a ResNet50 V1 FPN model identified by model_id tensorflow-od1-ssd-resnet50-v1-fpn-640x640-coco17-tpu-8 mukautetussa harjoitustietojoukossa. Jokaiselle model_id, aloittaakseen SageMaker-koulutustyön arviointityökalu class of the SageMaker Python SDK, you need to fetch the Docker image URI, training script URI, and pre-trained model URI through the utility functions provided in SageMaker. The training script URI contains all the necessary code for data processing, loading the pre-trained model, model training, and saving the trained model for inference. The pre-trained model URI contains the pre-trained model architecture definition and the model parameters. Note that the Docker image URI and the training script URI are the same for all the TensorFlow object detection models. The pre-trained model URI is specific to the particular model. The pre-trained model tarballs have been pre-downloaded from TensorFlow and saved with the appropriate model signature in Amazonin yksinkertainen tallennuspalvelu (Amazon S3) kauhoja, jotta koulutustyö suoritetaan verkkoeristettynä. Katso seuraava koodi:

from sagemaker import image_uris, model_uris, script_urisfrom sagemaker.estimator import Estimator

model_id, model_version = "tensorflow-od1-ssd-resnet50-v1-fpn-640x640-coco17-tpu-8", "*"
training_instance_type = "ml.p3.2xlarge"
# Retrieve the docker image
train_image_uri = image_uris.retrieve(model_id=model_id,model_version=model_version,image_scope="training",instance_type=training_instance_type,region=None,framework=None)# Retrieve the training script
train_source_uri = script_uris.retrieve(model_id=model_id, model_version=model_version, script_scope="training")# Retrieve the pre-trained model tarball for transfer learning
train_model_uri = model_uris.retrieve(model_id=model_id, model_version=model_version, model_scope="training")

output_bucket = sess.default_bucket()
output_prefix = "jumpstart-example-tensorflow-od-training"
s3_output_location = f"s3://{output_bucket}/{output_prefix}/output"

Näiden mallikohtaisten harjoitusartefaktien avulla voit rakentaa objektin arviointityökalu luokka:

# Create SageMaker Estimator instance
tf_od_estimator = Estimator(
    role=aws_role,
    image_uri=train_image_uri,
    source_dir=train_source_uri,
    model_uri=train_model_uri,
    entry_point="transfer_learning.py",
    instance_count=1,
    instance_type=training_instance_type,
    max_run=360000,
    hyperparameters=hyperparameters,
    output_path=s3_output_location,)

Seuraavaksi sinun on ehkä muutettava harjoitushyperparametrien oletusarvoja mukautetun tietojoukon oppimisen siirtämiseksi, jotka on lueteltu hyperparametrien. Voit hakea Python-sanakirjan näistä hyperparametreista niiden oletusarvoineen soittamalla hyperparameters.retrieve_default, päivitä ne tarvittaessa ja välitä ne sitten Estimator-luokkaan. Huomaa, että joidenkin hyperparametrien oletusarvot ovat erilaiset eri malleissa. Suurille malleille oletuserän koko on pienempi ja train_only_top_layer hyperparametri on asetettu arvoon True. Hyperparametri train_only_top_layer määrittää, mitkä mallin parametrit muuttuvat hienosäätöprosessin aikana. Jos train_only_top_layer is True, luokituskerrosten parametrit muuttuvat ja loput parametrit pysyvät vakioina hienosäätöprosessin aikana. Toisaalta jos train_only_top_layer is False, kaikki mallin parametrit ovat hienosäädettyjä. Katso seuraava koodi:

from sagemaker import hyperparameters# Retrieve the default hyper-parameters for fine-tuning the model
hyperparameters = hyperparameters.retrieve_default(model_id=model_id, model_version=model_version)# [Optional] Override default hyperparameters with custom values
hyperparameters["epochs"] = "5"

Tarjoamme PennFudanPed-tietojoukko as a default dataset for fine-tuning the models. The dataset comprises images of pedestrians. The following code provides the default training dataset hosted in S3 buckets:

# Sample training data is available in this bucket
training_data_bucket = f"jumpstart-cache-prod-{aws_region}"
training_data_prefix = "training-datasets/PennFudanPed_COCO_format/"

training_dataset_s3_path = f"s3://{training_data_bucket}/{training_data_prefix}"

Lopuksi käynnistä SageMaker-koulutustyö mallin hienosäätöä varten soittamalla .fit Estimator-luokan objektissa, kun ohitetaan harjoitustietojoukon S3-sijainti:

# Launch a SageMaker Training job by passing s3 path of the training data
tf_od_estimator.fit({"training": training_dataset_s3_path}, logs=True)

For more information about how to use the new SageMaker TensorFlow object detection algorithm for transfer learning on a custom dataset, deploy the fine-tuned model, run inference on the deployed model, and deploy the pre-trained model as is without first fine-tuning on a custom dataset, see the following example notebook: Introduction to SageMaker TensorFlow – Object Detection.

Input/output interface for the TensorFlow object detection algorithm

Voit hienosäätää jokaista luettelossa lueteltua esikoulutettua mallia TensorFlow mallit mihin tahansa tietojoukkoon, joka sisältää kuvia, jotka kuuluvat mihin tahansa määrään luokkia. Tavoitteena on minimoida syötetietojen ennustusvirhe. Hienosäädöllä palautettua mallia voidaan käyttää edelleen päätelmiä varten. Seuraavassa on ohjeet siitä, kuinka harjoitustiedot tulee muotoilla malliin syötettäväksi:

  • panos – A directory with sub-directory images and a file annotations.json.
  • ulostulo – There are two outputs. First is a fine-tuned model, which can be deployed for inference or further trained using incremental training. Second is a file which maps class indexes to class labels; this is saved along with the model.

The input directory should look like the following example:

input_directory
      | -- images
            |--abc.png
            |--def.png
      |--annotations.json

- annotations.json file should have information for bounding_boxes and their class labels. It should have a dictionary with the keys "images" ja "annotations". The value for the "images" key should be a list of entries, one for each image of the form {"file_name": image_name, "height": height, "width": width, "id": image_id}. Arvo "annotations" key should be a list of entries, one for each bounding box of the form {"image_id": image_id, "bbox": [xmin, ymin, xmax, ymax], "category_id": bbox_label}.

Inference with the TensorFlow object detection algorithm

Luotuja malleja voidaan isännöidä johtopäätösten tekemiseksi ja ne voivat tukea koodattuja .jpg-, .jpeg- ja .png-kuvamuotoja. application/x-image content type. The input image is resized automatically. The output contains the boxes, predicted classes, and scores for each prediction. The TensorFlow object detection model processes a single image per request and outputs only one line in the JSON. The following is an example of a response in JSON:

accept: application/json;verbose

{"normalized_boxes":[[xmin1, xmax1, ymin1, ymax1],....], "classes":[classidx1, class_idx2,...], "scores":[score_1, score_2,...], "labels": [label1, label2, ...], "tensorflow_model_output":}

If accept asetetaan application/json, then the model only outputs predicted boxes, classes, and scores. For more details on training and inference, see the sample notebook Introduction to SageMaker TensorFlow – Object Detection.

Käytä SageMakerin sisäänrakennettuja algoritmeja JumpStart-käyttöliittymän kautta

You can also use SageMaker TensorFlow object detection and any of the other built-in algorithms with a few clicks via the JumpStart UI. JumpStart is a SageMaker feature that allows you to train and deploy built-in algorithms and pre-trained models from various ML frameworks and model hubs through a graphical interface. It also allows you to deploy fully fledged ML solutions that string together ML models and various other AWS services to solve a targeted use case.

Seuraavassa on kaksi videota, jotka osoittavat, kuinka voit toistaa saman hienosäätö- ja käyttöönottoprosessin, jonka juuri kävimme läpi muutamalla napsautuksella JumpStart-käyttöliittymän kautta.

Hienosäädä esikoulutettu malli

Here is the process to fine-tune the same pre-trained object detection model.

Ota hienosäädetty malli käyttöön

Kun mallin koulutus on valmis, voit ottaa mallin suoraan käyttöön pysyvään, reaaliaikaiseen päätepisteeseen yhdellä napsautuksella.

Yhteenveto

In this post, we announced the launch of the SageMaker TensorFlow object detection built-in algorithm. We provided example code on how to do transfer learning on a custom dataset using a pre-trained model from TensorFlow using this algorithm.

Katso lisätietoja dokumentointi ja esimerkki muistikirja.


Tietoja kirjoittajista

Transfer learning for TensorFlow object detection models in Amazon SageMaker PlatoBlockchain Data Intelligence. Vertical Search. Ai.Tohtori Vivek Madan on soveltuva tutkija Amazon SageMaker JumpStart -tiimi. He got his PhD from University of Illinois at Urbana-Champaign and was a Post Doctoral Researcher at Georgia Tech. He is an active researcher in machine learning and algorithm design and has published papers in EMNLP, ICLR, COLT, FOCS, and SODA conferences.

Transfer learning for TensorFlow object detection models in Amazon SageMaker PlatoBlockchain Data Intelligence. Vertical Search. Ai.João Moura on AI/ML Specialist Solutions -arkkitehti Amazon Web Servicesissä. Hän keskittyy enimmäkseen NLP-käyttötapauksiin ja auttaa asiakkaita optimoimaan syvän oppimismallin koulutusta ja käyttöönottoa. Hän on myös aktiivinen matalan koodin ML-ratkaisujen ja ML-spesifisten laitteistojen kannattaja.

Transfer learning for TensorFlow object detection models in Amazon SageMaker PlatoBlockchain Data Intelligence. Vertical Search. Ai.Tohtori Ashish Khetan on vanhempi soveltuva tutkija Amazon SageMakerin sisäänrakennetut algoritmit ja auttaa kehittämään koneoppimisalgoritmeja. Hän sai tohtorin tutkinnon Illinois Urbana Champaignin yliopistosta. Hän on aktiivinen koneoppimisen ja tilastollisen päättelyn tutkija ja julkaissut monia artikkeleita NeurIPS-, ICML-, ICLR-, JMLR-, ACL- ja EMNLP-konferensseissa.

Aikaleima:

Lisää aiheesta AWS-koneoppiminen