Created
June 9, 2020 13:05
-
-
Save ulat/5658a863b578d2617654dabddd9dd1a7 to your computer and use it in GitHub Desktop.
I have extended the `SaveModelCallback` so that I can copy my saved models from colab onto gdrive automatically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SaveAndPersistModel(SaveModelCallback): | |
def __init__(self , monitor='valid_loss', comp=None, min_delta=0., fname='model', every_epoch=False, add_save=None, with_opt=False, | |
persistence_path:str='./drive/My\ Drive/'): | |
super().__init__(monitor, comp, min_delta, fname, every_epoch, add_save, with_opt) | |
self.persistence_path = persistence_path | |
def after_epoch(self): | |
super().after_epoch() | |
#print(str(self.path/f"{self.fname}.tar.gz")) | |
#print(str(self.path/self.model_dir/f"{self.fname}.pth")) | |
#print(self.persistence_path) | |
subprocess.call(["tar", "-czvf", str(self.path/f"{self.fname}.tar.gz"), | |
str(self.path/self.model_dir/f"{self.fname}.pth")]) | |
subprocess.call(["cp", self.path/f"{self.fname}.tar.gz", self.persistence_path]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Caveat: My gdrive will be mount at
./drive/My\ Drive/language_model
. I had not managed to work with the path, containing a blank. Therefore I have created a symbolic link which worked fine!subprocess.call(["ln", "-s", "./drive/My\ Drive/language_model", "model_upload"])