Image to Integer
Basic Machine Learning in F# and Dynamo
Inspiration for the node and source of code
1
namespace integerImage
2
open System.IO
3
module integerML =
4
type Example = {
5
Label : int
6
Pixels : int []
7
}
8
9
let readExamples path =
10
path
11
|> File.ReadAllLines
12
|> Array.map (fun line -> line.Split ',')
13
|> Array.map (fun line -> line |> Array.map int)
14
|> Array.map (fun line -> {Label = line.[0]; Pixels = line.[1..]} )
15
16
let distance (img1 : int[]) (img2 : int[]) =
17
Array.map2 (fun pix1 pix2 -> abs(pix1 - pix2)) img1 img2
18
|> Array.sum
19
20
let classify (img : int[]) =
21
let bestMatch =
22
readExamples (__SOURCE_DIRECTORY__ + "/train.csv")
23
|> Array.minBy (fun x -> distance x.Pixels img)
24
bestMat
Copied!
1
// Some codepublic class IntImg
2
{
3
private IntImg() { }
4
public static int intFrmImg(int[] tst)
5
{
6
return integerImage.integerML.classify(tst);
7
}
8
}
Copied!
MNIST: 60,000 hand written number images
Training Set Source
ML.zip
90MB
Binary
Last modified 1mo ago
Copy link