logy:

i need to extract the feature by ignoring the layer of classification


I think this code is doing what you intend to do (i.e., extract features without classification layer).
Bad numbers might have possibly a different reason than this code I guess.