Insightface: How to finetune ?

Created on 19 Nov 2018  ·  7Comments  ·  Source: deepinsight/insightface

Thank you for once again.I have trained se-res50 with ms1m dataset, then I want to train vgg dataset and treat the model of "se-res50-ms1m" as pretrained model ,but the error appear. How to I should modify the code and the error is:
" File "/usr/lib/python2.7/site-packages/mxnet/module/module.py", line 297, in _impl
cache_arr.copyto(arr)
File "/usr/lib/python2.7/site-packages/mxnet/ndarray/ndarray.py", line 2066, in copyto
return _internal._copyto(self, out=other)
File "", line 25, in _copyto
File "/usr/lib/python2.7/site-packages/mxnet/_ctypes/ndarray.py", line 92, in _imperative_invoke
ctypes.byref(out_stypes)))
File "/usr/lib/python2.7/site-packages/mxnet/base.py", line 252, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: [13:54:26] /home/travis/build/dmlc/mxnet-distro/mxnet-build/3rdparty/mshadow/../../src/operator/tensor/../elemwise_op_common.h:133: Check failed: assign(&dattr, (*vec)[i]) Incompatible attr in node at 0-th output: expected [85164,512], got [8631,512]

Stack trace returned 10 entries:
[bt] (0) /usr/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x36bac2) [0x7f6bd78d2ac2]
[bt] (1) /usr/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x36c0a8) [0x7f6bd78d30a8]
[bt] (2) /usr/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x548e23) [0x7f6bd7aafe23]
[bt] (3) /usr/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x54970b) [0x7f6bd7ab070b]
[bt] (4) /usr/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x2fa4692) [0x7f6bda50b692]
[bt] (5) /usr/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x2fae34e) [0x7f6bda51534e]
[bt] (6) /usr/lib/python2.7/site-packages/mxnet/libmxnet.so(+0x2ecc3ab) [0x7f6bda4333ab]
[bt] (7) /usr/lib/python2.7/site-packages/mxnet/libmxnet.so(MXImperativeInvokeEx+0x6f) [0x7f6bda43396f]
[bt] (8) /lib64/libffi.so.6(ffi_call_unix64+0x4c) [0x7f6c07219dcc]
[bt] (9) /lib64/libffi.so.6(ffi_call+0x1f5) [0x7f6c072196f5]
"

Most helpful comment

Delete fc7 weight by calling deploy/model_slim.py

All 7 comments

maybe you should modify vgg dataset's property file from
8631,112,112
to
85164,112,112

I am sorry to bother you.I think that is not caused by the vgg dataset's property. The vgg dataset's property is certainly "8631,112,112" and It is right. How to finetune ourselves dataset with the pretrained model and how to modify the layer of "fc7" or "args.num_classes"?

Delete fc7 weight by calling deploy/model_slim.py

Sorry ,I am still confused to your reply.I don not know how to modify the code of "model_slim.py" and can you tell me clearly?Thanks.
“from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import sys
import os
import argparse
import numpy as np
import mxnet as mx

parser = argparse.ArgumentParser(description='face model slim')

general

parser.add_argument('--model', default='../models/model-r34-amf/model,60', help='path to load model.')
args = parser.parse_args()

_vec = args.model.split(',')
assert len(_vec)==2
prefix = _vec[0]
epoch = int(_vec[1])
print('loading',prefix, epoch)
sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch)
all_layers = sym.get_internals()
sym = all_layers['fc1_output']
dellist = []
for k,v in arg_params.iteritems():
if k.startswith('fc7'):
dellist.append(k)
for d in dellist:
del arg_params[d]
mx.model.save_checkpoint(prefix+"s", 0, sym, arg_params, aux_params)

fc7 means the loss layer behind the network structure or the fully-connected layer belonging to the network structure ?
@nttstar
https://i.loli.net/2018/11/20/5bf375f8a24f7.png

Sorry ,I am still confused to your reply.I don not know how to modify the code of "model_slim.py" and can you tell me clearly?Thanks.
“from future import absolute_import
from future import division
from future import print_function

import sys
import os
import argparse
import numpy as np
import mxnet as mx

parser = argparse.ArgumentParser(description='face model slim')

general

parser.add_argument('--model', default='../models/model-r34-amf/model,60', help='path to load model.')
args = parser.parse_args()

_vec = args.model.split(',')
assert len(_vec)==2
prefix = _vec[0]
epoch = int(_vec[1])
print('loading',prefix, epoch)
sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch)
all_layers = sym.get_internals()
sym = all_layers['fc1_output']
dellist = []
for k,v in arg_params.iteritems():
if k.startswith('fc7'):
dellist.append(k)
for d in dellist:
del arg_params[d]
mx.model.save_checkpoint(prefix+"s", 0, sym, arg_params, aux_params)

I've tried this script and it works!

No need to modify the code of "model_slim.py". Just run this code like this:

python model_slim.py --model ../models/model-r34-amf/model,0

then if you look at the directory../models/model-r34-amf/ there would be two newly created file like this:
image

Then you can use the newly created model file and finetune with different datasets.

@Isaver23 ,thanks a lot .I would try to do it according to your advice but the problem is also solved by renaming the layer of "fc7", similar to caffe.

Was this page helpful?
0 / 5 - 0 ratings