DlibDotNet
DlibDotNet copied to clipboard
LossMetric.Deserialize() DlibDotNet.SerializationException
I use DlibDotNet.CUDA101 19.21.0.20210302.
When I try to deserialize a model that was trained using dlib 19.21 I get this exception:
DlibDotNet.SerializationException: 'An error occurred while trying to read the first object from the file C:\Work\models\metric_network_resnet2.dat.
ERROR: Unexpected version found while deserializing dlib::input_rgb_image_sized.
The model: https://drive.google.com/file/d/10cKyFdR9f-Xpdx-5gonnfsRZvO3z6sIp/view?usp=sharing
@davidrasmussen This model is generated by you? If so, how do you create it?
Metric Layer of DlibDotNet supports only https://github.com/takuya-takeuchi/DlibDotNet/blob/master/src/DlibDotNet.Native.Dnn/dlib/dnn/loss/metric/defines.h
I guess you create original layers. If so, you have to modify or add new layer definition to DlibDotNet.Native.Dnn or new libs. I recommend creating new libs like https://github.com/takuya-takeuchi/FaceRecognitionDotNet/tree/master/src/AgeClassification
FYI https://github.com/davisking/dlib/issues/575
@takuya-takeuchi I trained it myself using https://github.com/davisking/dlib/blob/master/examples/dnn_metric_learning_on_images_ex.cpp#L175
@davidrasmussen Your model does not equal to https://github.com/takuya-takeuchi/DlibDotNet/blob/8c1cbab8048e07fb74c6509401b68271a5f69bdf/src/DlibDotNet.Native.Dnn/dlib/dnn/loss/metric/defines.h#L32
using net_type = loss_metric<fc_no_bias<128,avg_pool_everything<
level0<
level1<
level2<
level3<
level4<
max_pool<3,3,2,2,relu<bn_con<con<32,7,7,2,2,
input_rgb_image
>>>>>>>>>>>>;
using anet_type = loss_metric<fc_no_bias<128,avg_pool_everything<
alevel0<
alevel1<
alevel2<
alevel3<
alevel4<
max_pool<3,3,2,2,relu<affine<con<32,7,7,2,2,
input_rgb_image_sized<150>
>>>>>>>>>>>>;
Dlib uses numerous no-parameterize template. So .NET wrapper have to define only specific type definition. Therefore, we can not use flexible usage like .net generic.
You have to define your model on DlibDotNet.Native.Dnn or new libs.
@takuya竹内我自己用https://github.com/davisking/dlib/blob/master/examples/dnn_metric_learning_on_images_ex.cpp#L175 训练它 Can you tell me how it was solved? I urgently need to train a model with dlib now.
@wzh52112 wrong mention
@wzh52112错误提及
An error is reported when running the model
@wzh52112 you go wrong. check your this mention id and remove it. im not takeuchi.
The official dataset is used, but the training is not very good
@wzh52112 you go wrong. check your this mention id and remove it. im not Takeuchi.
Or is it a mistake in importing the model?I know you're not Takeuchi.And thanks
@wzh52112 I guess you used wrong version of model file. Where model files did you used?
Current dlibdotnet expect that
using anet_type = loss_metric<fc_no_bias<128,avg_pool_everything<
alevel0<
alevel1<
alevel2<
alevel3<
alevel4<
max_pool<3,3,2,2,relu<affine<con<32,7,7,2,2,
input_rgb_image_sized<150> // new dlib does not use 150!!
>>>>>>>>>>>>;
And we have to modify it or add new type.
Thanks, I've solved it