MCPcopy Create free account
hub / github.com/MiniMax-AI/VTP / get_activations

Function get_activations

tools/test_reconstruction_hf.py:139–154  ·  view source on GitHub ↗
(path, model, batch_size, dims, device, num_workers)

Source from the content-addressed store, hash-verified

137 return self.model(x)
138
139 def get_activations(path, model, batch_size, dims, device, num_workers):
140 model.eval()
141 activations = []
142 dataset = ImageFolder(path, transform=transforms.Compose([
143 transforms.Resize((299, 299)),
144 transforms.ToTensor(),
145 ]))
146 dataloader = DataLoader(dataset, batch_size=batch_size, num_workers=num_workers)
147
148 with torch.no_grad():
149 for batch, _ in tqdm(dataloader, desc="Computing activations"):
150 pred = model(batch.to(device))
151 if pred.size(1) != dims:
152 pred = adaptive_avg_pool2d(pred, 1).squeeze()
153 activations.append(pred.cpu().numpy())
154 return np.concatenate(activations, axis=0)
155
156 model = InceptionV3().to(device).eval()
157 is_main = not dist.is_initialized() or dist.get_rank() == 0

Callers 1

_calculate_fid_manualFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected