-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetScore.py
57 lines (40 loc) · 1.73 KB
/
getScore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import random
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np
import os
from tensorflow.keras.models import load_model
# Load the saved model
base_path = "C:/Users/yulif/Documents/GitHub/SoftwareEngineeringCourse-DepressionDiagnosis"
# base_path = "D:/0SoftwareEngineering/SoftwareEngineeringCourse-FrontEnd-With-Database-main/SoftwareEngineeringCourse-FrontEnd-With-Database-main"
# D:\0SoftwareEngineering\SoftwareEngineeringCourse-FrontEnd-With-Database-main\SoftwareEngineeringCourse-FrontEnd-With-Database-main
model = load_model(base_path + "/mymodel2.h5")
folder_path = base_path+"/images" # 替换为你的文件夹路径
# 获取文件夹中所有文件的路径和修改时间
files = []
for root, _, filenames in os.walk(folder_path):
for filename in filenames:
file_path = os.path.join(root, filename)
file_time = os.path.getmtime(file_path)
files.append((file_path, file_time))
# 按照修改时间进行排序
files.sort(key=lambda x: x[1], reverse=True)
# 获取最晚修改时间的文件路径
latest_file_path = files[0][0]
def preprocess_image(image_path):
img = image.load_img(image_path, target_size=(224, 224))
img = image.img_to_array(img)
img = tf.keras.applications.vgg16.preprocess_input(img)
img = np.expand_dims(img, axis=0)
return img
# Function to make predictions using the trained model
def predict(image_path):
# Preprocess the image
img = preprocess_image(image_path)
# Make prediction using the model
prediction = model.predict(img)
return prediction[0][0]
# Example usage
image_path = latest_file_path # Replace with the path to your test image
prediction = predict(image_path)
print(str(prediction))