Using this repo you can extract features from each layer from pytorch Dense network.
Six feature maps are extracted in each step. The feature maps contains three 'families':
- Architectural
- Weights
- Activations
For each family type, 2 feature maps are constructed; one for the whole network and one for the wanted layer.
The layer's architectural feature map is represented similar to the network's architecture fm, but contains only one row according to the selected layer.
The main class is FeatureExtractor
. This class is initlized with the model, the train data (without the target column) and the device (cpu/gpu)
The following code created a FeatureExtractor
object and extract features from the first hidden layer.
feature_extractor = FeatureExtractor(self.loaded_model.model, self.X_data._values, device)
fm = feature_extractor.extract_features(0)