(self, model,
                 train_set=None,
                 output_file=None,
                 eval_freq=None,
                 progress_bar=True,
                 save_path=None,
                 serialize=0,
                 history=1,
                 model_file=None,
                 eval_set=None,
                 metric=None,
                 log_token=None,
                 multicost=False)
Create a callbacks container with the default callbacks.

        Arguments:
            model (Model): the model object
            output_file (string, optional): path to save callback data to
            eval_freq (int, optional): how often (in epochs) to run evaluation
            progress_bar (bool): control whether a progress bar callback is created.
                                 Defaults to True.
            save_path (string): file path to save model snapshots (default: None)
            serialize (int): serialize model every N epochs (default: 0)
            history (int): number of checkpoint files to retain (default: 1)
            model_file(string, optional): file to load weights (serialized model) from
            eval_set (NervanaDataIterator, optional): the dataset upon which to evaluate
                                                      loss or metric
            metric (Metric, optional):  metric to evaluate
            multicost (bool, optional): use the multicost callback. default to false.
Create a callbacks container with the default callbacks.
Create a callbacks container with the default callbacks .
def __init__(self, model,
                 train_set=None,
                 output_file=None,
                 eval_freq=None,
                 progress_bar=True,
                 save_path=None,
                 serialize=0,
                 history=1,
                 model_file=None,
                 eval_set=None,
                 metric=None,
                 log_token=None,
                 multicost=False):
        """
        Create a callbacks container with the default callbacks.

        Arguments:
            model (Model): the model object
            output_file (string, optional): path to save callback data to
            eval_freq (int, optional): how often (in epochs) to run evaluation
            progress_bar (bool): control whether a progress bar callback is created.
                                 Defaults to True.
            save_path (string): file path to save model snapshots (default: None)
            serialize (int): serialize model every N epochs (default: 0)
            history (int): number of checkpoint files to retain (default: 1)
            model_file(string, optional): file to load weights (serialized model) from
            eval_set (NervanaDataIterator, optional): the dataset upon which to evaluate
                                                      loss or metric
            metric (Metric, optional):  metric to evaluate
            multicost (bool, optional): use the multicost callback. default to false.
        """
        # once the deprecated args are removed the kwargs will also be removed
        # as well as the code below
        # epochs had to be completely remove since it is often passed by argparser args
        if train_set is not None:
            logger.warning("Deprecation warning.  Callbacks class no longer "
                           "accepts train_set as a parameter.  This argument will "
                           "be removed soon update your code.")

        super(Callbacks, self).__init__(name=None)
        self.callbacks = list()
        self.epoch_marker = 0
        self.output_file = output_file
        if output_file is None:
            if hasattr(self, 'callback_data'):
                del self.callback_data
            # self.name sould give a unique filename
            self.callback_data = h5py.File(self.name, driver='core', backing_store=False)
        else:
            if os.path.isfile(output_file):
                logger.warn("Overwriting output file %s", output_file)
                os.remove(output_file)
            self.callback_data = h5py.File(output_file, "w")

        self.model = weakref.ref(model)

        self.model_file = model_file

        if multicost is True:
            self.add_callback(TrainMulticostCallback())
        else:
            self.add_callback(TrainCostCallback())

        if progress_bar:
            self.add_callback(ProgressBarCallback())

        if eval_freq:
            if not eval_set:
                err_msg = 'Evaluation frequency specified but no eval set provided!'
                logger.exception(err_msg)
                raise ValueError(err_msg)

            ecb = LossCallback(eval_set, eval_freq)
            self.add_callback(ecb, insert_pos=0)
            if metric:
                ecb = MetricCallback(eval_set, metric, eval_freq)
                self.add_callback(ecb, insert_pos=None)

        self.save_path = save_path
        if save_path:
            serialize_interval = serialize if serialize > 1 else 1
            scb = SerializeModelCallback(save_path, serialize_interval, history)
            self.add_callback(scb)

        self.add_callback(TrainLoggerCallback())
        self.add_callback(RunTimerCallback())

        try:
            # Register if it exists
            from cloud_metrics import CloudMetricsCallback
            self.add_callback(CloudMetricsCallback(log_token, eval_freq, metric))
        except ImportError:
            pass
def __init__ ( self , model , train_set = None , output_file = None , eval_freq = None , progress_bar = True , save_path = None , serialize = 0 , history = 1 , model_file = None , eval_set = None , metric = None , log_token = None , multicost = False ) : # once the deprecated args are removed the kwargs will also be removed # as well as the code below # epochs had to be completely remove since it is often passed by argparser args if train_set is not None : logger . warning ( "Deprecation warning.  Callbacks class no longer " "accepts train_set as a parameter.  This argument will " "be removed soon update your code." ) super ( Callbacks , self ) . __init__ ( name = None ) self . callbacks = list ( ) self . epoch_marker = 0 self . output_file = output_file if output_file is None : if hasattr ( self , 'callback_data' ) : del self . callback_data # self.name sould give a unique filename self . callback_data = h5py . File ( self . name , driver = 'core' , backing_store = False ) else : if os . path . isfile ( output_file ) : logger . warn ( "Overwriting output file %s" , output_file ) os . remove ( output_file ) self . callback_data = h5py . File ( output_file , "w" ) self . model = weakref . ref ( model ) self . model_file = model_file if multicost is True : self . add_callback ( TrainMulticostCallback ( ) ) else : self . add_callback ( TrainCostCallback ( ) ) if progress_bar : self . add_callback ( ProgressBarCallback ( ) ) if eval_freq : if not eval_set : err_msg = 'Evaluation frequency specified but no eval set provided!' logger . exception ( err_msg ) raise ValueError ( err_msg ) ecb = LossCallback ( eval_set , eval_freq ) self . add_callback ( ecb , insert_pos = 0 ) if metric : ecb = MetricCallback ( eval_set , metric , eval_freq ) self . add_callback ( ecb , insert_pos = None ) self . save_path = save_path if save_path : serialize_interval = serialize if serialize > 1 else 1 scb = SerializeModelCallback ( save_path , serialize_interval , history ) self . add_callback ( scb ) self . add_callback ( TrainLoggerCallback ( ) ) self . add_callback ( RunTimerCallback ( ) ) try : # Register if it exists from cloud_metrics import CloudMetricsCallback self . add_callback ( CloudMetricsCallback ( log_token , eval_freq , metric ) ) except ImportError : pass