"FeatureExtractor" (Net Encoder)
NetEncoder[{"FeatureExtractor",f}]
represents an encoder that uses the FeatureExtractorFunction f to encode an input.
NetEncoder["FeatureExtractor"]
represents an encoder automatically learned during net training.
NetEncoder[{"FeatureExtractor","method"}]
uses a specific feature extraction method.
Details
- In NetEncoder[{"FeatureExtractor",f}], the FeatureExtractorFunction f should return a numeric vector.
- In NetEncoder["FeatureExtractor"], the extractor is learned on the training data when NetTrain is called on the net containing the encoder. The learned extractor typically returns a numeric vector.
- In NetEncoder[{"FeatureExtractor","method"}], "method" can be any feature extractor method of FeatureExtraction that produces numeric vectors: "StandardizedVector", "IndicatorVector", "TFIDF", "ImageFeatures", "AudioFeatures", "GraphFeatures", etc.
- NetEncoder[…][input] applies the encoder to an input to produce an output.
- NetEncoder[…][{input1,input2,…}] applies the encoder to a list of inputs to produce a list of outputs.
- An encoder can be attached to an input port of a net by specifying "port"NetEncoder[…] when constructing the net.
Examples
Basic Examples (2)
Define a net with a feature extractor that will automatically be learned on data:
net = NetChain[{LinearLayer[], SoftmaxLayer[]}, "Output" -> NetDecoder[{"Class", {"cat", "dog"}}], "Input" -> NetEncoder["FeatureExtractor"]]trained = NetTrain[net, {[image] -> "cat", [image] -> "cat", [image] -> "cat" , [image] -> "dog", [image] -> "dog"}]trained[[image]]Take some numeric vectors of dimension 3:
data = NumericArray[RandomVariate[NormalDistribution[1, 2], {1024, 3}], "Real32"]Train a FeatureExtractorFunction that standardizes this data:
fe = FeatureExtraction[data, "StandardizedVector"]Create a function encoder that applies this dimension reduction:
enc = NetEncoder[{"FeatureExtractor", fe}]Apply the encoder to an input vector:
enc[{1, 0, -1}]It gives the same result as the FeatureExtractorFunction:
fe[{1, 0, -1}]The same NetEncoder can be obtained by using NetTrain:
enc2 = NetEncoder[{"FeatureExtractor", "StandardizedVector"}]enc3 = NetTrain[enc2, data]The encoder can also be attached to a net and trained with the net (in a first phase):
net = NetChain[{LinearLayer["Real"], LogisticSigmoid}, "Input" -> enc2]trained = NetTrain[net, data, LossFunction -> "Output", MaxTrainingRounds -> 10]enc4 = NetExtract[trained, "Input"]enc4[{1, 0, -1}]See Also
NetEncoder NetDecoder NetChain NetGraph FeatureExtraction FeatureExtractorFunction
Net Encoders: Function