(self, model_name)
| 166 | |
| 167 | @pytest.mark.parametrize("model_name", models.list_models(models)) |
| 168 | def test_forward_backward(self, model_name): |
| 169 | model = models.get_model(model_name, **self.model_defaults).train() |
| 170 | train_return_nodes, eval_return_nodes = self._get_return_nodes(model) |
| 171 | model = self._create_feature_extractor( |
| 172 | model, train_return_nodes=train_return_nodes, eval_return_nodes=eval_return_nodes |
| 173 | ) |
| 174 | out = model(self.inp) |
| 175 | out_agg = 0 |
| 176 | for node_out in out.values(): |
| 177 | if isinstance(node_out, Sequence): |
| 178 | out_agg += sum(o.float().mean() for o in node_out if o is not None) |
| 179 | elif isinstance(node_out, Mapping): |
| 180 | out_agg += sum(o.float().mean() for o in node_out.values() if o is not None) |
| 181 | else: |
| 182 | # Assume that the only other alternative at this point is a Tensor |
| 183 | out_agg += node_out.float().mean() |
| 184 | out_agg.backward() |
| 185 | |
| 186 | def test_feature_extraction_methods_equivalence(self): |
| 187 | model = models.resnet18(**self.model_defaults).eval() |
nothing calls this directly
no test coverage detected