4
4
5
5
using Microsoft . ML . Core . Data ;
6
6
using Microsoft . ML . Data . StaticPipe . Runtime ;
7
- using Microsoft . ML . Runtime ;
8
- using Microsoft . ML . Runtime . Data ;
9
- using Microsoft . ML . Runtime . Data . IO ;
10
7
using Microsoft . ML . Runtime . Internal . Utilities ;
11
- using Microsoft . ML . Runtime . Model ;
12
8
using System ;
13
9
using System . Collections . Generic ;
14
10
using System . Linq ;
15
11
16
- [ assembly: LoadableClass ( typeof ( ConcatTransformer ) , null , typeof ( SignatureLoadModel ) ,
17
- "Concat Transformer Wrapper" , ConcatTransformer . LoaderSignature ) ]
18
-
19
12
namespace Microsoft . ML . Runtime . Data
20
13
{
21
14
public sealed class ConcatEstimator : IEstimator < ITransformer >
@@ -41,11 +34,7 @@ public ConcatEstimator(IHostEnvironment env, string name, params string[] source
41
34
public ITransformer Fit ( IDataView input )
42
35
{
43
36
_host . CheckValue ( input , nameof ( input ) ) ;
44
-
45
- var xf = new ConcatTransform ( _host , input , _name , _source ) ;
46
- var empty = new EmptyDataView ( _host , input . Schema ) ;
47
- var chunk = ApplyTransformUtils . ApplyAllTransformsToData ( _host , xf , empty , input ) ;
48
- return new ConcatTransformer ( _host , chunk ) ;
37
+ return new ConcatTransform ( _host , _name , _source ) ;
49
38
}
50
39
51
40
private bool HasCategoricals ( SchemaShape . Column col )
@@ -123,90 +112,6 @@ public SchemaShape GetOutputSchema(SchemaShape inputSchema)
123
112
}
124
113
}
125
114
126
- // REVIEW: Note that the presence of this thing is a temporary measure only.
127
- // If it is cleaned up by code complete so much the better, but if not we will
128
- // have to wait a little bit.
129
- internal sealed class ConcatTransformer : ITransformer , ICanSaveModel
130
- {
131
- public const string LoaderSignature = "ConcatTransformWrapper" ;
132
- private const string TransformDirTemplate = "Step_{0:000}" ;
133
-
134
- private readonly IHostEnvironment _env ;
135
- private readonly IDataView _xf ;
136
-
137
- internal ConcatTransformer ( IHostEnvironment env , IDataView xf )
138
- {
139
- _env = env ;
140
- _xf = xf ;
141
- }
142
-
143
- public ISchema GetOutputSchema ( ISchema inputSchema )
144
- {
145
- var dv = new EmptyDataView ( _env , inputSchema ) ;
146
- var output = ApplyTransformUtils . ApplyAllTransformsToData ( _env , _xf , dv ) ;
147
- return output . Schema ;
148
- }
149
-
150
- public void Save ( ModelSaveContext ctx )
151
- {
152
- ctx . CheckAtModel ( ) ;
153
- ctx . SetVersionInfo ( GetVersionInfo ( ) ) ;
154
-
155
- var dataPipe = _xf ;
156
- var transforms = new List < IDataTransform > ( ) ;
157
- while ( dataPipe is IDataTransform xf )
158
- {
159
- // REVIEW: a malicious user could construct a loop in the Source chain, that would
160
- // cause this method to iterate forever (and throw something when the list overflows). There's
161
- // no way to insulate from ALL malicious behavior.
162
- transforms . Add ( xf ) ;
163
- dataPipe = xf . Source ;
164
- Contracts . AssertValue ( dataPipe ) ;
165
- }
166
- transforms . Reverse ( ) ;
167
-
168
- ctx . SaveSubModel ( "Loader" , c => BinaryLoader . SaveInstance ( _env , c , dataPipe . Schema ) ) ;
169
-
170
- ctx . Writer . Write ( transforms . Count ) ;
171
- for ( int i = 0 ; i < transforms . Count ; i ++ )
172
- {
173
- var dirName = string . Format ( TransformDirTemplate , i ) ;
174
- ctx . SaveModel ( transforms [ i ] , dirName ) ;
175
- }
176
- }
177
-
178
- private static VersionInfo GetVersionInfo ( )
179
- {
180
- return new VersionInfo (
181
- modelSignature : "CCATWRPR" ,
182
- verWrittenCur : 0x00010001 , // Initial
183
- verReadableCur : 0x00010001 ,
184
- verWeCanReadBack : 0x00010001 ,
185
- loaderSignature : LoaderSignature ) ;
186
- }
187
-
188
- public ConcatTransformer ( IHostEnvironment env , ModelLoadContext ctx )
189
- {
190
- ctx . CheckAtModel ( GetVersionInfo ( ) ) ;
191
- int n = ctx . Reader . ReadInt32 ( ) ;
192
-
193
- ctx . LoadModel < IDataLoader , SignatureLoadDataLoader > ( env , out var loader , "Loader" , new MultiFileSource ( null ) ) ;
194
-
195
- IDataView data = loader ;
196
- for ( int i = 0 ; i < n ; i ++ )
197
- {
198
- var dirName = string . Format ( TransformDirTemplate , i ) ;
199
- ctx . LoadModel < IDataTransform , SignatureLoadDataTransform > ( env , out var xf , dirName , data ) ;
200
- data = xf ;
201
- }
202
-
203
- _env = env ;
204
- _xf = data ;
205
- }
206
-
207
- public IDataView Transform ( IDataView input ) => ApplyTransformUtils . ApplyAllTransformsToData ( _env , _xf , input ) ;
208
- }
209
-
210
115
/// <summary>
211
116
/// The extension methods and implementation support for concatenating columns together.
212
117
/// </summary>
0 commit comments