Load network weights.
        data_path: The path to the numpy-serialized network weights
        session: The current TensorFlow session
        ignore_missing: If true, serialized weights for missing layers are ignored.
358971
def _load(self, data_path, ignore_missing=False):
        '''
        '''
        if data_path.endswith(".npz"):
            data_dict = np.load(data_path)
            keys = sorted(data_dict.keys())
            for i, k in enumerate(keys):
                data = data_dict[k]
                op_name = "_".join(k.split("_")[:-1])
                param_name = "weights" if k.split("_")[-1] == "W" else "biases"
                if self.verbose:
                    print("Loaded: {} {}".format(op_name, param_name))
                if op_name not in self.weights:
                    self.weights[op_name] = {}
                self.weights[op_name][param_name] = data
        elif data_path.endswith(".npy"):
            data_dict = np.load(data_path).item()
            for op_name in data_dict:
                with tf.variable_scope(op_name, reuse=True):
                    for param_name, data in data_dict[op_name].iteritems():
                        if self.verbose:
                            print("Loaded: {} {}".format(op_name, param_name))
                        if op_name not in self.weights:
                            self.weights[op_name] = {}
                        self.weights[op_name][param_name] = data
        else:
            raise RuntimeError("Invalid file type.")
437860
def load(self, rel_path=None):
        
        for k, v in self.layer.iteritems():
            self.add(k, v['module'], v.get('package'))
            filename = v.get('filename')
            path = v.get('path')
            if filename:
                # default path for data is in ../data
                if not path:
                    path = rel_path
                else:
                    path = os.path.join(rel_path, path)
                # filename can be a list or a string, concatenate list with
                # os.pathsep and append the full path to strings.
                if isinstance(filename, basestring):
                    filename = os.path.join(path, filename)
                else:
                    file_list = [os.path.join(path, f) for f in filename]
                    filename = os.path.pathsep.join(file_list)
                self.open(k, filename)
1370211
def _raw_weights(self):
        
        if self._debug:
            return np.array([[],[],[],[]])

        if not self._running:
            raise ValueError('Weight sensor is not running!')
        if len(self._weight_buffers) == 0:
            time.sleep(0.3)
            if len(self._weight_buffers) == 0:
                raise ValueError('Weight sensor is not retrieving data!')
        weights = np.array(self._weight_buffers)
        return weights
676487
def load(self, path):
        
        self.dct = wrapper.Dictionary.load(path)
        return self
356656
def load_mnist(training_num=50000):
    """"""
    data_path = os.path.join(os.path.dirname(os.path.realpath('__file__')), 'mnist.npz')
    if not os.path.isfile(data_path):
        from six.moves import urllib
        origin = (
            'https://github.com/sxjscience/mxnet/raw/master/example/bayesian-methods/mnist.npz'
        )
        print('Downloading data from %s to %s' % (origin, data_path))
        ctx = ssl._create_unverified_context()
        with urllib.request.urlopen(origin, context=ctx) as u, open(data_path, 'wb') as f:
            f.write(u.read())
        print('Done!')
    dat = numpy.load(data_path)
    X = (dat['X'][:training_num] / 126.0).astype('float32')
    Y = dat['Y'][:training_num]
    X_test = (dat['X_test'] / 126.0).astype('float32')
    Y_test = dat['Y_test']
    Y = Y.reshape((Y.shape[0],))
    Y_test = Y_test.reshape((Y_test.shape[0],))
    return X, Y, X_test, Y_test
241070
def _init_network(self):
        """"""
        self.network = Network(self.problem.layers)
        self.weights = Matrices(self.network.shapes)
        if self.load:
            loaded = np.load(self.load)
            assert loaded.shape == self.weights.shape, (
                'weights to load must match problem definition')
            self.weights.flat = loaded
        else:
            self.weights.flat = np.random.normal(
                self.problem.weight_mean, self.problem.weight_scale,
                len(self.weights.flat))
1236149
def load_tf_weights_in_gpt2(model, gpt2_checkpoint_path):
    
    try:
        import re
        import numpy as np
        import tensorflow as tf
    except ImportError:
        print("Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please see "
            "https://www.tensorflow.org/install/ for installation instructions.")
        raise
    tf_path = os.path.abspath(gpt2_checkpoint_path)
    print("Converting TensorFlow checkpoint from {}".format(tf_path))
    # Load weights from TF model
    init_vars = tf.train.list_variables(tf_path)
    names = []
    arrays = []
    for name, shape in init_vars:
        print("Loading TF weight {} with shape {}".format(name, shape))
        array = tf.train.load_variable(tf_path, name)
        names.append(name)
        arrays.append(array.squeeze())

    for name, array in zip(names, arrays):
        name = name[6:]  # skip "model/"
        name = name.split('/')
        pointer = model
        for m_name in name:
            if re.fullmatch(r'[A-Za-z]+\d+', m_name):
                l = re.split(r'(\d+)', m_name)
            else:
                l = [m_name]
            if l[0] == 'w' or l[0] == 'g':
                pointer = getattr(pointer, 'weight')
            elif l[0] == 'b':
                pointer = getattr(pointer, 'bias')
            elif l[0] == 'wpe' or l[0] == 'wte':
                pointer = getattr(pointer, l[0])
                pointer = getattr(pointer, 'weight')
            else:
                pointer = getattr(pointer, l[0])
            if len(l) >= 2:
                num = int(l[1])
                pointer = pointer[num]
        try:
            assert pointer.shape == array.shape
        except AssertionError as e:
            e.args += (pointer.shape, array.shape)
            raise
        print("Initialize PyTorch weight {}".format(name))
        pointer.data = torch.from_numpy(array)
    return model
499728
def load_data(train_path='./data/regression.train', test_path='./data/regression.test'):
    '''
    
    '''
    print('Load data...')
    df_train = pd.read_csv(train_path, header=None, sep='\t')
    df_test = pd.read_csv(test_path, header=None, sep='\t')
    num = len(df_train)
    split_num = int(0.9 * num)

    y_train = df_train[0].values
    y_test = df_test[0].values
    y_eval = y_train[split_num:]
    y_train = y_train[:split_num]

    X_train = df_train.drop(0, axis=1).values
    X_test = df_test.drop(0, axis=1).values
    X_eval = X_train[split_num:, :]
    X_train = X_train[:split_num, :]

    # create dataset for lightgbm
    lgb_train = lgb.Dataset(X_train, y_train)
    lgb_eval = lgb.Dataset(X_eval, y_eval, reference=lgb_train)

    return lgb_train, lgb_eval, X_test, y_test
1179319
def init_conv_weight(layer):
    '''
    '''
    n_filters = layer.filters
    filter_shape = (layer.kernel_size,) * get_n_dim(layer)
    weight = np.zeros((n_filters, n_filters) + filter_shape)

    center = tuple(map(lambda x: int((x - 1) / 2), filter_shape))
    for i in range(n_filters):
        filter_weight = np.zeros((n_filters,) + filter_shape)
        index = (i,) + center
        filter_weight[index] = 1
        weight[i, ...] = filter_weight
    bias = np.zeros(n_filters)

    layer.set_weights(
        (add_noise(weight, np.array([0, 1])), add_noise(bias, np.array([0, 1])))
    )
46002
def load_embedding(path):
    '''
    
    '''
    EMBEDDING_DIM = 300
    embedding_dict = {}
    with open(path, 'r', encoding='utf-8') as file:
        pairs = [line.strip('\r\n').split() for line in file.readlines()]
        for pair in pairs:
            if len(pair) == EMBEDDING_DIM + 1:
                embedding_dict[pair[0]] = [float(x) for x in pair[1:]]
    logger.debug('embedding_dict size: %d', len(embedding_dict))
    return embedding_dict
335780
def load_model(file_path):
    
    if not path.exists(file_path):
        raise FileNotFoundError("{0} was not found.".format(file_path))
    model = onnx_proto.ModelProto()
    with open(file_path, 'rb') as f:
        model.ParseFromString(f.read())
    return model
820519
def __load(self, path):
        """"""
        try:
            path = os.path.abspath(path)
            with open(path, 'rb') as df:
                # loaded_dataset = pickle.load(df)
                self.__data, self.__classes, self.__labels, \
                self.__dtype, self.__description, \
                self.__num_features, self.__feature_names = pickle.load(df)

            # ensure the loaded dataset is valid
            self.__validate(self.__data, self.__classes, self.__labels)

        except IOError as ioe:
            raise IOError('Unable to read the dataset from file: {}', format(ioe))
        except:
            raise
792411
def load(cls, path):
        
        data = json.load(open(path))

        weights = data['weights']
        weights = np.asarray(weights, dtype=np.float64)

        s = cls(data['map_dimensions'],
                data['params']['lr']['orig'],
                data['data_dimensionality'],
                influence=data['params']['infl']['orig'],
                lr_lambda=data['params']['lr']['factor'],
                infl_lambda=data['params']['infl']['factor'])

        s.weights = weights
        s.trained = True

        return s
1030532
def _load(cls,
              config: Params,
              serialization_dir: str,
              weights_file: str = None,
              cuda_device: int = -1) -> 'Model':
        
        model_params = config.get('model')

        # The experiment config tells us how to _train_ a model, including where to get pre-trained
        # embeddings from.  We're now _loading_ the model, so those embeddings will already be
        # stored in our weights.  We don't need any pretrained weight file anymore, and we don't
        # want the code to look for it, so we remove it from the parameters here.
        remove_pretrained_embedding_params(model_params)
        model = Model.from_params(vocab=None, params=model_params)

        # Force model to cpu or gpu, as appropriate, to make sure that the embeddings are
        # in sync with the weights
        if cuda_device >= 0:
            model.cuda(cuda_device)
        else:
            model.cpu()

        return model
835671
def path_deserialize(cls, serialized_path):
        
        def _chomp_netstring_payload(s):
            try:
                ns_len_str, ns_body = s.split(':', 1)
                ns_len = int(ns_len_str)
                assert ns_body[ns_len] == ','
                ns_payload = ns_body[:ns_len]
                return ns_payload, ns_body[ns_len+1:]
            except:
                raise ValueError("Invalid netstring '{}'".format(s))

        path_str, extra = _chomp_netstring_payload(serialized_path)
        if len(extra) > 0:
            raise ValueError("Danlging data in '{}'".format(serialized_path))

        path = []
        while True:
            path_part, path_str = _chomp_netstring_payload(path_str)
            try:
                order, hash_hex = path_part.split('-', 1)
                assert order in ['l', 'r', 'm']
                path.append({'order': order, 'hash': hash_hex})
            except:
                raise ValueError("Invalid path entry {}".format(path_part))

            if len(path_str) == 0:
                break

        return path
172816
def init_bn_weight(layer):
    '''
    '''
    n_filters = layer.num_features
    new_weights = [
        add_noise(np.ones(n_filters, dtype=np.float32), np.array([0, 1])),
        add_noise(np.zeros(n_filters, dtype=np.float32), np.array([0, 1])),
        add_noise(np.zeros(n_filters, dtype=np.float32), np.array([0, 1])),
        add_noise(np.ones(n_filters, dtype=np.float32), np.array([0, 1])),
    ]
    layer.set_weights(new_weights)
1200767
def load_data_file(path_of_file):
    
    if os.path.exists(path_of_file):
        return storage_utils.load_objects_from_json(path_of_file)
    raise ValueError("Data file not found: {0}".format(path_of_file))