DlibDotNet icon indicating copy to clipboard operation
DlibDotNet copied to clipboard

LossMetric.Deserialize() DlibDotNet.SerializationException

Open davidrasmussen opened this issue 3 years ago • 4 comments

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 avatar Mar 20 '21 14:03 davidrasmussen

@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

takuya-takeuchi avatar Mar 20 '21 14:03 takuya-takeuchi

FYI https://github.com/davisking/dlib/issues/575

takuya-takeuchi avatar Mar 20 '21 14:03 takuya-takeuchi

@takuya-takeuchi I trained it myself using https://github.com/davisking/dlib/blob/master/examples/dnn_metric_learning_on_images_ex.cpp#L175

davidrasmussen avatar Mar 20 '21 14:03 davidrasmussen

@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-takeuchi avatar Mar 20 '21 15:03 takuya-takeuchi

@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 avatar Nov 27 '22 00:11 wzh52112

@wzh52112 wrong mention

takuya avatar Nov 27 '22 07:11 takuya

5c37ad05a375b0547714000f43335f1

@wzh52112错误提及

An error is reported when running the model

wzh52112 avatar Nov 27 '22 07:11 wzh52112

@wzh52112 you go wrong. check your this mention id and remove it. im not takeuchi.

takuya avatar Nov 27 '22 07:11 takuya

image 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 avatar Nov 27 '22 08:11 wzh52112

@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.

takuya-takeuchi avatar Nov 28 '22 03:11 takuya-takeuchi

Thanks, I've solved it

wzh52112 avatar Dec 01 '22 02:12 wzh52112