Insightface: confused with args

Created on 8 Jul 2019  路  3Comments  路  Source: deepinsight/insightface

hi
i need some help to figure out the args in face embedding and Face model example
especially i would like to know what are and how to use this :
prefix
epoch
ctx
layer
than k you

Most helpful comment

Hi @Alloshee,

I'm not sure what layer is used for.

But prefix is meant to be the path to your model, with the prefix of the model name included. For example if the .params and .json files of your model are located in /xxx/insightface-master/models/retinaface-R50/R50-0000.params and /xxx/insightface-master/models/retinaface-R50/R50-symbol.json, then prefix will have to be /xxx/insightface-master/models/retinaface-R50/R50.

The epoch argument is used when you have a model that has already been trained. I think the number of epochs is basically the number if iterations of training the model has gone through. In this code, when you train a model, for let's say 1234 epochs (so 1234 iterations on the training dataset), the model will be saved in a .params file named prefix-1234.params. And when you launch a test script, setting the epoch argument to a certain value will tell the code to load the model corresponding to this value.

A concrete example : setting the prefix value to /xxx/insightface-master/models/retinaface-R50/R50 and the epoch value to 1234 will tell the program to load the model which .json file is /xxx/insightface-master/models/retinaface-R50/R50-symbol.json and which .params file is /xxx/insightface-master/models/retinaface-R50/R50-1234.params.

And finally, the ctx argument is used to tell your program if you want to use the CPU or a GPU for execution. Setting the ctx argument to a positive value (>= 0) will tell the program to use the GPU that is identified by the value of ctx (for example setting ctx to 2 will tell the program to run on the GPU number 2), and setting ctx to a strictly negative value will tell the program to run on CPU.

I hope I didn't say anything completely wrong, and that this answered your question, apart from the layer argument that is.

All 3 comments

Hi @Alloshee,

I'm not sure what layer is used for.

But prefix is meant to be the path to your model, with the prefix of the model name included. For example if the .params and .json files of your model are located in /xxx/insightface-master/models/retinaface-R50/R50-0000.params and /xxx/insightface-master/models/retinaface-R50/R50-symbol.json, then prefix will have to be /xxx/insightface-master/models/retinaface-R50/R50.

The epoch argument is used when you have a model that has already been trained. I think the number of epochs is basically the number if iterations of training the model has gone through. In this code, when you train a model, for let's say 1234 epochs (so 1234 iterations on the training dataset), the model will be saved in a .params file named prefix-1234.params. And when you launch a test script, setting the epoch argument to a certain value will tell the code to load the model corresponding to this value.

A concrete example : setting the prefix value to /xxx/insightface-master/models/retinaface-R50/R50 and the epoch value to 1234 will tell the program to load the model which .json file is /xxx/insightface-master/models/retinaface-R50/R50-symbol.json and which .params file is /xxx/insightface-master/models/retinaface-R50/R50-1234.params.

And finally, the ctx argument is used to tell your program if you want to use the CPU or a GPU for execution. Setting the ctx argument to a positive value (>= 0) will tell the program to use the GPU that is identified by the value of ctx (for example setting ctx to 2 will tell the program to run on the GPU number 2), and setting ctx to a strictly negative value will tell the program to run on CPU.

I hope I didn't say anything completely wrong, and that this answered your question, apart from the layer argument that is.

hi, after hours of trail i got this :
yes prefix is the model path but without the epoch number
in my case the model name is model-0000 where epoch is 0000 so i think epoch is for people who would like to fine tune the model of train it from scratch
layer is the output layer you wish to use i used fc1 which refers to fully connected layer number 1 but i didn't know what other layers can be used any way no other one worked for me (i am using a pretrained model)
ctx is the cpu/gpu config but i had to use mx.cpu() or mx.gpu() (not numbers) to make this work
please correct me if i am wrong
finally a usage documentation would be helpful ^_^

Hi again,

thanks for explaining what layer is, I'm not sure I'll ever need to use an other layer but it's always good to know.

And yes, the ctx argument in itself won't tell MXNet whether to use CPU or a GPU for execution. But, in functions, ctx is usually used in an if clause that would typically look like this :

    if ctx >= 0:
            self.ctx = mx.gpu(ctx)
    else:
            self.ctx = mx.cpu()

(Where self.ctxwould be the ctx attribute of the object that is created by the code).

So you are right in saying that to create an execution context you indeed have to call mx.cpu() or mx.gpu() (which, without any explicit parameter, means mx.gpu(0) if I'm not mistaken).
What I meant in my previous message is that the ctx parameter of predefined functions (such as the constructor for a RetinaFace object) is meant to be a number, as shown in the code above. But I agree that my formulation might have been misleading.

A usage documentation would indeed be great, but I understand that they prefer to focus on research, and I think their code is still largely usable and adaptable with a bit of looking around.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xysong1201 picture xysong1201  路  4Comments

shenriver picture shenriver  路  5Comments

mdv3101 picture mdv3101  路  5Comments

WIll-Xu35 picture WIll-Xu35  路  3Comments

lzg188 picture lzg188  路  5Comments