51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
|
|
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
@project:
|
|
@File : testfps
|
|
@Author : qiqq
|
|
@create_time : 2023/11/6 16:40
|
|
"""
|
|
|
|
import os
|
|
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
|
|
|
import torch
|
|
import numpy as np
|
|
|
|
from taihuyuan_pv.compared_experiment.deeplabv3Plus.model.modeling import deeplabv3plus_resnet50
|
|
|
|
model = deeplabv3plus_resnet50(num_classes=2, output_stride=8, pretrained_backbone=False)
|
|
|
|
model_path = "/home/qiqq/q3dl/code/applicationproject/taihuyuan_pv/deeplabv3Plus/train_val_test/checkpoints/2023-10-23-23.34/best.pth"
|
|
model_dict = torch.load(model_path)
|
|
model.load_state_dict(model_dict['net'])
|
|
print("权重加载")
|
|
model.eval()
|
|
|
|
device = torch.device("cuda")
|
|
model.to(device)
|
|
dummy_input = torch.randn(1, 3, 512, 512,dtype=torch.float).to(device)
|
|
starter, ender = torch.cuda.Event(enable_timing=True), torch.cuda.Event(enable_timing=True)
|
|
repetitions = 300
|
|
timings=np.zeros((repetitions,1))
|
|
#GPU-WARM-UP
|
|
for _ in range(10):
|
|
_ = model(dummy_input)
|
|
# MEASURE PERFORMANCE
|
|
with torch.no_grad():
|
|
for rep in range(repetitions):
|
|
starter.record()
|
|
_ = model(dummy_input)
|
|
ender.record()
|
|
# WAIT FOR GPU SYNC
|
|
torch.cuda.synchronize()
|
|
curr_time = starter.elapsed_time(ender)
|
|
timings[rep] = curr_time
|
|
mean_syn = np.sum(timings) / repetitions
|
|
std_syn = np.std(timings)
|
|
mean_fps = 1000. / mean_syn
|
|
print(' * Mean@1 {mean_syn:.3f}ms Std@5 {std_syn:.3f}ms FPS@1 {mean_fps:.2f}'.format(mean_syn=mean_syn, std_syn=std_syn, mean_fps=mean_fps))
|
|
print(mean_syn)
|