Skip to content

The issue of the number of parameters #8

Description

@Guan725713

if name == 'main':
device = "cuda" if torch.cuda.is_available() else "cpu"

dummy_input = torch.randn(1, 3, 256, 256).to(device)

model = mobileuvit_l(out_channel=1).to(device)

model.eval()

output = model(dummy_input)

print(f"\n输入尺寸: {dummy_input.shape}")
print(f"输出尺寸: {output.shape}")
assert output.shape == (1, 1, 256, 256)

print("\n" + "="*30)
print("  性能指标计算")
print("="*30)

macs, params = profile(model, inputs=(dummy_input, ))
gflops = macs * 2 / 1e9

print(f"模型总参数量 (Params): {params / 1e6:.2f} M")
print(f"理论计算量 (GFLOPs): {gflops:.2f} G")

print("\n==> 正在测试模型推理速度 (FPS)...")
with torch.no_grad():
    for _ in range(20):
        _ = model(dummy_input)

num_test_frames = 100
start_time = time.time()
with torch.no_grad():
    for _ in range(num_test_frames):
        _ = model(dummy_input)
        if device == 'cuda':
            torch.cuda.synchronize()

end_time = time.time()

elapsed_time = end_time - start_time
fps = num_test_frames / elapsed_time

print(f"处理 {num_test_frames} 帧耗时: {elapsed_time:.2f} 秒")
print(f"模型推理速度 (FPS): {fps:.2f} 帧/秒")

large版本:
模型总参数量 (Params): 6.21 M
理论计算量 (GFLOPs): 20.86 G

==> 正在测试模型推理速度 (FPS)...
处理 100 帧耗时: 0.75 秒
模型推理速度 (FPS): 132.86 帧/秒

base版本:
模型总参数量 (Params): 1.39 M
理论计算量 (GFLOPs): 5.01 G

==> 正在测试模型推理速度 (FPS)...
处理 100 帧耗时: 0.59 秒
模型推理速度 (FPS): 169.73 帧/秒

Originally posted by @da-cai-ji in #4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions