今朝方体調不良で目が覚めた。ここ数日の肌寒さが気にはなっていたが特に対処しなかったのがたたったかな😨 くしゃみ、鼻水が止まらなくて寝てられなかった。とはいえ、先に進める必要があるので作業は続けてます。
前回進捗状況観る為にってやつですが、あれだと何が何だか分からない出力がだらだらと出るだけで、まあ、チュートリアルではなんであんなの入れているのか不明だけど、実際にはその続きが書かれているのかなぁ。
- public class AutoMLMonitor : IMonitor
- {
- private readonly SweepablePipeline _pipeline;
- private readonly List<TrialResult> _completedTrials;
- private readonly RichTextBox _richTextBox;
- public IEnumerable<TrialResult> GetCompletedTrials() => _completedTrials;
- public AutoMLMonitor(SweepablePipeline pipeline, RichTextBox rtbLog)
- {
- _pipeline = pipeline;
- _completedTrials = new List<TrialResult>();
- _richTextBox = rtbLog;
- }
- public void ReportBestTrial(TrialResult result)
- {
- return;
- }
- public void ReportCompletedTrial(TrialResult result)
- {
- var trialId = result.TrialSettings.TrialId;
- var timeToTrain = result.DurationInMilliseconds;
- var pipeline = _pipeline.ToString(result.TrialSettings.Parameter);
- _completedTrials.Add(result);
- // Console.WriteLine($"Trial {trialId} finished training in {timeToTrain}ms with pipeline {pipeline}");
- _richTextBox.AppendText($"Trial {trialId} finished training in {timeToTrain}ms with pipeline {pipeline}" + Environment.NewLine);
- }
- public void ReportFailTrial(TrialSettings settings, Exception exception = null)
- {
- if (exception.Message.Contains("Operation was canceled."))
- {
- // Console.WriteLine($"{settings.TrialId} cancelled. Time budget exceeded.");
- _richTextBox.AppendText($"{settings.TrialId} cancelled. Time budget exceeded." + Environment.NewLine);
- }
- // Console.WriteLine($"{settings.TrialId} failed with exception {exception.Message}");
- _richTextBox.AppendText($"{settings.TrialId} failed with exception {exception.Message}" + Environment.NewLine);
- }
- public void ReportRunningTrial(TrialSettings setting)
- {
- return;
- }
- }
これが本来使うもので、ああ、実際には相変わらずConsole.WriteLineだったのでRichTextBoxに出力する様に修正してます。で、これをAutoML実行前に、
- var monitor = new AutoMLMonitor(pipeline, rtbLog);
- experiment.SetMonitor(monitor);
としておけばいい感じです。AutoMLの実行も
- var cts = new CancellationTokenSource();
- TrialResult experimentResults = await experiment.RunAsync(cts.Token);
って感じに変更なんですが、この部分がいまいちよく分かってないけど真似しておく😉 AutoMPが終わったら
- var completedTrials = monitor.GetCompletedTrials();
- mlContext.Model.Save(experimentResults.Model, data.Schema, $"ShinbaTime.zip");
てな感じで保存しておかないと無駄になるのでしておきます。保存しておけば、
- DataViewSchema predictionPipelineSchema;
- ITransformer predictionPipeline = mlContext.Model.Load($"ShinbaTime.zip", out predictionPipelineSchema);
- predictionEngine = mlContext.Model.CreatePredictionEngine<ShinbaTime, ShinbaTimePrediction>(predictionPipeline);
とすれば使えます。予測したいサンプル準備して
- yoso = predictionEngine.Predict(inputData);
まだまだやる事は多いけど、一時は全ての苦労が水の泡かと思ったけどなんとかなったかな😁
0 件のコメント:
コメントを投稿