LoginSignup
2
1

More than 5 years have passed since last update.

Amazon SageMakerで物体検出(うまい棒検出の記事を補足)

Last updated at Posted at 2019-04-05

物体検出モデルを自前に作るには、Amazon SageMakerというサービスを使うのがとても便利。
ハイパーパラメータの説明も以下の通り分かりやすい。
https://docs.aws.amazon.com/ja_jp/sagemaker/latest/dg/object-detection-api-config.html

さて、動かし方ですが、基本的には以下記事の通りに実装すればOK。多謝。
https://dev.classmethod.jp/cloud/aws/sagemaker-umaibo-object-detection/

ただし、VoTTのoutputとSageMaker投入用inputのフォーマットを合わせるところのスクリプトが若干異なっていたので、以下のように修正。

import json

file_name = '{your_file_path}'
class_list = {'your_class':0}

with open(file_name) as f:
    js = json.load(f)

    for k, v in js['assets'].items():

        fileno = v["asset"]["name"].split(".")[0]

        line = {}
        line['file'] = fileno + '.jpg'
        line['image_size'] = [{
            'width':v["asset"]["size"]["width"],
            'height':v["asset"]["size"]["height"],
            'depth':3
        }]

        line['annotations'] = []

        for annotation in v["regions"]:

            line['annotations'].append(
                {
                    'class_id':class_list[annotation['tags'][0]],
                    'top':annotation['boundingBox']["top"],
                    'left':annotation['boundingBox']["left"],
                    'width':annotation['boundingBox']["width"],
                    'height':annotation['boundingBox']["height"]
                }
            )

        line['categories'] = []

        for name, class_id in class_list.items():

            line['categories'].append(
                {
                    'class_id':class_id,
                    'name':name
                }
            )

        f = open('./json/' + fileno + '.json', 'w')
        json.dump(line, f)
        f.close()

さらにさらに、当然ながらトレーニングにはGPUインスタンスが必要なので、アカウント作りたての方はリソースの上限緩和が必要。私の場合は以下の通り申請し変更。
トレーニング:ml.p3.2xlarge
ホスティング:ml.m4.xlarge
常識かもしれませんが、念の為。

ちなみに認識結果は公開できないのですが、400枚弱のアノテーション、ハイパーパラメータのチューニングはほぼなしでモデル構築したところ、F値は9割超え。素晴らしい。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1