//  [python]
def restore(self, sess, model_path, no_gan=False, clear_rms=False):
        """
        Restores a session from a checkpoint

        :param sess: current session instance
        :param model_path: path to file system checkpoint location
        :param no_gan: only restore mr variables
        :param clear_rms: does not restore RMSprop internal variables, please set is true
        """
        saver = tf.train.Saver(tf.contrib.framework.get_variables() + tf.get_collection_ref("internal_batchnorm_variables") )
        logging.info("Model restored from file: %s" % model_path)
        if no_gan is True:
            logging.info("I only load the main variables! without batchnorm!!!")
            variables = tf.global_variables()
            reader = tf.pywrap_tensorflow.NewCheckpointReader(model_path)
            var_keep_dic = reader.get_variable_to_shape_map()
            variables_to_restore = []
            for v in variables:
                if v.name.split(':')[0] in var_keep_dic:
                    if ("adapt" in v.name) or ("cls" in v.name) or("Adam" in v.name):
                        continue
                    if ("group" in v.name) or ("output" in v.name):
                        logging.info("restoring "+str(v.name))
                        variables_to_restore.append(v)
            restorer = tf.train.Saver(variables_to_restore)
            restorer.restore(sess, model_path)

            logging.info("Model restored from file: %s, the pre-trained MRI model (without bn params)" % model_path)

            return 0

        if clear_rms is True:
            logging.info("Calculating RMS parameters from beginning")
            variables = tf.global_variables()
            reader = tf.pywrap_tensorflow.NewCheckpointReader(model_path)
            var_keep_dic = reader.get_variable_to_shape_map()
            variables_to_restore = []
            for v in variables:
                if v.name.split(':')[0] in var_keep_dic:
                    if ("RMS" in v.name) :
                        continue
                    else:
                        logging.info("restoring "+str(v.name))
                        variables_to_restore.append(v)
            restorer = tf.train.Saver(variables_to_restore)
            restorer.restore(sess, model_path)

            logging.info("Model restored from file: %s and RMS variables are ignored" % model_path)
            return 0

        try: # else, just restore as much as possible
            saver.restore(sess, model_path)
            logging.info("Model restored from file: %s" % model_path)
        except:
            variables = tf.global_variables()
            reader = tf.pywrap_tensorflow.NewCheckpointReader(model_path)
            var_keep_dic = reader.get_variable_to_shape_map()
            variables_to_restore = []
            for v in variables:
                if v.name.split(':')[0] in var_keep_dic:
                    skip_flg = False
                    for kwd in self.network_config["restore_skip_kwd"]: # if it is manully specified to be skipped, don't restore it
                        if kwd in v.name:
                            skip_flg = True
                            break
                    if skip_flg is False:
                        variables_to_restore.append(v)
                        logging.info("cannot fully restore the model, restoring "+str(v.name))
            restorer = tf.train.Saver(variables_to_restore)
            restorer.restore(sess, model_path)

            logging.info("Model restored from file: %s with relaxation" % model_path)