| 121 | return accuracy |
| 122 | |
| 123 | class ProxyEvaluator: |
| 124 | def __init__(self, device: str = 'cuda'): |
| 125 | self.device = device |
| 126 | |
| 127 | def evaluate(self, architecture: Architecture, search_space: SearchSpace) -> Tuple[float, float]: |
| 128 | model = search_space.build_model(architecture) |
| 129 | model = model.to(self.device) |
| 130 | |
| 131 | complexity = search_space.estimate_complexity(architecture) |
| 132 | params = complexity['params'] |
| 133 | flops = complexity['flops'] |
| 134 | |
| 135 | num_layers = len([g for g in architecture.genome if g.get('type') != 'pooling']) |
| 136 | |
| 137 | estimated_accuracy = 60.0 + torch.rand(1).item() * 20.0 |
| 138 | estimated_accuracy = min(95.0, estimated_accuracy - params / 1e8) |
| 139 | |
| 140 | fitness = estimated_accuracy - 0.1 * (params / 1e7) - 0.05 * (flops / 1e9) |
| 141 | |
| 142 | return fitness, estimated_accuracy |