Hi I’ve the need to get feature vector of the intermediate layer of pretrained ciphar 10 dataset. However no sample code is available. I came across this documentation
[class gluoncv.nn.feature.
FeatureExtractor
( network , outputs , inputs=‘data’ , pretrained=False , ctx=cpu(0) , **kwargs )]
But not sure how to use it.
Can anyone guide me?
Hi @Apoorva_Rani ,
You can do this using gluon.nn.SymbolBlock
as described here:
For 1. Reading the model zoo documentation should get you most of the way. Here is a complete working example:
import mxnet as mx
from mxnet import gluon, nd
from mxnet.gluon.model_zoo import vision
import numpy as np
import wget
import json
# Get the image net labels
wget.download('https://gist.githubusercontent.com/ThomasDelteil/3bc3a3a7e9601b2a67646b4813981a40/raw/6fe3860887a3ac6ea1d8301531b57603909b6ff3/image_net_labels.json')
categories = json.load(open('image_net_labels.json', 'r'))
# G…
Hoping that this will help you
import mxnet as mx
from gluoncv.model_zoo import get_model
net = get_model('cifar_resnet110_v1', classes=10, pretrained=True, root='./model')
#dummy input data
img = mx.nd.random.uniform(shape=(1,3,32,32))
#example1
net_feature_0 = net.features
output1 = net_feature_0(img)
#example2
net_feature_1 = net.features[:-1]
output2 = net_feature_1(img)
#example3
net_feature_2 = net.features[:-2]
output3 = net_feature_2(img)
Is this helpful for you?