Пример #1
0
 def dump_model(self, epoch=None):
     """
     Dump the model into a pickled version in the model path formulated in the initialisation method.
     """
     p = paths.get_model_path(self.get_root_path(), self.model_name, self.n_in, self.n_hidden, self.n_out)
     if not epoch is None: p += "_epoch_%i" % epoch
     if self.model_params is None:
         raise ("Model params are not set and can therefore not be pickled.")
     model_params = [param.get_value() for param in self.model_params]
     pkl.dump(model_params, open(p, "wb"), protocol=pkl.HIGHEST_PROTOCOL)
Пример #2
0
 def dump_model(self, epoch=None):
     """
     Dump the model into a pickled version in the model path formulated in the initialisation method.
     """
     p = paths.get_model_path(self.get_root_path(), self.model_name,
                              self.n_in, self.n_hidden, self.n_out)
     if not epoch is None: p += "_epoch_%i" % epoch
     if self.model_params is None:
         raise "Model params are not set and can therefore not be pickled."
     model_params = [param.get_value() for param in self.model_params]
     pkl.dump(model_params, open(p, "wb"), protocol=pkl.HIGHEST_PROTOCOL)
 def load_model(self, id):
     """
     Load the pickled version of the model into a 'new' model instance.
     :param id: The model ID is constructed from the timestamp when the model was defined.
     """
     model_params = (self.model_name, self.n_in, self.n_hidden, self.n_out, id)
     root = paths.get_root_output_path(*model_params)
     p = paths.get_model_path(root, *model_params[:-1])
     model_params = pkl.load(open(p, "rb"))
     for i in range(len(self.model_params)):
         self.model_params[i].set_value(np.asarray(model_params[i], dtype=theano.config.floatX), borrow=True)
Пример #4
0
 def load_model(self, id):
     """
     Load the pickled version of the model into a 'new' model instance.
     :param id: The model ID is constructed from the timestamp when the model was defined.
     """
     model_params = (self.model_name, self.n_in, self.n_hidden, self.n_out,
                     id)
     root = paths.get_root_output_path(*model_params)
     p = paths.get_model_path(root, *model_params[:-1])
     model_params = pkl.load(open(p, "rb"))
     for i in range(len(self.model_params)):
         self.model_params[i].set_value(np.asarray(
             model_params[i], dtype=theano.config.floatX),
                                        borrow=True)
Пример #5
0
 def load_model(self, id):
     """
     Load the pickled version of the model into a 'new' model instance.
     :param id: The model ID is constructed from the timestamp when the model was defined.
     """
     model_params = (self.model_name, self.n_in, self.n_hidden, self.n_out, id)
     root = paths.get_root_output_path(*model_params)
     self.root_path = root
     p = paths.get_model_path(root, *model_params[:-1])
     model_params = pkl.load(open(p, "rb"))
     for i in range(len(self.model_params)):
         init_param = self.model_params[i]
         loaded_param = model_params[i]
         if not loaded_param.shape == tuple(init_param.shape.eval()):
             print "Model could not be loaded, since parameters are not aligned."
         self.model_params[i].set_value(np.asarray(model_params[i], dtype=theano.config.floatX), borrow=True)
Пример #6
0
 def load_model(self, id):
     """
     Load the pickled version of the model into a 'new' model instance.
     :param id: The model ID is constructed from the timestamp when the model was defined.
     """
     model_params = (self.model_name, self.n_in, self.n_hidden, self.n_out,
                     id)
     root = paths.get_root_output_path(*model_params)
     self.root_path = root
     p = paths.get_model_path(root, *model_params[:-1])
     model_params = pkl.load(open(p, "rb"))
     for i in range(len(self.model_params)):
         init_param = self.model_params[i]
         loaded_param = model_params[i]
         if not loaded_param.shape == tuple(init_param.shape.eval()):
             print "Model could not be loaded, since parameters are not aligned."
         self.model_params[i].set_value(np.asarray(
             model_params[i], dtype=theano.config.floatX),
                                        borrow=True)