我正在尝试使用https://github.com/rcmalli/keras-vggface的keras-vggface库来训练CNN。我已经安装了tensorflow 2.0.0-rc1,keras 2.3.1,cuda 10.1,cudnn 7.6.5,驱动程序的版本是418,问题是当我尝试使用vggface模型作为卷积基础时,我得到了一个错误,以下是代码和错误
from keras_vggface.vggface import VGGFace
conv_base = VGGFace(model='vgg16', include_top=False)
model = models.Sequential()
model.add(conv_base)
model.add(layers.Flatten())
model.add(layers.Dense(1024, activation='relu'))
model.add(layers.Dense(800, activation='softmax'))错误!
TypeError Traceback (most recent call last)
<ipython-input-4-f6b5cad8f44b> in <module>
1 #arquitectura
2 model = models.Sequential()
----> 3 model.add(conv_base)
4 model.add(layers.Flatten())
5 model.add(layers.Dense(1024, activation='relu'))
~/anaconda3/envs/vggface/lib/python3.7/site-packages/tensorflow_core/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
455 self._self_setattr_tracking = False # pylint: disable=protected-access
456 try:
--> 457 result = method(self, *args, **kwargs)
458 finally:
459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
~/anaconda3/envs/vggface/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/sequential.py in add(self, layer)
156 raise TypeError('The added layer must be '
157 'an instance of class Layer. '
--> 158 'Found: ' + str(layer))
159
160 tf_utils.assert_no_legacy_layers([layer])
TypeError: The added layer must be an instance of class Layer. Found: <keras.engine.training.Model object at 0x7f0bf03db210>我希望你能告诉我为什么会出现这个错误,以及如何解决它,谢谢阅读。
发布于 2020-01-16 16:11:40
问题是keras和tf.keras之间不兼容。您正在使用的库(vggface-keras)使用keras,而您的代码使用tf.keras。这是行不通的。
唯一可能的解决方案是在整个管道中使用keras,或者修改vggface-keras库以使用tf.keras,包括修改所有导入和修复出现的任何错误。
发布于 2020-06-24 23:19:23
这是一个页面,您可以在其中下载带有vggface模型权重的.h5文件,这样我们就可以使用它在高于1.15版本的tensorflow中进行训练
https://sefiks.com/2018/09/03/face-recognition-with-facenet-in-keras/
发布于 2020-07-01 21:45:20
VGG-Face封装在python的deepface框架中。只需将VGG-Face字符串传递给模型名称变量即可。
#!pip install deepface
from deepface import DeepFace
obj = DeepFace.verify([
["img1.jpg", "img2.jpg"],
["img1.jpg", "img3.jpg"],
["img1.jpg", "img4.jpg"],
]
, model_name = "VGG-Face")
print(obj)此块将检查img2、img3、img4中的img1。
https://stackoverflow.com/questions/59763562
复制相似问题