Skip to content

Commit

Permalink
isort
Browse files Browse the repository at this point in the history
  • Loading branch information
Atashnezhad committed Jun 30, 2023
1 parent d9d01d0 commit ed488ae
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions neural_network_model/transfer_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def _prepare_data(
logging.info("Data was prepared")

def plot_classes_number(
self, figsize=(10, 5), x_rotation=0, palette="Greens_r", **kwargs,
self,
figsize=(10, 5),
x_rotation=0,
palette="Greens_r",
**kwargs,
) -> None:
"""
Plot the number of images per species
Expand All @@ -89,8 +93,9 @@ def plot_classes_number(
:param kwargs: figure_folder_path
:return: None
"""
figure_folder_path = kwargs.get("figure_folder_path",
Path(__file__).parent / ".." / "figures")
figure_folder_path = kwargs.get(
"figure_folder_path", Path(__file__).parent / ".." / "figures"
)
# check if the folder exists if not create it
if not figure_folder_path.exists():
os.makedirs(figure_folder_path)
Expand Down Expand Up @@ -141,8 +146,9 @@ def analyze_image_names(
:param num_cluster: number of clusters - unsupervised learning on width of images
"""

figure_folder_path = kwargs.get("figure_folder_path",
Path(__file__).parent / ".." / "figures")
figure_folder_path = kwargs.get(
"figure_folder_path", Path(__file__).parent / ".." / "figures"
)
# check if the folder exists if not create it
if not figure_folder_path.exists():
os.makedirs(figure_folder_path)
Expand Down Expand Up @@ -252,7 +258,9 @@ def analyze_image_names(
plt.savefig(figure_folder_path / "cluster_number_per_class.png")
plt.show()

def plot_data_images(self, num_rows=None, num_cols=None, figsize=(15, 10), **kwargs):
def plot_data_images(
self, num_rows=None, num_cols=None, figsize=(15, 10), **kwargs
):
"""
Plot the images in a grid
:param num_rows: number of rows in the grid
Expand All @@ -262,8 +270,9 @@ def plot_data_images(self, num_rows=None, num_cols=None, figsize=(15, 10), **kwa
:return: None
"""

figure_folder_path = kwargs.get("figure_folder_path",
Path(__file__).parent / ".." / "figures")
figure_folder_path = kwargs.get(
"figure_folder_path", Path(__file__).parent / ".." / "figures"
)
# check if the folder exists if not create it
if not figure_folder_path.exists():
os.makedirs(figure_folder_path)
Expand Down Expand Up @@ -527,9 +536,9 @@ def train_model(self, epochs=10, batch_size=32):
self.model.save(self.model_address)

def plot_metrics_results(self, **kwargs):

figure_folder_path = kwargs.get("figure_folder_path",
Path(__file__).parent / ".." / "figures")
figure_folder_path = kwargs.get(
"figure_folder_path", Path(__file__).parent / ".." / "figures"
)
# check if the folder exists if not create it
if not figure_folder_path.exists():
os.makedirs(figure_folder_path)
Expand Down Expand Up @@ -589,8 +598,9 @@ def predcit_test(self, **kwargs):
test_images,
) = self._create_gen()

figure_folder_path = kwargs.get("figure_folder_path",
Path(__file__).parent / ".." / "figures")
figure_folder_path = kwargs.get(
"figure_folder_path", Path(__file__).parent / ".." / "figures"
)
# check if the folder exists if not create it
if not figure_folder_path.exists():
os.makedirs(figure_folder_path)
Expand Down Expand Up @@ -687,7 +697,9 @@ def _save_and_display_gradcam(
figure_folder_path: the path to the folder where we want to save the cam (default: figures)
"""

cam_path = kwargs.get("figure_folder_path", Path(__file__).parent / ".." / "figures")
cam_path = kwargs.get(
"figure_folder_path", Path(__file__).parent / ".." / "figures"
)
# check if the cam_path exists if not create it
if not os.path.exists(cam_path):
os.makedirs(cam_path)
Expand Down

0 comments on commit ed488ae

Please sign in to comment.