1 people like it.

Configure F# Interactive to use Microsoft.ML.Net

Updated to support the new Visual Studio project format where all packages are stored in a common location outside of the solution directory, namely: 'c:/users/%UserName%/.nuget'

  1: 
  2: 
  3: 
  4: 
  5: 
  6: 
  7: 
  8: 
  9: 
 10: 
 11: 
 12: 
 13: 
 14: 
 15: 
 16: 
 17: 
 18: 
 19: 
 20: 
 21: 
 22: 
 23: 
 24: 
 25: 
 26: 
 27: 
 28: 
 29: 
 30: 
 31: 
 32: 
 33: 
 34: 
 35: 
 36: 
 37: 
 38: 
 39: 
 40: 
 41: 
 42: 
 43: 
 44: 
 45: 
 46: 
 47: 
 48: 
 49: 
 50: 
 51: 
 52: 
 53: 
 54: 
 55: 
 56: 
 57: 
 58: 
 59: 
 60: 
 61: 
 62: 
 63: 
 64: 
 65: 
 66: 
 67: 
 68: 
 69: 
 70: 
 71: 
 72: 
 73: 
 74: 
 75: 
 76: 
 77: 
 78: 
 79: 
 80: 
 81: 
 82: 
 83: 
 84: 
 85: 
 86: 
 87: 
 88: 
 89: 
 90: 
 91: 
 92: 
 93: 
 94: 
 95: 
 96: 
 97: 
 98: 
 99: 
100: 
101: 
102: 
103: 
104: 
105: 
106: 
107: 
108: 
109: 
110: 
111: 
112: 
//as of ML.Net 1.7 with new Project types
//Updated to reference packages from 'c:\users\%UserName%\.nuget'

(* Script to generate: 
    a) lib references for ML dlls
    b) code that adds the required native libraries to Path

open System
open System.IO
open System.Collections.Generic

let __PKG_ROOT__ = Path.Combine( @"C:\Users\",Environment.UserName,".nuget")

let includeSet = 
    [ 
        "System.Collections.Immutable"
        "System.Runtime.CompilerServices.Unsafe"
        "System.Memory"
        "System.Numerics.Vector"
        "Microsoft.ML"
        "IronSnappy"
        "Parquet"
    ]
    |> List.map (fun x->x.ToLower())

let excludeSet = 
    [                //exclude files that may get caught in the includeSet filter
         //"LightGbm.2.2.3"
        "Mkl.Redist"
        "ML.OnnxRuntime"
        "Probabilistic.Visualizers"
    ]
    |> List.map (fun x->x.ToLower())

let dirs = Directory.EnumerateDirectories(__PKG_ROOT__ + @"\packages")  |> Seq.map (fun x->x.ToLower())
let comp a b = Comparer<string>.Default.Compare(a, b) //> 0// String.Compare(a,b,StringComparison.OrdinalIgnoreCase)

;;
let dirVers =
    dirs
    //|> Seq.map (fun d->d.Replace()) 
    |> Seq.filter(fun dir -> includeSet |> List.exists(fun y -> dir.Contains(y)))
    |> Seq.filter(fun dir -> excludeSet |> List.exists(fun y -> dir.Contains(y)) |> not)
    |> Seq.map(fun dir -> 
        let ver = Directory.GetDirectories(dir) |> Seq.sortWith comp |> Seq.last
        Path.Combine(dir,ver))

    
dirVers 
|> Seq.collect(fun dir -> 
    let p = Path.Combine(dir,"lib","netstandard2.0") 
    Directory.GetFiles(p,"*.dll"))
|> Seq.map (fun path ->  path.Replace(__PKG_ROOT__+ @"\",""))
|> Seq.map (fun path -> sprintf "#r @\"%s\"" path)
|> Seq.iter (printfn "%s")

;;
let platform = @"win-x64"
let nativeLibs = 
    dirVers
    |> Seq.collect(fun dir -> 
        let p1 = Path.Combine(dir,"runtimes",platform,"native")
        let p2 = Path.Combine(dir,"runtimes",platform,"nativeassets","netstandard2.0")
        [p1;p2]
        |> Seq.collect (fun p ->
            if Directory.Exists p then Directory.GetFiles(p,"*.dll")
            else Array.empty))
    |> Seq.toList
;;
nativeLibs |> Seq.iter (printfn """+ ";" + "%s" """)
*)


#r "netstandard"
//need specific version otherwise fsi will bind to system versions
#r @"c:\users\admin\.nuget\packages\ironsnappy\1.2.4\lib\netstandard2.0\IronSnappy.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml\1.5.2\lib\netstandard2.0\Microsoft.ML.Core.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml\1.5.2\lib\netstandard2.0\Microsoft.ML.Data.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml\1.5.2\lib\netstandard2.0\Microsoft.ML.KMeansClustering.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml\1.5.2\lib\netstandard2.0\Microsoft.ML.PCA.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml\1.5.2\lib\netstandard2.0\Microsoft.ML.StandardTrainers.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml\1.5.2\lib\netstandard2.0\Microsoft.ML.Transforms.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.automl\0.17.2\lib\netstandard2.0\Microsoft.ML.AutoML.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.cpumath\1.5.2\lib\netstandard2.0\Microsoft.ML.CpuMath.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.dataview\1.5.2\lib\netstandard2.0\Microsoft.ML.DataView.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.fasttree\1.5.2\lib\netstandard2.0\Microsoft.ML.FastTree.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.imageanalytics\1.5.2\lib\netstandard2.0\Microsoft.ML.ImageAnalytics.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.lightgbm\1.5.2\lib\netstandard2.0\Microsoft.ML.LightGbm.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.mkl.components\1.5.2\lib\netstandard2.0\Microsoft.ML.Mkl.Components.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.parquet\0.17.2\lib\netstandard2.0\Microsoft.ML.Parquet.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.recommender\0.17.2\lib\netstandard2.0\Microsoft.ML.Recommender.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.tensorflow\1.5.2\lib\netstandard2.0\Microsoft.ML.TensorFlow.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.timeseries\1.5.2\lib\netstandard2.0\Microsoft.ML.TimeSeries.dll"
#r @"c:\users\admin\.nuget\packages\microsoft.ml.vision\1.5.2\lib\netstandard2.0\Microsoft.ML.Vision.dll"
#r @"c:\users\admin\.nuget\packages\parquet.net\3.7.7\lib\netstandard2.0\Parquet.dll"
#r @"c:\users\admin\.nuget\packages\system.collections.immutable\5.0.0-preview.6.20305.6\lib\netstandard2.0\System.Collections.Immutable.dll"
#r @"c:\users\admin\.nuget\packages\system.memory\4.5.4\lib\netstandard2.0\System.Memory.dll"
#r @"c:\users\admin\.nuget\packages\system.numerics.vectors\4.5.0\lib\netstandard2.0\System.Numerics.Vectors.dll"
#r @"c:\users\admin\.nuget\packages\system.runtime.compilerservices.unsafe\5.0.0-preview.6.20305.6\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll"

open System
let path = Environment.GetEnvironmentVariable("path")

let path' = 
    path 
    + ";" + "c:\users\admin\.nuget\packages\microsoft.ml\1.5.2\runtimes\win-x64\native\LdaNative.dll" 
    + ";" + "c:\users\admin\.nuget\packages\microsoft.ml.cpumath\1.5.2\runtimes\win-x64\nativeassets\netstandard2.0\CpuMathNative.dll" 
    + ";" + "c:\users\admin\.nuget\packages\microsoft.ml.fasttree\1.5.2\runtimes\win-x64\native\FastTreeNative.dll" 
    + ";" + "c:\users\admin\.nuget\packages\microsoft.ml.mkl.components\1.5.2\runtimes\win-x64\native\SymSgdNative.dll" 
    + ";" + "c:\users\admin\.nuget\packages\microsoft.ml.recommender\0.17.2\runtimes\win-x64\native\MatrixFactorizationNative.dll" 

Environment.SetEnvironmentVariable("path",path')
namespace System
val path : string
type Environment =
  static member CommandLine : string
  static member CurrentDirectory : string with get, set
  static member CurrentManagedThreadId : int
  static member Exit : exitCode:int -> unit
  static member ExitCode : int with get, set
  static member ExpandEnvironmentVariables : name:string -> string
  static member FailFast : message:string -> unit + 2 overloads
  static member GetCommandLineArgs : unit -> string[]
  static member GetEnvironmentVariable : variable:string -> string + 1 overload
  static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
  ...
  nested type SpecialFolder
  nested type SpecialFolderOption
Environment.GetEnvironmentVariable(variable: string) : string
Environment.GetEnvironmentVariable(variable: string, target: EnvironmentVariableTarget) : string
val path' : string
Environment.SetEnvironmentVariable(variable: string, value: string) : unit
Environment.SetEnvironmentVariable(variable: string, value: string, target: EnvironmentVariableTarget) : unit

More information

Link:http://fssnip.net/7Wi
Posted:19 days ago
Author:Faisal Waris
Tags: machine learning , ml.net