pretrain model
1 加载预训练模型注意:
I'm not sure which file you are trying to load. I recently tried loading a pretrained model with train_tripletloss.py and worked out fine. Then I used
--pretrained_model ~/models/20170214-092102/model-20170214-092102.ckpt-80000
But it should be noted that there is no file named model-20170214-092102.ckpt-80000 in the 20170214-092102 directory, so Tensorflow adds .data-00000-of-00001 before restoring. These are the files in the directory:
-rwxrwxrwx 1 root root 96689276 feb 14 18:49 model-20170214-092102.ckpt-80000.data-00000-of-00001
-rwxrwxrwx 1 root root 22478 feb 14 18:49 model-20170214-092102.ckpt-80000.index
-rwxrwxrwx 1 root root 19991968 feb 14 09:29 model-20170214-092102.meta
2 Finetune模型(需要修改):
I had the same problems, and solved by changing the code
" saver = tf.train.Saver(tf.trainable_variables(), max_to_keep=3) "
as follows:
all_vars = tf.trainable_variables()
var_to_restore = [v for v in all_vars if not v.name.startswith('Logits')]
saver = tf.train.Saver(var_to_restore)
which gets a list of all of the variables in the model and filter out the variables of the last layer.