keras 无法加载模块-Imgur

yptwkmov  于 2022-11-24  发布在  其他
关注(0)|答案(1)|浏览(111)

我是相当新的tensorflow和不知道什么是错的。它让我不断显示这个"坏马歇尔错误",我似乎不能理解是什么造成的。版本:Python皮:3.8tensorflow :2.5.0克拉:2.4.3
下面是我的代码

import os
import tensorflow as tf
from tensorflow.keras import layers
from keras.models import load_model
from tensorflow.keras.models import Model
from tensorflow.python.keras.backend import set_session 
from flask import Flask, request
from flask_cors import CORS
import cv2
import json
import numpy as np
import base64
from datetime import datetime

database = {}
graph = tf.compat.v1.get_default_graph()
app = Flask(__name__)
CORS(app)
sess = tf.compat.v1.Session()
set_session(sess)

#loading model
model = load_model('facenet_keras.h5')
model.summary()

下面是我遇到的错误:

Traceback (most recent call last):
  File "index.py", line 24, in <module>
    model = load_model('facenet_keras.h5')
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/saving/save.py", line 201, in load_model
    return hdf5_format.load_model_from_hdf5(filepath, custom_objects,
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/saving/hdf5_format.py", line 180, in load_model_from_hdf5
    model = model_config_lib.model_from_config(model_config,
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/saving/model_config.py", line 59, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/layers/serialization.py", line 159, in deserialize
    return generic_utils.deserialize_keras_object(
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/utils/generic_utils.py", line 668, in deserialize_keras_object
    deserialized_obj = cls.from_config(
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/engine/training.py", line 2332, in from_config
    functional.reconstruct_from_config(config, custom_objects))
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/engine/functional.py", line 1274, in reconstruct_from_config
    process_layer(layer_data)
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/engine/functional.py", line 1256, in process_layer
    layer = deserialize_layer(layer_data, custom_objects=custom_objects)
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/layers/serialization.py", line 159, in deserialize
    return generic_utils.deserialize_keras_object(
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/utils/generic_utils.py", line 668, in deserialize_keras_object
    deserialized_obj = cls.from_config(
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/layers/core.py", line 1001, in from_config
    function = cls._parse_function_from_config(
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/layers/core.py", line 1053, in _parse_function_from_config
    function = generic_utils.func_load(
  File "/home/faheel/.local/lib/python3.8/site-packages/keras/utils/generic_utils.py", line 783, in func_load
    code = marshal.loads(raw_code)
ValueError: bad marshal data (unknown type code)
t8e9dugd

t8e9dugd1#

    • 改用keras-facenet库:**
pip install keras-facenet

from keras_facenet import FaceNet

embedder = FaceNet()

获取图像中每个人脸的检测规则。每个检测规则都有边界框和人脸标志(来自mtcnn.MTCNN),以及来自FaceNet的嵌入。

detections = embedder.extract(image, threshold=0.95)

如果您有预裁剪的图像,则可以跳过检测步骤。

embeddings = embedder.embeddings(images)

相关问题