9
9
using Microsoft . ML . Calibrators ;
10
10
using Microsoft . ML . Data ;
11
11
using Microsoft . ML . RunTests ;
12
+ using Microsoft . ML . TestFramework ;
12
13
using Microsoft . ML . Trainers . FastTree ;
13
14
using Xunit ;
15
+ using Xunit . Abstractions ;
14
16
15
- namespace Microsoft . ML . Tests . Scenarios . Api
17
+ namespace Microsoft . ML . Functional . Tests
16
18
{
17
- public partial class ApiScenariosTests
19
+ public partial class ModelLoadingTests : BaseTestClass
18
20
{
21
+ public ModelLoadingTests ( ITestOutputHelper output ) : base ( output )
22
+ {
23
+ }
24
+
19
25
private class InputData
20
26
{
21
27
[ LoadColumn ( 0 ) ]
22
- public float Label { get ; set ; }
28
+ public bool Label { get ; set ; }
23
29
[ LoadColumn ( 9 , 14 ) ]
24
30
[ VectorType ( 6 ) ]
25
31
public float [ ] Features { get ; set ; }
@@ -35,23 +41,38 @@ public void LoadModelAndExtractPredictor()
35
41
36
42
// Pipeline.
37
43
var pipeline = ml . BinaryClassification . Trainers . GeneralizedAdditiveModels ( ) ;
38
-
44
+ // Define the same pipeline starting with the loader.
45
+ var pipeline1 = loader . Append ( ml . BinaryClassification . Trainers . GeneralizedAdditiveModels ( ) ) ;
46
+
39
47
// Train.
40
48
var model = pipeline . Fit ( data ) ;
49
+ var model1 = pipeline1 . Fit ( file ) ;
41
50
42
51
// Save and reload.
43
52
string modelPath = GetOutputPath ( FullTestName + "-model.zip" ) ;
44
53
using ( var fs = File . Create ( modelPath ) )
45
54
ml . Model . Save ( data . Schema , model , fs ) ;
55
+ string modelPath1 = GetOutputPath ( FullTestName + "-model1.zip" ) ;
56
+ using ( var fs = File . Create ( modelPath1 ) )
57
+ ml . Model . Save ( model1 , fs ) ;
46
58
47
59
ITransformer loadedModel ;
60
+ IDataLoader < IMultiStreamSource > loadedModel1 ;
48
61
using ( var fs = File . OpenRead ( modelPath ) )
49
62
loadedModel = ml . Model . Load ( fs , out var loadedSchema ) ;
63
+ using ( var fs = File . OpenRead ( modelPath1 ) )
64
+ loadedModel1 = ml . Model . Load ( fs ) ;
50
65
51
66
var gam = ( ( loadedModel as ISingleFeaturePredictionTransformer < object > ) . Model
52
67
as CalibratedModelParametersBase ) . SubModel
53
68
as BinaryClassificationGamModelParameters ;
54
69
Assert . NotNull ( gam ) ;
70
+
71
+ gam = ( ( ( loadedModel1 as CompositeDataLoader < IMultiStreamSource , ITransformer > ) . Transformer . LastTransformer
72
+ as ISingleFeaturePredictionTransformer < object > ) . Model
73
+ as CalibratedModelParametersBase ) . SubModel
74
+ as BinaryClassificationGamModelParameters ;
75
+ Assert . NotNull ( gam ) ;
55
76
}
56
77
57
78
[ Fact ]
0 commit comments