1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SageMakerのhyperparametersでlist型の引数を渡す方法

Posted at

以下の issue の通り、 hyperparameters の各要素は一度 str に変換されます。

ですので、文字列にしたリストを list 型に戻す必要があります。このとき、json ライブラリを使うことで簡単に戻すことができます。

entrypoint.py
import json
import argparse

parser = argparse.ArgumentParser()
paresr.add_argument(
    '--listarg',
    type=lambda s: json.loads(s.replace("'", '"'))
)

変換するときに、シングルクォーテーションをダブルクォーテーションに置換しないとエラーが出てしまいます。

ちなみに、この方法で dict 型も引数として渡すことができます。

1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?