转换模型中缺少权重

gcxthw6b  于 2021-09-08  发布在  Java
关注(0)|答案(0)|浏览(257)

我正在尝试将keras模型转换为tensorflow模型,然后将其加载到react本机应用程序中。但是,在转换之后,一些权重似乎丢失了。模型生成和保存代码:

import os

# from face_recognition import FaceRecognition

import keras_vggface
from mtcnn.mtcnn import MTCNN
from PIL import Image
from keras_vggface.utils import preprocess_input
from matplotlib import pyplot
from numpy import asarray
from keras_vggface.vggface import VGGFace
from scipy.spatial.distance import cosine
from tensorflow.keras.models import load_model

def get_embeddings(filenames):
    # extract faces
    faces = [extract_face(f) for f in filenames]
    # convert into an array of samples
    samples = asarray(faces, 'float32')
    # prepare the face for the model, e.g. center pixels
    samples = preprocess_input(samples, version=2)
    # create a vggface model
    model = VGGFace(model='resnet50', include_top=False, input_shape=(224, 224, 3), pooling='avg')
    # perform prediction
    yhat = model.predict(samples)
    return yhat, model

def is_match(known_embedding, candidate_embedding, thresh=0.5):
    # calculate distance between embeddings
    score = cosine(known_embedding, candidate_embedding)
    if score <= thresh:
        print('>face is a Match' % (score, thresh))
    else:
        print('>face is not a match' % (score, thresh))

if __name__ == '__main__':
    filenames = ["test1.jpg", "test2.jpg", "test3.jpg", "test4.jpg"]
    embeddings, model = get_embeddings(filenames);
    ahmed_id = embeddings[1];
    is_match(embeddings[0], embeddings[1])
    is_match(embeddings[2], embeddings[3])
    is_match(embeddings[1], embeddings[2])
    model.save("model", include_optimizer=True)

该模型在python中运行良好,预测准确。然后我使用tensorflowjs_向导将其转换为javascript。命令是:

tensorflowjs_converter --input_format=keras_saved_model --metadata= --quantize_uint8=* C:\Users\user\Documents\Face_Recognition_Tensorflow\model .

生成的模型缺少某些层的权重。当我尝试在react native应用程序中加载它时,我收到以下错误:

[Unhandled promise rejection: Error: 212 of 265 weights are not set: conv1/7x7_s2/bn/gamma,conv1/7x7_s2/bn/beta, ...

如果我真的打开model.json,我可以看到在 model_config 第节,但仅与中的53个相关的元数据 weightsManifest 节。
你知道我做错了什么吗?塔尔

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题