def _optimistic_restore_model(self, sess):
    '\n        restore weights of same names with model.\n        :param sess:\n        :return:\n        '
    if (self.restore_ckpt_file is None):
        logger.warn(Color.yellow('No ckpt file for restore vars, ckpt file is None'))
        return False
    reader = tf.train.NewCheckpointReader(self.restore_ckpt_file)
    saved_shapes = reader.get_variable_to_shape_map()
    if (self._var_list is None):
        restore_key2vars = {var.name.split(':')[0]: var for var in tf.global_variables()}
    elif isinstance(self._var_list, list):
        restore_key2vars = {var.name.split(':')[0]: var for var in self._var_list}
    elif isinstance(self._var_list, dict):
        restore_key2vars = self._var_list
    else:
        raise RuntimeError('type error {}'.format(self._var_list))
    assert (len(restore_key2vars) > 0)
    restore_key2vars = sorted([(k, v) for (k, v) in restore_key2vars.items() if (k in saved_shapes)])
    msg = []
    var_list = dict()
    with tf.variable_scope('', reuse=True):
        for (key, var) in restore_key2vars:
            var_shape = var.get_shape().as_list()
            if (var_shape == saved_shapes[key]):
                var_list[key] = var
                var_name = var.name[:var.name.index(':')]
                msg.append(('- restoring variable: {}'.format(var_name) if (var_name == key) else '- restoring variable {} from {}'.format(var_name, key)))
            else:
                msg.append(Color.yellow('- variable({}) with inconsistent shape: {}(graph) != {}(ckpt)'.format(key, var_shape, saved_shapes[key])))
    if (len(var_list) != 0):
        msg += ['- total variable count: {}'.format(len(var_list))]
        logger.info('\n'.join(msg))
        saver = tf.train.Saver(var_list, name='tk_restore')
        saver.restore(sess, self.restore_ckpt_file)
        return True
    else:
        logger.warn(Color.yellow('No vars need to restore from file: {}'.format(self.restore_ckpt_file)))
    return False
restore weights of same names with model.
:param sess:
:return:
def _optimistic_restore_model(self, sess):
    '\n        restore weights of same names with model.\n        :param sess:\n        :return:\n        '
    if (self.restore_ckpt_file is None):
        logger.warn(Color.yellow('No ckpt file for restore vars, ckpt file is None'))
        return False
    reader = tf.train.NewCheckpointReader(self.restore_ckpt_file)
    saved_shapes = reader.get_variable_to_shape_map()
    if (self._var_list is None):
        restore_key2vars = {var.name.split(':')[0]: var for var in tf.global_variables()}
    elif isinstance(self._var_list, list):
        restore_key2vars = {var.name.split(':')[0]: var for var in self._var_list}
    elif isinstance(self._var_list, dict):
        restore_key2vars = self._var_list
    else:
        raise RuntimeError('type error {}'.format(self._var_list))
    assert (len(restore_key2vars) > 0)
    restore_key2vars = sorted([(k, v) for (k, v) in restore_key2vars.items() if (k in saved_shapes)])
    msg = []
    var_list = dict()
    with tf.variable_scope(, reuse=True):
        for (key, var) in restore_key2vars:
            var_shape = var.get_shape().as_list()
            if (var_shape == saved_shapes[key]):
                var_list[key] = var
                var_name = var.name[:var.name.index(':')]
                msg.append(('- restoring variable: {}'.format(var_name) if (var_name == key) else '- restoring variable {} from {}'.format(var_name, key)))
            else:
                msg.append(Color.yellow('- variable({}) with inconsistent shape: {}(graph) != {}(ckpt)'.format(key, var_shape, saved_shapes[key])))
    if (len(var_list) != 0):
        msg += ['- total variable count: {}'.format(len(var_list))]
        logger.info('\n'.join(msg))
        saver = tf.train.Saver(var_list, name='tk_restore')
        saver.restore(sess, self.restore_ckpt_file)
        return True
    else:
        logger.warn(Color.yellow('No vars need to restore from file: {}'.format(self.restore_ckpt_file)))
    return False