-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_model.py
45 lines (34 loc) · 1.29 KB
/
test_model.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
from net.models.SUM import SUM
from net.configs.config_setting import setting_config
import torch
config = setting_config
model_cfg = config.model_config
if config.network == 'sum':
model = SUM(
num_classes=model_cfg['num_classes'],
input_channels=model_cfg['input_channels'],
depths=model_cfg['depths'],
depths_decoder=model_cfg['depths_decoder'],
drop_path_rate=model_cfg['drop_path_rate'],
)
model.load_from()
model.cuda()
# Freeze the encoder
for param in model.salu_mamba.layers.parameters():
param.requires_grad = False
# Move the model to GPU
model.cuda()
conditions = torch.eye(4)[torch.randint(0, 4, (10,))].cuda()
# Move the model to GPU (if not already moved)
model.cuda()
# Generate a random input tensor
inp = torch.rand(10, 3, 256, 256).cuda()
# Perform a forward pass with the input and condition
out = model(inp, conditions)
print(out.shape)
# Counting the total parameters
total_params = sum(p.numel() for p in model.parameters())
print(f"Total number of parameters in the model: {total_params}")
# Counting only the trainable parameters to verify if the encoder is frozen
trainable_params = sum(p.numel() for p in model.parameters() if p.requires_grad)
print(f"Total number of trainable parameters in the model: {trainable_params}")