1 Star 0 Fork 1

ray7jq/ShortVideo Classification

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
val.py 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
ray7jq 提交于 2023-05-28 16:26 . V1.0
import torch
import torch.nn as nn
from model import ActionClassificationModel
from dataset import CustomImageFolder
from torchvision.transforms import transforms
# 1. Define data preprocessing
test_transforms = transforms.Compose([
transforms.Resize((112, 112)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
# 2. Load test dataset
test_dataset = CustomImageFolder("dataset/val", transform=test_transforms)
test_loader = torch.utils.data.DataLoader(
test_dataset, batch_size=4, shuffle=False, num_workers=0
)
# 3. Load the saved model
model = ActionClassificationModel()
model.load_state_dict(torch.load("model_epoch_10.pth")) # Replace with your desired checkpoint file
# 4. Test the model on the test dataset
correct = 0
total = 0
with torch.no_grad():
for data in test_loader:
inputs, labels = data
outputs = model(inputs)
_, predicted = torch.max(outputs.data, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
accuracy = 100 * correct / total
print('Accuracy of the network on the test images: %d %%' % accuracy)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ray7jq/short-video-classification.git
git@gitee.com:ray7jq/short-video-classification.git
ray7jq
short-video-classification
ShortVideo Classification
master

搜索帮助