以前にmetaflowの環境を構築しましたが、引数を渡してmetaflowを実行したいと思い、
調べて試してみました
こちらの記事は備忘録になります
※環境構築は以下を参照
technoxs-stacker.hatenablog.com
目次
スポンサーリンク
この記事でわかること
metaflowでコマンドライン引数の渡し方
1.コードの改造
以下のようにhello worldのコードを改造
from metaflow import FlowSpec, step, Parameter class HelloFlow(FlowSpec): """ A flow where Metaflow prints 'Hi'. Run this flow to validate that Metaflow is installed correctly. """ strat_msg = Parameter('strat_msg', help='strat messege.', type=str, required=True) lr = Parameter('lr', help='Learning rate', default=0.01, type=float) batch_size = Parameter('batch_size', help='batch size', default=128, type=int) @step def start(self): """ This is the 'start' step. All flows must have a step named 'start' that is the first step in the flow. """ print('Metaflow says: %s' % self.strat_msg) self.next(self.hello) @step def hello(self): """ A step for metaflow to introduce itself. """ print('learning rate is %f' % self.lr) print('batch size is %d' % self.batch_size) self.next(self.end) @step def end(self): """ This is the 'end' step. All flows must have an 'end' step, which is the last step in the flow. """ print("HelloFlow is all done.") if __name__ == '__main__': HelloFlow()
2.parameter クラスのメモ
変数名 | 内容 | 例 |
---|---|---|
name | parameter名 | strat_msg |
default | デフォルト値 | default='hoge' |
type | parameterの型(str, float, int, bool) | type=str |
help | helpメッセージ | help='hugahuga' |
required | 省略可否(True/False) | required=True |
スポンサーリンク