SlideShare a Scribd company logo
.NETラボ 勉強会 2021年1月
23th January 2021
Fujio Kojima
『C#で機械学習』
自己紹介
• 小島 富治雄
• @Fujiwo
• 福井コンピュータ グループ
• Microsoft MVP (2005-2021)
•BuriKaigi 2021
• オンライン開催!
• 2021/01/30 13:30 - 17:30
• オンライン懇親会!
with ぶりしゃぶ!
大事な話は最初に!
https://toyama-eng.connpass.com/event/198500/
Agenda
1. 機械学習 (ML: Machine Learning)
2. フルスクラッチ ニューラル ネットワーク (C#)
3. ML.NET (C#)
• ML.NET Model Builder → ML.NET (C#)
4. Azure Machine Learning → C#
4.1. デザイナーで機械学習 → API 作成 → API コール (C#)
4.2. Jupyter Notebook (Python) で機械学習 → ONNX モデル作成 → ML.NET (C#)
4.3. AutoMLでディープ ラーニング → API 作成 → API コール (C#)
本日のソースコード
• .NET Lab Study Meeging Jan. 2021 「Machine Learning with C#」 | Fujiwo | GitHub
• https://github.com/Fujiwo/DotNetLabNeuralNetworkSample202101
1. 機械学習 (ML: Machine Learning)
人工知能 (AI)
機械学習 (ML)
ニューラル ネットワーク
6
Deep Learning
ニューラル ネットワークとは
7
神経細胞のネットワーク
8
神経細胞のネットワークを模倣
ニューラル ネットワーク
入力
入力
・
・
・
出力
出力
・
・
・
・
・
・
・
・
・ ・
・
・
ニューロン
入力層 中間層 出力層
9
個々のニューロン
ニューロン
出力
入力
入力
・
・
・
入力
バイアス
10
ニューラル ネットワーク
入力
入力
出力
ニューロン
入力層 中間層 出力層
バイアス
重み
11
ニューラル ネットワークの訓練
正解
ー
1. 重みの修正
2. 重みの修正
入力
入力
ニューロン
入力層 中間層 出力層
バイアス
重み
出力
12
2. フルスクラッチ ニューラル ネットワーク (C#)
13
実際にニューラルネットワークを
プログラミング言語 (C#) で
フルスクラッチで書いて理解しよう
ニューラル ネットワークによる分類 (classification)
14
「その座標は福井県か否か?」
•学習データ
1. 郵便局の郵便番号データ
• 地名の一覧を取得
2. Google Maps の API で
緯度・経度に変換
CSV 形式で保存
2値による分類 (Classification)
16
Longitude 136
Latitude 36
Longitude
Latitude
➢ 一般的なアルゴリズムで
解くことはむつかしい
➢ 二次元だとこんな感じ
➢ 二次元の線で分けられる
➢ N次元に一般化すると?
➢ N次元空間の面で分ける
➢ 数学的には、テンソル
(N次元の値の集まり)
の流れ (tensor flow)
で考えることができる
public class Neuron // ニューロン
{
double sum;
public double Value { get; private set; } = 0.0;
public void Input(IEnumerable<Input> inputData)
{
inputData.ForEach(input => Input(input.WeightingValue));
Value = Math.Sigmoid(sum);
}
void Input(double value) => sum += value;
}
C# によるニューロンの実装
17
C# によるニューラル ネットワークの実装
public class NeuralNetwork // ニューラル ネットワーク
{
// 各層
double[] inputLayer;
Neuron[] middleLayer;
Neuron outputLayer;
// バイアス
double inputLayerBias = 1.0;
double middleLayerBias = 1.0;
// 各層の重み
// 入力層 → 中間層の重み
double[,] inputWeight = new double[,] { { RandomWeight, RandomWeight },
{ RandomWeight, RandomWeight }, { RandomWeight, RandomWeight } };
// 中間層 → 出力層の重み
double[] middleWeight = new[] { RandomWeight, RandomWeight, RandomWeight };
18
C# によるニューラル ネットワークの実装 (続き)
// 実行
public double Commit((double, double) data)
{
// 各層
inputLayer = new[] { data.Item1, data.Item2, inputLayerBias };
middleLayer = new[] { new Neuron(), new Neuron() };
outputLayer = new Neuron();
// 入力層→中間層
middleLayer.For((index, neuron)
=> middleLayer[index].Input(ToInputData(inputLayer, inputWeight.GetColumn(index).ToArray())));
// 中間層→出力層
outputLayer.Input(new[] { new Input { Value = middleLayer[0].Value, Weight = middleWeight[0] },
new Input { Value = middleLayer[1].Value, Weight = middleWeight[1] },
new Input { Value = middleLayerBias , Weight = middleWeight[2] } });
return outputLayer.Value;
}
19
C# によるニューラル ネットワークの実装 (続き)
// 学習 void Learn((double, double, double) data)
{
var outputData = Commit((data.Item1, data.Item2));
var correctValue = data.Item3;
var learningRate = 0.3; // 学習係数
// 出力層→中間層
// δmo = (出力値 - 正解値) × 出力の微分
var daltaMO = (correctValue - outputData) * outputData * (1.0 - outputData);
var oldMiddleWeight = middleWeight.Clone() as double[];
// 修正量 = δmo × 中間層の値 × 学習係数
middleLayer.For((index, neuron) => middleWeight[index] += neuron.Value * daltaMO * learningRate);
middleWeight[2] += middleLayerBias * daltaMO * learningRate;
// 中間層→入力層
// δim = δmo × 中間出力の重み × 中間層の微分
var deltaIM = middleLayer.IndexSelect(index =>
daltaMO * oldMiddleWeight[index] * middleLayer[index].Value * (1.0 - middleLayer[index].Value)).ToArray();
// 修正量 = δim × 入力層の値 × 学習係数
inputWeight.For((row, column, _) =>
inputWeight[row, column] += inputLayer[row] * deltaIM[column] * learningRate);
}
20
C# によるニューラル ネットワークの実装 (続き)
// 学習
public void Learn(IEnumerable<(double, double, double)> dataCollection, int times)
=> times.Times(() => dataCollection.ForEach(data => Learn(data)));
static IEnumerable<Input> ToInputData(double[] inputLayer, double[] inputWeight)
=> inputLayer.IndexSelect(index =>
new Input { Value = inputLayer[index], Weight = inputWeight[index] });
readonly static Random random = new Random();
const double weightRange = 10.0;
static double RandomWeight => (random.NextDouble() - 0.5) * weightRange;
}
21
実行結果 (座標データと訓練前)
22
実行結果 (教師データと訓練後)
23
訓練前の重みの値
24
訓練後の重みの値
25
Demo
26
3. ML.NET (C#)
•ML.NET Model Builder → ML.NET (C#)
27
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
Demo
39
4. Azure Machine Learning → C#
•よくあるシナリオ
1. クラウド (Azure) でトレーニングし、機械学習済みのモデルを作成
• ハイコスト
• ハイパフォーマンスのコンピューター
• 低頻度
2. エッジ デバイスで、そのモデルを利用
• ローコスト
• 非力なマシン
• 高頻度
40
Azure Machine Learning → C# の3つのシナリオ
• 4.1. デザイナーで機械学習
→ API 作成
→ API コール (C#)
• 4.2. Jupyter Notebook (Python) で機械学習/ディープ ラーニング
→ ONNX モデル作成
→ ML.NET (C#)
• 4.3. AutoML で機械学習/ディープ ラーニング
→ API 作成
→ API コール (C#)
4.1. デザイナーで機械学習
•デザイナーで機械学習
→ API 作成
→ API コール (C#)
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
Demo
69
4.2. Jupyter Notebook (Python) で機械学習
•Jupyter Notebook (Python) で機械学習
→ ONNX モデル作成
→ ML.NET (C#)
4.2. Jupyter Notebook (Python) で機械学習
•Fujiwo/decode2020: 【de:code 2020】 Azure
Machine Learning Studio と Python と C#/.NET に
よるディープ ラーニングのサンプル/チュートリアル
https://github.com/Fujiwo/decode2020
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
Demo
75
4.3. AutoMLでディープ ラーニング
•AutoMLでディープ ラーニング
→ API 作成
→ API コール (C#)
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
.NETラボ 勉強会 2021年1月 「C#で機械学習」
Demo
103
本日やったこと
1. 機械学習 (ML: Machine Learning)
2. フルスクラッチ ニューラル ネットワーク (C#)
3. ML.NET (C#)
• ML.NET Model Builder → ML.NET (C#)
4. Azure Machine Learning → C#
4.1. デザイナーで機械学習 → API 作成 → API コール (C#)
4.2. Jupyter Notebook (Python) で機械学習 → ONNX モデル作成 → ML.NET (C#)
4.3. AutoMLでディープ ラーニング → API 作成 → API コール (C#)
参考資料
• .NET で AutoML ONNX モデルを使用して予測を行う - Azure Machine Learning | Microsoft Docs
• 自動 ML とは AutoML - Azure Machine Learning | Microsoft Docs
• ONNX: 高パフォーマンスなクロス プラットフォームの推論 - Azure Machine Learning | Microsoft Docs
• 自動 ML 分類モデルを作成する - Azure Machine Learning | Microsoft Docs
• AutoML を使用して、モデルとデプロイを作成する - Azure Machine Learning | Microsoft Docs
• Web サービスとしてデプロイされるモデル用のクライアントを作成する - Azure Machine Learning | Microsoft Docs

More Related Content

PDF
Introduction to YOLO detection model
PPTX
[DL輪読会]Set Transformer: A Framework for Attention-based Permutation-Invariant...
PPTX
DLLab 異常検知ナイト 資料 20180214
PDF
PRML学習者から入る深層生成モデル入門
PPTX
[DL輪読会]Vision Transformer with Deformable Attention (Deformable Attention Tra...
PDF
SSII2022 [SS2] 少ないデータやラベルを効率的に活用する機械学習技術 〜 足りない情報をどのように補うか?〜
PDF
[DL輪読会]Taskonomy: Disentangling Task Transfer Learning
PPTX
CPU / GPU高速化セミナー!性能モデルの理論と実践:理論編
Introduction to YOLO detection model
[DL輪読会]Set Transformer: A Framework for Attention-based Permutation-Invariant...
DLLab 異常検知ナイト 資料 20180214
PRML学習者から入る深層生成モデル入門
[DL輪読会]Vision Transformer with Deformable Attention (Deformable Attention Tra...
SSII2022 [SS2] 少ないデータやラベルを効率的に活用する機械学習技術 〜 足りない情報をどのように補うか?〜
[DL輪読会]Taskonomy: Disentangling Task Transfer Learning
CPU / GPU高速化セミナー!性能モデルの理論と実践:理論編

What's hot (20)

PDF
SSII2022 [SS1] ニューラル3D表現の最新動向〜 ニューラルネットでなんでも表せる?? 〜​
PDF
研究室における研究・実装ノウハウの共有
PDF
SSII2022 [OS3-02] Federated Learningの基礎と応用
PPTX
[DL輪読会]Encoder-Decoder with Atrous Separable Convolution for Semantic Image S...
PDF
動画認識サーベイv1(メタサーベイ )
PPTX
[DL輪読会]Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
PDF
【DL輪読会】GAN-Supervised Dense Visual Alignment (CVPR 2022)
PPTX
【DL輪読会】SimCSE: Simple Contrastive Learning of Sentence Embeddings (EMNLP 2021)
PDF
【メタサーベイ】Neural Fields
PPTX
[DL輪読会]GLIDE: Guided Language to Image Diffusion for Generation and Editing
PDF
【DL輪読会】Perceiver io a general architecture for structured inputs &amp; outputs
PDF
自己教師学習(Self-Supervised Learning)
PPTX
C# でニューラルネットワークをスクラッチで書いて機械学習の原理を理解しよう
PPTX
[DL輪読会]YOLOv4: Optimal Speed and Accuracy of Object Detection
PDF
機械学習のためのベイズ最適化入門
PDF
【DL輪読会】DINOv2: Learning Robust Visual Features without Supervision
PPTX
【DL輪読会】言語以外でのTransformerのまとめ (ViT, Perceiver, Frozen Pretrained Transformer etc)
PDF
[DL輪読会]Energy-based generative adversarial networks
PPTX
学習時に使ってはいないデータの混入「リーケージを避ける」
PDF
(DL輪読)Variational Dropout Sparsifies Deep Neural Networks
SSII2022 [SS1] ニューラル3D表現の最新動向〜 ニューラルネットでなんでも表せる?? 〜​
研究室における研究・実装ノウハウの共有
SSII2022 [OS3-02] Federated Learningの基礎と応用
[DL輪読会]Encoder-Decoder with Atrous Separable Convolution for Semantic Image S...
動画認識サーベイv1(メタサーベイ )
[DL輪読会]Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
【DL輪読会】GAN-Supervised Dense Visual Alignment (CVPR 2022)
【DL輪読会】SimCSE: Simple Contrastive Learning of Sentence Embeddings (EMNLP 2021)
【メタサーベイ】Neural Fields
[DL輪読会]GLIDE: Guided Language to Image Diffusion for Generation and Editing
【DL輪読会】Perceiver io a general architecture for structured inputs &amp; outputs
自己教師学習(Self-Supervised Learning)
C# でニューラルネットワークをスクラッチで書いて機械学習の原理を理解しよう
[DL輪読会]YOLOv4: Optimal Speed and Accuracy of Object Detection
機械学習のためのベイズ最適化入門
【DL輪読会】DINOv2: Learning Robust Visual Features without Supervision
【DL輪読会】言語以外でのTransformerのまとめ (ViT, Perceiver, Frozen Pretrained Transformer etc)
[DL輪読会]Energy-based generative adversarial networks
学習時に使ってはいないデータの混入「リーケージを避ける」
(DL輪読)Variational Dropout Sparsifies Deep Neural Networks
Ad

Similar to .NETラボ 勉強会 2021年1月 「C#で機械学習」 (20)

PPTX
機械学習入門
PDF
機械学習 (AI/ML) 勉強会 #1 基本編
PDF
20160329.dnn講演
PDF
Deep learning実装の基礎と実践
PDF
20150803.山口大学集中講義
PPTX
「機械学習とは?」から始める Deep learning実践入門
PDF
03_深層学習
PPTX
機械学習 / Deep Learning 大全 (2) Deep Learning 基礎編
PDF
Deep learning reading club @ nimiri for SWEST
PDF
PythonによるDeep Learningの実装
PDF
Azure Machine Learning getting started
PDF
20150310 第1回 ディープラーニング勉強会
PPTX
Azure Machine Learning services 2019年6月版
PDF
SGDによるDeepLearningの学習
PDF
Getting Started with Deep Learning using Scala
PPTX
エンジニアのための機械学習の基礎
PPTX
Deep Learningについて(改訂版)
PPTX
2018/06/23 Sony"s deep learning software and the latest information
PPTX
機械学習 / Deep Learning 大全 (6) Library編
PDF
Azure Machine Learning アップデートセミナー 20191127
機械学習入門
機械学習 (AI/ML) 勉強会 #1 基本編
20160329.dnn講演
Deep learning実装の基礎と実践
20150803.山口大学集中講義
「機械学習とは?」から始める Deep learning実践入門
03_深層学習
機械学習 / Deep Learning 大全 (2) Deep Learning 基礎編
Deep learning reading club @ nimiri for SWEST
PythonによるDeep Learningの実装
Azure Machine Learning getting started
20150310 第1回 ディープラーニング勉強会
Azure Machine Learning services 2019年6月版
SGDによるDeepLearningの学習
Getting Started with Deep Learning using Scala
エンジニアのための機械学習の基礎
Deep Learningについて(改訂版)
2018/06/23 Sony"s deep learning software and the latest information
機械学習 / Deep Learning 大全 (6) Library編
Azure Machine Learning アップデートセミナー 20191127
Ad

More from Fujio Kojima (20)

PDF
AIエージェント勉強会~マイクロソフトの最新技術発表を受けて~ (2025/07)
PDF
ITエンジニア (Developer) 向けAIエージェント勉強会 (2025/06/13)
PDF
Burikaigi 2023「C# Live Coding!」 小島の分
PDF
2022.04.23 .NET 6 -7 時代のデスクトップ アプリケーション開発
PDF
.NET 6 時代のデスクトップ アプリケーション開発
PDF
BuriKaigi 2022 「C# Live Coding!」 小島の分
PDF
C#勉強会 ~ C#9の新機能 ~
PDF
.NET 5 勉強会 ~.NET Framework から .NET へ~
PDF
『議論パターン』 (Discussion Patterns) ~不毛な議論を避け、実り有る議論とするために~
PDF
C#の新機能勉強会 ~ C#7、8の新機能を活用して速く安全なプログラムを書こう~
PDF
C# ドキドキ ライブ コーディング!! ~ 小島の分 ~ | BuriKaigi 2020
PDF
牛タン会議 2019 @ 仙台 「C# ドキドキ ライブ!!」 小島の分
PDF
『機械学習 (AI/ML) の基礎と Microsoft の AI | 2019/04/02 Global AI Nights Fukui
PDF
機械学習 (AI/ML) 勉強会 #2 IoT編
PPTX
BuriKaigi2019 「C# ドキドキ・ライブコーディング」 小島の分
PPTX
C# LINQ ~深く知って、使いまくろう~
PPTX
「ふくいソフトウェアコンペティション 2014 大賞受賞者プレゼンテーション」
PPTX
.NET MVP によるドキドキ・ライブコーディング! 小島の分
PPTX
Windows アプリケーション開発 はじめに ~ Windows アプリケーション開発初学者の方向け Visual Studio を使ったアプリケーショ...
PPTX
HTML5 on ASP.NET
AIエージェント勉強会~マイクロソフトの最新技術発表を受けて~ (2025/07)
ITエンジニア (Developer) 向けAIエージェント勉強会 (2025/06/13)
Burikaigi 2023「C# Live Coding!」 小島の分
2022.04.23 .NET 6 -7 時代のデスクトップ アプリケーション開発
.NET 6 時代のデスクトップ アプリケーション開発
BuriKaigi 2022 「C# Live Coding!」 小島の分
C#勉強会 ~ C#9の新機能 ~
.NET 5 勉強会 ~.NET Framework から .NET へ~
『議論パターン』 (Discussion Patterns) ~不毛な議論を避け、実り有る議論とするために~
C#の新機能勉強会 ~ C#7、8の新機能を活用して速く安全なプログラムを書こう~
C# ドキドキ ライブ コーディング!! ~ 小島の分 ~ | BuriKaigi 2020
牛タン会議 2019 @ 仙台 「C# ドキドキ ライブ!!」 小島の分
『機械学習 (AI/ML) の基礎と Microsoft の AI | 2019/04/02 Global AI Nights Fukui
機械学習 (AI/ML) 勉強会 #2 IoT編
BuriKaigi2019 「C# ドキドキ・ライブコーディング」 小島の分
C# LINQ ~深く知って、使いまくろう~
「ふくいソフトウェアコンペティション 2014 大賞受賞者プレゼンテーション」
.NET MVP によるドキドキ・ライブコーディング! 小島の分
Windows アプリケーション開発 はじめに ~ Windows アプリケーション開発初学者の方向け Visual Studio を使ったアプリケーショ...
HTML5 on ASP.NET

.NETラボ 勉強会 2021年1月 「C#で機械学習」