[英]TypeError: can't pickle _thread.lock objects while dumping nn4_small2_pretrained model from Keras-Openface Project
I was trying to implement Facial Recognition using the pretrained models from Keras-Openface Project and amazingly explained and implimented by Martin Krasser here 我正在尝试使用Keras-Openface项目的预训练模型来实现面部识别,并在这里由Martin Krasser进行了令人惊讶的解释和暗示。
The OpenFace project provides pre-trained models that were trained with the public face recognition datasets FaceScrub and CASIA-WebFace. OpenFace项目提供了使用公共面部识别数据集FaceScrub和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 Keras-OpenFace项目将预先训练的nn4.small2.v1模型的权重转换为CSV文件,然后在此处转换为二进制格式,Keras可以使用load_weights加载
The Code is simply : 该代码很简单:
nn4_small2_pretrained = create_model()
nn4_small2_pretrained.load_weights('weights/nn4.small2.v1.h5')
Before going to the error to give more insight on what's happening in create_model(), you can go through the code here 在进行错误操作以更深入地了解create_model()中发生的情况之前,您可以在此处遍历代码
Now I need nn4_small2_pretrained in my predict.py file (It is initially a part of train.py to train my custom images), but if I do 现在我需要nn4_small2_pretrained在我predict.py文件(它最初train.py训练我的自定义图像的一部分),但如果我这样做
from train import nn4_small2_pretrained
Or write the code 或写代码
nn4_small2_pretrained = create_model()
nn4_small2_pretrained.load_weights('weights/nn4.small2.v1.h5')
all over again, then the prediction file takes a lot of time to compile as it goes through the whole process again. 从头再来,那么预测文件要花很多时间才能重新编译整个过程。 So to resolve this, I tried to dump the model in a pickle file like so 因此,为解决此问题,我尝试将模型转储到类似pickle的文件中
# Save the nn4 pretrained model to pickle file
f = open('pretrained_model.pickle', 'wb')
pickle.dump(nn4_small2_pretrained, f)
When I run the code it gives me this error 当我运行代码时,它给了我这个错误
File "train.py", line 24, in <module>
pickle.dump(nn4_small2_pretrained, f)
TypeError: can't pickle _thread.lock objects
I have started with Deel Learning Models and Pickle recently and I cannot figure out what's wrong. 最近,我开始学习Deel学习模型和Pickle,但我不知道出了什么问题。 Any help would be much appreciated. 任何帮助将非常感激。
Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.