Python通过vggface提取人脸特征值并保存的代码
时间: 2023-04-01 22:02:42 浏览: 143
以下是Python通过vggface提取人脸特征值并保存的代码:
```python
import numpy as np
import cv2
from keras_vggface.vggface import VGGFace
from keras_vggface.utils import preprocess_input
# 加载模型
model = VGGFace(model='resnet50', include_top=False, input_shape=(224, 224, 3), pooling='avg')
# 读取图像
img = cv2.imread('test.jpg')
# 调整图像大小
img = cv2.resize(img, (224, 224))
# 预处理图像
img = preprocess_input(img)
# 提取特征值
features = model.predict(np.array([img]))
# 保存特征值
np.savetxt('features.txt', features)
```
希望对您有所帮助!
阅读全文