docstr: Saves the model to files in the given directory.
  :param directory_path: str
  The path to the directory in which to save the model.
  :return:
code: def save_model(self, directory_path):
      """
      Saves the model to files in the given directory.
      :param directory_path: str
      The path to the directory in which to save the model.
      :return:
      """
  
      # Ensure that the model has been fit
      if self.tf_prediction is None:
          raise ModelNotFitException(method="save_model")
  
      if not os.path.exists(directory_path):
          os.makedirs(directory_path)
  
      saver = tf.train.Saver()
      session_path = os.path.join(
          directory_path, "tensorrec_session.cpkt"
      )
      saver.save(sess=get_session(), save_path=session_path)
  
      # Break connections to the graph before saving the python object
      self._break_graph_hooks()
      tensorrec_path = os.path.join(directory_path, "tensorrec.pkl")
      with open(tensorrec_path, "wb") as file:
          pickle.dump(file=file, obj=self)
  
      # Reconnect to the graph after saving
      self._attach_graph_hooks()
  
imports: from functools import partial
  from itertools import cycle
  import logging
  import numpy
  import os
  import pickle
  from scipy import sparse
  import tensorflow
  from .errors import ModelNotBiasedException, ModelNotFitException, ModelWithoutAttentionException, BatchNonSparseInputException, TfVersionException
  from .input_utils import create_tensorrec_iterator, get_dimensions_from_tensorrec_dataset
  from .loss_graphs import AbstractLossGraph, RMSELossGraph
  from .prediction_graphs import AbstractPredictionGraph, DotProductPredictionGraph
  from .recommendation_graphs import project_biases, split_sparse_tensor_indices, bias_prediction_dense, bias_prediction_serial, rank_predictions, densify_sampled_item_predictions, collapse_mixture_of_tastes, predict_similar_items
  from .representation_graphs import AbstractRepresentationGraph, LinearRepresentationGraph
  from .session_management import get_session
  from .util import sample_items, calculate_batched_alpha, datasets_from_raw_input
label_desc: Use image node_id 19 for calling the TensorRec obj's underlying member method code with example usage: obj.save_model(directory_path) without return types