简体   繁体   中英

How to remove the last layer of pretrained model in tensorflow

I want to remove the last layer of sports1m_finetuning_ucf101.model in C3D tensorflow ( https://github.com/hx173149/C3D-tensorflow ) and add my own classifier layer for my dataset which has different number of labels than the model. I know in Keras i can use the pop method but here I don't know how to load the model in tensorflow and remove the last layer. Is there anyone to tell me how I can do it?

In tensorflow editing model is not recommended. What you can probably do is that you can set the output based on the layer name.

for layer in model.layers:
    if layer.name == desired_layer_name:
        output = layer.output
        break

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