Skip to content

Commit 81fe79a

Browse files
committed
added VB FashionMnist sample
1 parent b6f9c35 commit 81fe79a

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

FashionMnistClassification/FashionMnistClassification.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ static void Main() {
1616
// requires Internet connection
1717
(dynamic train, dynamic test) = tf.keras.datasets.fashion_mnist.load_data();
1818
// will be able to do (trainImages, trainLabels) = train;
19-
ndarray trainImages = train.Item1;
19+
ndarray trainImages = train.Item1 / 255.0f;
2020
ndarray trainLabels = train.Item2;
21-
ndarray testImages = test.Item1;
21+
ndarray testImages = test.Item1 / 255.0f;
2222
ndarray testLabels = test.Item2;
2323

2424
bool loaded = 60000 == trainImages.Length;

Gradient-Samples.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "BasicMathF", "FSharp\BasicM
2727
EndProject
2828
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "VB", "VB", "{875975E4-796F-4181-BACE-7DC71CE35D1F}"
2929
EndProject
30-
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "BasicMathVB", "VB\BasicMathVB\BasicMathVB.vbproj", "{453E1365-83C2-46B6-B8E0-728B778CA1A7}"
30+
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "BasicMathVB", "VB\BasicMathVB\BasicMathVB.vbproj", "{453E1365-83C2-46B6-B8E0-728B778CA1A7}"
31+
EndProject
32+
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "FashionMnistVB", "VB\FashionMnistVB\FashionMnistVB.vbproj", "{1077A08A-AB90-4286-BB0C-0F2E9D620595}"
3133
EndProject
3234
Global
3335
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -67,13 +69,18 @@ Global
6769
{453E1365-83C2-46B6-B8E0-728B778CA1A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
6870
{453E1365-83C2-46B6-B8E0-728B778CA1A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
6971
{453E1365-83C2-46B6-B8E0-728B778CA1A7}.Release|Any CPU.Build.0 = Release|Any CPU
72+
{1077A08A-AB90-4286-BB0C-0F2E9D620595}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
73+
{1077A08A-AB90-4286-BB0C-0F2E9D620595}.Debug|Any CPU.Build.0 = Debug|Any CPU
74+
{1077A08A-AB90-4286-BB0C-0F2E9D620595}.Release|Any CPU.ActiveCfg = Release|Any CPU
75+
{1077A08A-AB90-4286-BB0C-0F2E9D620595}.Release|Any CPU.Build.0 = Release|Any CPU
7076
EndGlobalSection
7177
GlobalSection(SolutionProperties) = preSolution
7278
HideSolutionNode = FALSE
7379
EndGlobalSection
7480
GlobalSection(NestedProjects) = preSolution
7581
{CEF0739E-BD49-466E-9F8D-226C9C474DB4} = {B18FC4F9-E13F-437F-A8DB-4783E9C0F356}
7682
{453E1365-83C2-46B6-B8E0-728B778CA1A7} = {875975E4-796F-4181-BACE-7DC71CE35D1F}
83+
{1077A08A-AB90-4286-BB0C-0F2E9D620595} = {875975E4-796F-4181-BACE-7DC71CE35D1F}
7784
EndGlobalSection
7885
GlobalSection(ExtensibilityGlobals) = postSolution
7986
SolutionGuid = {052B6168-274F-43B0-B3F0-24F5C5D4BE58}

VB/FashionMnistVB/FashionMnist.vb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Imports System
2+
Imports Gradient
3+
Imports SharPy.Runtime
4+
Imports tensorflow
5+
Imports tensorflow.keras
6+
Imports tensorflow.keras.layers
7+
Imports tensorflow.keras.optimizers
8+
9+
Module Program
10+
Sub Main()
11+
GradientLog.OutputWriter = Console.Out
12+
GradientSetup.UseEnvironmentFromVariable()
13+
14+
' requires Internet connection
15+
Dim data = tf.keras.datasets.fashion_mnist.load_data()
16+
Dim train = data.Item1
17+
Dim trainImages = train.Item1 / 255.0F
18+
Dim trainLabels = train.Item2
19+
Dim test = data.Item2
20+
Dim testImages = test.Item1 / 255.0F
21+
Dim testLabels = test.Item2
22+
23+
Dim shapeArgs = New PythonDict(Of String, Object) From {{"input_shape", (28, 28)}}
24+
Dim model = New Sequential(New Layer() {
25+
New Flatten(kwargs:=shapeArgs),
26+
New Dense(units:=128, activation:=tf.nn.leaky_relu_fn),
27+
New Dense(units:=10, activation:=tf.nn.softmax_fn)
28+
})
29+
30+
model.compile(
31+
optimizer:=New Adam(),
32+
loss:="sparse_categorical_crossentropy",
33+
metrics:=New Object() {"accuracy"})
34+
35+
36+
model.fit(trainImages, trainLabels, epochs:=5)
37+
38+
Dim evaluationResult = model.evaluate(testImages, testLabels)
39+
Dim accuracy = evaluationResult(1)
40+
Console.WriteLine($"Test accuracy: {accuracy}")
41+
End Sub
42+
End Module
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<RootNamespace>FashionMnistVB</RootNamespace>
6+
<TargetFramework>netcoreapp2.2</TargetFramework>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Gradient" Version="0.1.10-tech-preview5.1.1" />
11+
</ItemGroup>
12+
13+
</Project>

0 commit comments

Comments
 (0)