简体   繁体   中英

Tensorflow: How can I extract image features from a specific layer of a pre-trained CNN?

I have a pre-trained CNN model as a .pb file. I can load the model and extract the final vector from the last layer for all images. Now I would like to extract the vector coming from a specific layer and not the final for my images. I am using an import_graph_def function to load the model and I don't know the names of the layers because .pb file is large and I can't open it.

How can I run one part of the model and not the whole in order to get vectors until the layer I want?

One approach other than what was mentioned by Peter Hawkins, to use tf.Graph.get_operations() in the comments is to use tensorboard to find the name of the layer you would like to extract from.

From there you can just use

graph.get_tensor_by_name("import/layer_name")

to extract out whichever features you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM