类型错误:无法pickle_螺纹锁紧从KerasOpenface项目转储nn4_small2_预训练模型时的对象

2024-09-29 01:38:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用KerasOpenFace项目的预训练模型实现面部识别,Martin Krasser对此进行了令人惊讶的解释和实现

The OpenFace project provides pre-trained models that were trained with the public face recognition datasets FaceScrub and CASIA-WebFace. The Keras-OpenFace project converted the weights of the pre-trained nn4.small2.v1 model to CSV files which were then converted here to a binary format that can be loaded by Keras with load_weights

代码很简单:

nn4_small2_pretrained = create_model()
nn4_small2_pretrained.load_weights('weights/nn4.small2.v1.h5')

在查看错误以深入了解create_model()中发生的情况之前,可以先浏览代码here

现在我需要nn4_small2_pretrained在我的预测.py文件(它最初是火车.py训练我的自定义图像),但如果我这样做

^{pr2}$

或者写代码

nn4_small2_pretrained = create_model()
nn4_small2_pretrained.load_weights('weights/nn4.small2.v1.h5')

再重复一遍,然后预测文件将花费大量时间来编译,因为它再次经历整个过程。为了解决这个问题,我尝试将模型转储到pickle文件中,如下所示

# Save the nn4 pretrained model to pickle file
f = open('pretrained_model.pickle', 'wb')
pickle.dump(nn4_small2_pretrained, f)

当我运行代码时,它会给我这个错误

    File "train.py", line 24, in <module>
        pickle.dump(nn4_small2_pretrained, f)
TypeError: can't pickle _thread.lock objects

我最近刚开始学习Deel模型和Pickle,但我不知道出了什么问题。 任何帮助都将不胜感激。在

谢谢。在


Tags: theto代码py模型modelcreateload