Image to Integer
Basic Machine Learning in F# and Dynamo
Inspiration for the node and source of code
namespace integerImage
open System.IO
module integerML =
type Example = {
Label : int
Pixels : int []
}
let readExamples path =
path
|> File.ReadAllLines
|> Array.map (fun line -> line.Split ',')
|> Array.map (fun line -> line |> Array.map int)
|> Array.map (fun line -> {Label = line.[0]; Pixels = line.[1..]} )
let distance (img1 : int[]) (img2 : int[]) =
Array.map2 (fun pix1 pix2 -> abs(pix1 - pix2)) img1 img2
|> Array.sum
let classify (img : int[]) =
let bestMatch =
readExamples (__SOURCE_DIRECTORY__ + "/train.csv")
|> Array.minBy (fun x -> distance x.Pixels img)
bestMat
// Some codepublic class IntImg
{
private IntImg() { }
public static int intFrmImg(int[] tst)
{
return integerImage.integerML.classify(tst);
}
}
MNIST: 60,000 hand written number images
Training Set Source
ML.zip
90MB
Binary
Copy link