Skip to content

Commit

Permalink
Enhance restore plot backend for binary image
Browse files Browse the repository at this point in the history
  • Loading branch information
ppizarror committed Aug 19, 2024
1 parent 1434e0c commit 7239a2c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion MLStructFP/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
__description__ = 'Machine learning structural floor plan dataset'
__keywords__ = ['ml', 'ai', 'floor plan', 'architectural', 'dataset', 'cnn']
__email__ = 'pablo@ppizarror.com'
__version__ = '0.6.7'
__version__ = '0.6.8'

# URL
__url__ = 'https://github.com/MLSTRUCT/MLSTRUCT-FP'
Expand Down
2 changes: 1 addition & 1 deletion MLStructFP/db/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
Dataset image operations.
"""

from MLStructFP.db.image._rect_binary import RectBinaryImage
from MLStructFP.db.image._rect_binary import RectBinaryImage, restore_plot_backend
from MLStructFP.db.image._rect_photo import RectFloorPhoto
14 changes: 11 additions & 3 deletions MLStructFP/db/image/_rect_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Image of the surroundings of a rect.
"""

__all__ = ['RectBinaryImage']
__all__ = ['RectBinaryImage', 'restore_plot_backend']

from MLStructFP.db.image._base import BaseImage, TYPE_IMAGE
from MLStructFP.utils import make_dirs
Expand All @@ -31,6 +31,14 @@
PLOT_BACKEND: str = 'agg'


def restore_plot_backend() -> None:
"""
Restores plot backend.
"""
if plt.get_backend() == PLOT_BACKEND:
plt.switch_backend(INITIAL_BACKEND)


class RectBinaryImage(BaseImage):
"""
Rect binary image.
Expand Down Expand Up @@ -260,7 +268,7 @@ def close(self, restore_plot: bool = True) -> None:
self._names.clear()

# Restore plot
if restore_plot and plt.get_backend() == PLOT_BACKEND:
plt.switch_backend(INITIAL_BACKEND)
if restore_plot:
restore_plot_backend()

self._initialized = False
2 changes: 1 addition & 1 deletion MLStructFP/db/image/_rect_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def _get_crop_image(

return image_kernel

def close(self) -> None:
def close(self, **kwargs) -> None:
"""
Close and delete all generated figures.
"""
Expand Down

0 comments on commit 7239a2c

Please sign in to comment.