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

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)
    

    类似这样子

    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗