def save(self, dst): # save custom_objects for model cloudpickle.dump(self._custom_objects, open(self.spec._custom_objects_path(dst), "wb")) # save keras model self._model.save(self.spec._model_file_path(dst))
def save(self, dst): # save the keras module name to be used when loading with open(self.spec._keras_module_name_path(dst), "wb") as text_file: text_file.write(self.spec._keras_module_name.encode("utf-8")) # save custom_objects for model cloudpickle.dump(self._custom_objects, open(self.spec._custom_objects_path(dst), "wb")) # save keras model using json and weights if requested if self.spec._store_as_json_and_weights: with open(self.spec._model_json_path(dst), "w") as json_file: json_file.write(self._model.to_json()) self._model.save_weights(self.spec._model_weights_path(dst)) # otherwise, save standard keras model else: self._model.save(self.spec._model_file_path(dst))
def save(self, dst): try: import torch except ImportError: raise MissingDependencyException( "torch package is required to use PytorchModelArtifact") # If model is a TorchScriptModule, we cannot apply standard pickling if isinstance(self._model, torch.jit.ScriptModule): return torch.jit.save(self._model, self._file_path(dst)) return cloudpickle.dump(self._model, open(self._file_path(dst), "wb"))
def save(self, dst): return cloudpickle.dump(self._model, open(self.spec._file_path(dst), "wb"))