苏三福 2019-01-06 15:07 采纳率: 0%
浏览 3607
已结题

tensorflow 怎么预训练 微调自己的数据

我在github上找了一个代码:https://github.com/MrCPlusPlus/MobileFaceNet_Tensorflow_Pretrain/blob/master/train_nets.py

我想要尝试训练自己的数据集,我知道好像只要加几行代码就行, 但是我小白不知道怎么加,好像只要把最后一层输出层改下,其它层固定就可以了, 请大家帮忙,谢谢!

我自己瞎折腾报错 :Key Mean_1/avg not found in checkpoint, 不知道为什么??
最后一层好像是这个:
fc7/biases (DT_FLOAT) [85164]
fc7/weights (DT_FLOAT) [128,85164]
saver = tf.train.Saver(tf.trainable_variables(), max_to_keep=args.saver_maxkeep)

    # init all variables
    sess.run(tf.global_variables_initializer())
    sess.run(tf.local_variables_initializer())

    # load pretrained model
    if pretrained_model:
        print('Restoring pretrained model: %s' % pretrained_model)
        ckpt = tf.train.get_checkpoint_state(pretrained_model)
        #tf.reset_default_graph()
        saver.restore(sess, ckpt.model_checkpoint_path)
        print('Successfully restored!')

        exclude = ['fc7']
        variables_to_restore = slim.get_variables_to_restore(exclude=exclude)
        init_fn = slim.assign_from_checkpoint_fn('./output/ckpt_best/MobileFaceNet_pretrain.ckpt',
                                                 variables_to_restore)
        init_fn(sess)

我加的代码是这样的,但是报错lhs=[1156], rhs=[85164 也就是说原来模型的输出
和自己训练的数据集类数不同, 但是我不是已经排除模型最后一层了吗 ?

我找不到的变量是这种形式的,好像是global variables中的:
fc7/weights/ExponentialMovingAverage:0
fc7/biases/ExponentialMovingAverage:0

不同于网络结构中打出来的变量:
fc7/biases (DT_FLOAT) [85164]
fc7/weights (DT_FLOAT) [128,85164]

还有报错很多变量未初始化,但是我也添加了初始化代码啊
很郁闷. 请大家帮帮忙,谢谢了.

或者可以加我微信沟通:1886 2232 309 ,谢谢! 急 急急!

  • 写回答

1条回答

  • ethanzhangg 2019-01-09 13:33
    关注
    variables_to_restore = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)
    variables_to_restore=[v for v in variables_to_restore if 'Mean' not in v.name]
    restorer = tf.train.Saver(variables_to_restore)
    restorer.restore(sess, ckpt.model_checkpoint_path)
    

    类似这样子

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型