获取人脸数据集
This commit is contained in:
+2
-2
@@ -16,5 +16,5 @@ def save_img_subset(data, save_path, num_samples):
|
||||
img.save(os.path.join(save_path, f"{i}-label-{label}.png"))
|
||||
|
||||
# 保存前 600 张训练集图片和前 100 张测试集图片
|
||||
save_img_subset(train_data, './DataImages-Train', 6000)
|
||||
save_img_subset(test_data, './DataImages-Test', 1000)
|
||||
save_img_subset(train_data, './DataImages-Train', 60000)
|
||||
save_img_subset(test_data, './DataImages-Test', 10000)
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 289 B After Width: | Height: | Size: 8.1 KiB |
+3
-3
@@ -64,8 +64,8 @@ def ensure_dir_exists(directory):
|
||||
os.makedirs(directory)
|
||||
|
||||
# 加载训练数据
|
||||
trains_paths, trains_labels = load_data("cache/pretrains/train")
|
||||
test_paths, test_labels = load_data("cache/pretrains/test")
|
||||
trains_paths, trains_labels = load_data("DataImages-Train")
|
||||
test_paths, test_labels = load_data("DataImages-Test")
|
||||
|
||||
# 提取特征和标签
|
||||
X_train = np.array([extract_features(train_path) for train_path in tqdm.tqdm(trains_paths, desc="训练集特征提取中:")])
|
||||
@@ -87,7 +87,7 @@ for test_sample in tqdm.tqdm(X_test, desc="测试集中预测进度"):
|
||||
Y_pred.append(classifier.predict(test_sample.reshape(1, -1)))
|
||||
accuracy = accuracy_score(Y_test, Y_pred)
|
||||
|
||||
print(f"性能: {accuracy * 100:.2f}%")
|
||||
print(f"准确率: {accuracy * 100:.2f}%")
|
||||
|
||||
# 保存模型
|
||||
ensure_dir_exists("models")
|
||||
|
||||
Reference in New Issue
Block a user