Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trainers: fix plotting file handle leak #826

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Trainers: fix plotting file handle leak
adamjstewart committed Oct 10, 2022

Verified

This commit was signed with the committer’s verified signature.
nickvergessen Joas Schilling
commit 1fff63bea9f6adf8cf9a6984ac71f4638e269f88
2 changes: 2 additions & 0 deletions torchgeo/trainers/classification.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import os
from typing import Any, Dict, cast

import matplotlib.pyplot as plt
import pytorch_lightning as pl
import timm
import torch
@@ -199,6 +200,7 @@ def validation_step(self, *args: Any, **kwargs: Any) -> None:
summary_writer.add_figure(
f"image/{batch_idx}", fig, global_step=self.global_step
)
plt.close()
except AttributeError:
pass

2 changes: 2 additions & 0 deletions torchgeo/trainers/detection.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

from typing import Any, Dict, List, cast

import matplotlib.pyplot as plt
import pytorch_lightning as pl
import torch
import torchmetrics
@@ -190,6 +191,7 @@ def validation_step(self, *args: Any, **kwargs: Any) -> None:
summary_writer.add_figure(
f"image/{batch_idx}", fig, global_step=self.global_step
)
plt.close()
except AttributeError:
pass

2 changes: 2 additions & 0 deletions torchgeo/trainers/regression.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

from typing import Any, Dict, cast

import matplotlib.pyplot as plt
import pytorch_lightning as pl
import torch
import torch.nn as nn
@@ -140,6 +141,7 @@ def validation_step(self, *args: Any, **kwargs: Any) -> None:
summary_writer.add_figure(
f"image/{batch_idx}", fig, global_step=self.global_step
)
plt.close()
except AttributeError:
pass

2 changes: 2 additions & 0 deletions torchgeo/trainers/segmentation.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import warnings
from typing import Any, Dict, cast

import matplotlib.pyplot as plt
import pytorch_lightning as pl
import segmentation_models_pytorch as smp
import torch
@@ -194,6 +195,7 @@ def validation_step(self, *args: Any, **kwargs: Any) -> None:
summary_writer.add_figure(
f"image/{batch_idx}", fig, global_step=self.global_step
)
plt.close()
except AttributeError:
pass