4646import torch
4747from torch .utils .data import DataLoader
4848# Import from 'bulkDGD'.
49- from bulkDGD import util
5049from . import (
5150 dataclasses ,
5251 decoder ,
6564#######################################################################
6665
6766
67+ def uniquify_file_path (file_path ):
68+ """If ``file_path`` exists, number it uniquely.
69+
70+ Parameters
71+ ----------
72+ file_path : ``str``
73+ The file path.
74+
75+ Returns
76+ -------
77+ unique_file_path : ``str``
78+ A unique file path generated from the original file path.
79+ """
80+
81+ # Get the file's name and extension.
82+ file_name , file_ext = os .path .splitext (file_path )
83+
84+ # Set the counter to 1.
85+ counter = 1
86+
87+ # If the file already exists
88+ while os .path .exists (file_path ):
89+
90+ # Set the path to the new unique file.
91+ file_path = file_name + "_" + str (counter ) + file_ext
92+
93+ # Update the counter.
94+ counter += 1
95+
96+ # Return the new path.
97+ return file_path
98+
99+
100+ #######################################################################
101+
102+
68103class DGDModel :
69104
70105 """
@@ -2852,7 +2887,7 @@ def train(self,
28522887
28532888 # Save the GMM's parameters.
28542889 torch .save (self .gmm .state_dict (),
2855- util . uniquify_file_path (gmm_pth_file ))
2890+ uniquify_file_path (gmm_pth_file ))
28562891
28572892 # Inform the user that the parameters were saved.
28582893 infostr = \
@@ -2864,7 +2899,7 @@ def train(self,
28642899
28652900 # Save the decoder's parameters.
28662901 torch .save (self .dec .state_dict (),
2867- util . uniquify_file_path (dec_pth_file ))
2902+ uniquify_file_path (dec_pth_file ))
28682903
28692904 # Inform the user that the parameters were saved.
28702905 infostr = \
0 commit comments