更新 function.py
Gitea Actions Experiment Test / Experiment-Actions (push) Successful in 12s

This commit is contained in:
2024-10-16 20:49:40 +08:00
parent 01e976f847
commit 4a340d7eef
+42 -41
View File
@@ -78,47 +78,48 @@ def img_to_vector(filename):
    return returnVect     return returnVect
if __name__ == "__main__": if __name__ == "__main__":
    # 使用绝对路径加载数据集     # 使用绝对路径加载数据集
    directory = r"C:\Users\HP\Desktop\trainingDigits"     directory = r"C:\Users\86199\Desktop\trainingDigits"
    train_data, train_labels = load_dataset(directory)     train_data, train_labels = load_dataset(directory)
# 确保 test_data 字符串长度为1024
    test_data = (
        "00000000000000110000000000000000"
        "00000000000011111000000000000000"
        "00000000000011111100000000000000"
        "00000000001111111110000000000000"
        "00000000001111111110000000000000"
        "00000000001111111100000000000000"
        "00000000011111111000000000000000"
        "00000000111111111000000000000000"
        "00000000111111110000000000000000"
        "00000000111111110000000000000000"
        "00000000111111110000000000000000"
        "00000000111111110000000000000000"
        "00000000111111100000000000000000"
        "00000001111111100000000000000000"
        "00000001111111100000000000000000"
        "00000001111111100000000000000000"
        "00000001111111111111000000000000"
        "00000001111111111111111000000000"
        "00000001111111111111111100000000"
        "00000011111111111111111100000000"
        "00000011111111111111111100000000"
        "00000001111111111111111110000000"
        "00000001111111111111111110000000"
        "00000000111111111100111111100000"
        "00000000111111111000111111100000"
        "00000000011111111100111111110000"
        "00000000011111111111111111000000"
        "00000000001111111111111111000000"
        "00000000000111111111111111000000"
        "00000000000011111111111100000000"
        "00000000000000111111111000000000"
        "00000000000000000111100000000000"
    ).replace("\n", "")  # 移除换行符
test_data = (     # 将 test_data 转换为 NumPy 数组,并确保其长度为1024
"00000000000000110000000000000000"     test_vector = np.array([int(char) for char in test_data])[:1024].reshape(1, 1024)
"00000000000011111000000000000000"
"00000000000011111100000000000000"
"00000000001111111110000000000000"
"00000000001111111110000000000000"
"00000000001111111100000000000000"
"00000000011111111000000000000000"
"00000000111111111000000000000000"
"00000000111111110000000000000000"
"00000000111111110000000000000000"
"00000000111111110000000000000000"
"00000000111111110000000000000000"
"00000000111111100000000000000000"
"00000001111111100000000000000000"
"00000001111111100000000000000000"
"00000001111111100000000000000000"
"00000001111111111111000000000000"
"00000001111111111111111000000000"
"00000001111111111111111100000000"
"00000011111111111111111110000000"
"00000011111111111111111110000000"
"00000001111111111111111110000000"
"00000001111111111111111110000000"
"00000000111111111100111111100000"
"00000000111111111000111111100000"
"00000000011111111001111111100000"
"00000000011111111111111111000000"
"00000000001111111111111111000000"
"00000000000111111111111111000000"
"00000000000011111111111100000000"
"00000000000001111111110000000000"
"00000000000000000111100000000000"
)
predicted_label = classify(
np.array([int(char) for char in test_data]).reshape(1, 1024),
train_data,
train_labels,
)
print(f"预测的标签: {predicted_label}")     # 确保数组大小为1024后再进行分类
    predicted_label = classify(test_vector, train_data, train_labels)
    print(f"预测的标签: {predicted_label}")