|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 |
| -from typing import Any, Callable, List, Mapping, Optional, Sequence, Type, Union |
| 14 | +from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Type, Union |
15 | 15 |
|
16 | 16 | import torch
|
17 | 17 | from torch import nn, tensor
|
@@ -88,7 +88,7 @@ def __init__(
|
88 | 88 | anchor_generator: Optional[Type['AnchorGenerator']] = None,
|
89 | 89 | loss=None,
|
90 | 90 | metrics: Union[Callable, nn.Module, Mapping, Sequence, None] = None,
|
91 |
| - optimizer: Type[Optimizer] = torch.optim.Adam, |
| 91 | + optimizer: Type[Optimizer] = torch.optim.AdamW, |
92 | 92 | learning_rate: float = 1e-3,
|
93 | 93 | **kwargs: Any,
|
94 | 94 | ):
|
@@ -180,28 +180,28 @@ def validation_step(self, batch, batch_idx):
|
180 | 180 | # fasterrcnn takes only images for eval() mode
|
181 | 181 | outs = self.model(images)
|
182 | 182 | iou = torch.stack([_evaluate_iou(t, o) for t, o in zip(targets, outs)]).mean()
|
183 |
| - return {"val_iou": iou} |
| 183 | + self.log("val_iou", iou) |
184 | 184 |
|
185 |
| - def validation_epoch_end(self, outs): |
186 |
| - avg_iou = torch.stack([o["val_iou"] for o in outs]).mean() |
187 |
| - logs = {"val_iou": avg_iou} |
188 |
| - return {"avg_val_iou": avg_iou, "log": logs} |
| 185 | + def on_validation_end(self) -> None: |
| 186 | + return super().on_validation_end() |
189 | 187 |
|
190 | 188 | def test_step(self, batch, batch_idx):
|
191 | 189 | images, targets = batch[DefaultDataKeys.INPUT], batch[DefaultDataKeys.TARGET]
|
192 | 190 | # fasterrcnn takes only images for eval() mode
|
193 | 191 | outs = self.model(images)
|
194 | 192 | iou = torch.stack([_evaluate_iou(t, o) for t, o in zip(targets, outs)]).mean()
|
195 |
| - return {"test_iou": iou} |
196 |
| - |
197 |
| - def test_epoch_end(self, outs): |
198 |
| - avg_iou = torch.stack([o["test_iou"] for o in outs]).mean() |
199 |
| - logs = {"test_iou": avg_iou} |
200 |
| - return {"avg_test_iou": avg_iou, "log": logs} |
| 193 | + self.log("test_iou", iou) |
201 | 194 |
|
202 | 195 | def predict_step(self, batch: Any, batch_idx: int, dataloader_idx: int = 0) -> Any:
|
203 | 196 | images = batch[DefaultDataKeys.INPUT]
|
204 | 197 | return self.model(images)
|
205 | 198 |
|
206 | 199 | def configure_finetune_callback(self):
|
207 | 200 | return [ObjectDetectionFineTuning(train_bn=True)]
|
| 201 | + |
| 202 | + def _ci_benchmark_fn(self, history: List[Dict[str, Any]]) -> None: |
| 203 | + """ |
| 204 | + This function is used only for debugging usage with CI |
| 205 | + """ |
| 206 | + # todo (tchaton) Improve convergence |
| 207 | + # history[-1]["val_iou"] |
0 commit comments