简体   繁体   English

TypeError:从Keras-Openface项目中转储nn4_small2_pretrained模型时无法腌制_thread.lock对象

[英]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. 谢谢。

I see that the create_model() creates an instance of Keras Model. 我看到create_model()创建了Keras Model的实例。 If it is a Keras Model then you can save the model using model.save(filepath) . 如果是Keras模型,则可以使用model.save(filepath)保存模型。 Refer this link for other options. 请参阅此链接以了解其他选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Keras模型:TypeError:无法腌制_thread.lock对象 - Keras model: TypeError: can't pickle _thread.lock objects Keras:TypeError:无法使用KerasClassifier来pickle _thread.lock对象 - Keras: TypeError: can't pickle _thread.lock objects with KerasClassifier Keras 2,TypeError:无法pickle _thread.lock对象 - Keras 2, TypeError: can't pickle _thread.lock objects TypeError:训练keras模型时无法pickle _thread.lock对象 - TypeError: can't pickle _thread.lock objects when training keras model Keras Lambda图层和变量:“TypeError:无法pickle _thread.lock对象” - Keras Lambda layer and variables : “TypeError: can't pickle _thread.lock objects” Joblib错误:TypeError:无法腌制_thread.lock对象 - Joblib error: TypeError: can't pickle _thread.lock objects 收到TypeError:无法腌制_thread.lock对象 - Getting TypeError: can't pickle _thread.lock objects 使用 Queue() 进行多处理:TypeError: can't pickle _thread.lock objects - Multiprocessing with Queue(): TypeError: can't pickle _thread.lock objects 在将Queue传递给子进程中的线程时,如何解决“ TypeError:无法腌制_thread.lock对象” - How to fix 'TypeError: can't pickle _thread.lock objects' when passing a Queue to a thread in a child process 当joblib具有&gt; = 2个作业时,keras.wrappers无法使_thread.lock对象腌制 - keras.wrappers can't pickle _thread.lock objects when joblib has >= 2 jobs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM