-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
모델의 성능을 수치로만 나타냈다. 테스트 이미지를 따로 넣어봄으로써 성능을 검증해보겠다.
코드
- 저장된 모델 선언
model = torch.load('./Saved_Models/ResNet18.pth')- 이미지 resize 후 시각화
img = Image.open("./Model_Predict_Test_Images/20201211_General_122_DOC_A_M50_MM_069_0101.jpg")
img_resize = img.resize((224, 224))
img_resize- 테스트 이미지 검증
import torch
import torchvision.transforms as transforms
from PIL import Image
# Define the transforms for preprocessing the image
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
# Load the image
img = Image.open("./Model_Predict_Test_Images/20201211_General_122_DOC_A_M50_MM_069_0101.jpg").convert('RGB')
# Preprocess the image
img_tensor = transform(img).unsqueeze(0)
# Move the model and input tensor to the CPU or GPU
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
img_tensor = img_tensor.to(device)
model.to(device)
# Set the model to evaluation mode
model.eval()
# Make a prediction
with torch.no_grad():
predictions = model(img_tensor)
# Print the predicted class
predicted_class = torch.argmax(predictions[0]).item()
print("Predicted class:", predicted_class)
img_resize테스트 결과
class 2 => backswingtop
실제 동작은 backswing이지만 이 이미지는 json file에 의해 backswingtop으로 분류되어 있던 사진이다. 정답은 맞춘 셈이다.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
