當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.savez_compressed方法代碼示例

本文整理匯總了Python中numpy.savez_compressed方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.savez_compressed方法的具體用法?Python numpy.savez_compressed怎麽用?Python numpy.savez_compressed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.savez_compressed方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: process_training_data

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def process_training_data(num_clips):
    """
    Processes random training clips from the full training data. Saves to TRAIN_DIR_CLIPS by
    default.

    @param num_clips: The number of clips to process. Default = 5000000 (set in __main__).

    @warning: This can take a couple of hours to complete with large numbers of clips.
    """
    num_prev_clips = len(glob(c.TRAIN_DIR_CLIPS + '*'))

    for clip_num in xrange(num_prev_clips, num_clips + num_prev_clips):
        clip = process_clip()

        np.savez_compressed(c.TRAIN_DIR_CLIPS + str(clip_num), clip)

        if (clip_num + 1) % 100 == 0: print 'Processed %d clips' % (clip_num + 1) 
開發者ID:dyelax,項目名稱:Adversarial_Video_Generation,代碼行數:19,代碼來源:process_data.py

示例2: write_cache_file

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def write_cache_file(cache_filename, Y, image_IDs):
    """ Writes data to a cache file using np.savez_compressed

    Args:
        cache_filename (str): cache filename
        Y (np.ndarray): data to write to cache file
        image_IDs (iterable): list of image IDs corresponding to data in cache
            file. If not specified, function will not check for correspondence

    """
    np.savez_compressed(cache_filename, **{
        'Y': Y, _image_ID_str: image_IDs
    })


# Cache file updating 
開發者ID:ceholden,項目名稱:yatsm,代碼行數:18,代碼來源:cache.py

示例3: save_subvolume

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def save_subvolume(labels, origins, output_path, **misc_items):
  """Saves an FFN subvolume.

  Args:
    labels: 3d zyx number array with the segment labels
    origins: dictionary mapping segment ID to origin information
    output_path: path at which to save the segmentation in the form
        of a .npz file
    **misc_items: (optional) additional values to save
        in the output file
  """
  seg = segmentation.reduce_id_bits(labels)
  gfile.MakeDirs(os.path.dirname(output_path))
  with atomic_file(output_path) as fd:
    np.savez_compressed(fd,
                        segmentation=seg,
                        origins=origins,
                        **misc_items) 
開發者ID:google,項目名稱:ffn,代碼行數:20,代碼來源:storage.py

示例4: save_checkpoint

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def save_checkpoint(self, path):
    """Saves a inference checkpoint to `path`."""
    self.log_info('Saving inference checkpoint to %s.', path)
    with timer_counter(self.counters, 'save_checkpoint'):
      gfile.MakeDirs(os.path.dirname(path))
      with storage.atomic_file(path) as fd:
        seed_policy_state = None
        if self.seed_policy is not None:
          seed_policy_state = self.seed_policy.get_state()

        np.savez_compressed(fd,
                            movement_policy=self.movement_policy.get_state(),
                            segmentation=self.segmentation,
                            seg_qprob=self.seg_prob,
                            seed=self.seed,
                            origins=self.origins,
                            overlaps=self.overlaps,
                            history=np.array(self.history),
                            history_deleted=np.array(self.history_deleted),
                            seed_policy_state=seed_policy_state,
                            counters=self.counters.dumps())
    self.log_info('Inference checkpoint saved.') 
開發者ID:google,項目名稱:ffn,代碼行數:24,代碼來源:inference.py

示例5: fill_mesh

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def fill_mesh(mesh2fill, file: str, opt):
    load_path = get_mesh_path(file, opt.num_aug)
    if os.path.exists(load_path):
        mesh_data = np.load(load_path, encoding='latin1', allow_pickle=True)
    else:
        mesh_data = from_scratch(file, opt)
        np.savez_compressed(load_path, gemm_edges=mesh_data.gemm_edges, vs=mesh_data.vs, edges=mesh_data.edges,
                            edges_count=mesh_data.edges_count, ve=mesh_data.ve, v_mask=mesh_data.v_mask,
                            filename=mesh_data.filename, sides=mesh_data.sides,
                            edge_lengths=mesh_data.edge_lengths, edge_areas=mesh_data.edge_areas,
                            features=mesh_data.features)
    mesh2fill.vs = mesh_data['vs']
    mesh2fill.edges = mesh_data['edges']
    mesh2fill.gemm_edges = mesh_data['gemm_edges']
    mesh2fill.edges_count = int(mesh_data['edges_count'])
    mesh2fill.ve = mesh_data['ve']
    mesh2fill.v_mask = mesh_data['v_mask']
    mesh2fill.filename = str(mesh_data['filename'])
    mesh2fill.edge_lengths = mesh_data['edge_lengths']
    mesh2fill.edge_areas = mesh_data['edge_areas']
    mesh2fill.features = mesh_data['features']
    mesh2fill.sides = mesh_data['sides'] 
開發者ID:ranahanocka,項目名稱:MeshCNN,代碼行數:24,代碼來源:mesh_prepare.py

示例6: combine_levels

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def combine_levels(directory):
    """
    Merge all files in a single directory.
    """
    files = sorted(glob.glob(os.path.join(directory, '*.npz')))
    all_data = []
    max_name_len = 0
    for file in files:
        with np.load(file) as data:
            name = os.path.split(file)[1]
            max_name_len = max(max_name_len, len(name))
            all_data.append(data.items() + [('name', name)])
    dtype = []
    for key, val in all_data[0][:-1]:
        dtype.append((key, val.dtype, val.shape))
    dtype.append(('name', str, max_name_len))
    combo_data = np.array([
        tuple([val for key, val in data]) for data in all_data
    ], dtype=dtype)
    np.savez_compressed(directory + '.npz', levels=combo_data) 
開發者ID:PartnershipOnAI,項目名稱:safelife,代碼行數:22,代碼來源:level_iterator.py

示例7: save_twiss_file

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def save_twiss_file(self, twiss_list):
        if self.tws_file is None:
            tws_file_name = self.output_beam_file.replace("particles", "tws")
        else:
            tws_file_name = self.tws_file

        self.folder_check_create(tws_file_name)

        bx = np.array([tw.beta_x for tw in twiss_list])
        by = np.array([tw.beta_y for tw in twiss_list])
        ax = np.array([tw.alpha_x for tw in twiss_list])
        ay = np.array([tw.alpha_x for tw in twiss_list])
        s = np.array([tw.s for tw in twiss_list])
        E = np.array([tw.E for tw in twiss_list])

        emit_x = np.array([tw.emit_x for tw in twiss_list])
        emit_y = np.array([tw.emit_y for tw in twiss_list])

        np.savez_compressed(tws_file_name, beta_x=bx, beta_y=by, alpha_x=ax, alpha_y=ay, E=E, s=s,
                            emit_x=emit_x, emit_y=emit_y) 
開發者ID:ocelot-collab,項目名稱:ocelot,代碼行數:22,代碼來源:section_track.py

示例8: main

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("src_path", type=str)
    parser.add_argument("dst_path", type=str)
    args = parser.parse_args()

    src_path = Path(args.src_path)
    dst_path = Path(args.dst_path)

    assert src_path.is_file()
    src_trajs = types.load(str(src_path))
    dst_trajs = convert_trajs_to_sb(src_trajs)
    os.makedirs(dst_path.parent, exist_ok=True)
    with open(dst_path, "wb") as f:
        np.savez_compressed(f, **dst_trajs)

    print(f"Dumped rollouts to {dst_path}") 
開發者ID:HumanCompatibleAI,項目名稱:imitation,代碼行數:19,代碼來源:convert_traj.py

示例9: export_trimmed_glove_vectors

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def export_trimmed_glove_vectors(vocab, glove_filename, trimmed_filename, dim):
    """Saves glove vectors in numpy array

    Args:
        vocab: dictionary vocab[word] = index
        glove_filename: a path to a glove file
        trimmed_filename: a path where to store a matrix in npy
        dim: (int) dimension of embeddings

    """
    embeddings = np.zeros([len(vocab), dim])
    with open(glove_filename, encoding="utf8") as f:
        for line in f:
            line = line.strip().split(' ')
            word = line[0]
            embedding = [float(x) for x in line[1:]]
            if word in vocab:
                word_idx = vocab[word]
                embeddings[word_idx] = np.asarray(embedding)

    np.savez_compressed(trimmed_filename, embeddings=embeddings) 
開發者ID:yongyuwen,項目名稱:PyTorch-Elmo-BiLSTMCRF,代碼行數:23,代碼來源:data_utils.py

示例10: average_model_chainer

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def average_model_chainer(ifiles, ofile):
    omodel = {}
    # get keys from the first file
    model = np.load(ifiles[0])
    for x in model:
        if 'model' in x:
            print(x)
    keys = [x.split('main/')[1] for x in model if 'model' in x]
    print(keys)
    for path in ifiles:
        model = np.load(path)
        for key in keys:
            val = model['updater/model:main/{}'.format(key)]
            if key not in omodel:
                omodel[key] = val
            else:
                omodel[key] += val
    for key in keys:
        omodel[key] /= len(ifiles)
    np.savez_compressed(ofile, **omodel) 
開發者ID:hitachi-speech,項目名稱:EEND,代碼行數:22,代碼來源:model_averaging.py

示例11: main

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def main():
    env = gym.make('FetchPickAndPlace-v0')
    numItr = 100
    initStateSpace = "random"
    env.reset()
    print("Reset!")
    while len(actions) < numItr:
        obs = env.reset()
        print("ITERATION NUMBER ", len(actions))
        goToGoal(env, obs)
        

    fileName = "data_fetch"
    fileName += "_" + initStateSpace
    fileName += "_" + str(numItr)
    fileName += ".npz"
    
    np.savez_compressed(fileName, acs=actions, obs=observations, info=infos) # save the file 
開發者ID:hiwonjoon,項目名稱:ICML2019-TREX,代碼行數:20,代碼來源:fetch_data_generation.py

示例12: backup_batches

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def backup_batches(batches_vol, batches_seg, path, case_id):
    # Create model directory of not existent
    if not os.path.exists(path):
        os.mkdir(path)
    # Create subdirectory for the case if not existent
    case_dir = os.path.join(path, "tmp.case_" + str(case_id).zfill(5))
    if not os.path.exists(case_dir):
        os.mkdir(case_dir)
    # Backup volume batches
    if batches_vol is not None:
        for i, batch in enumerate(batches_vol):
            out_path = os.path.join(case_dir,
                                    "batch_vol." + str(i))
            np.savez(out_path, data=batch)

    # Backup segmentation batches
    if batches_seg is not None:
        for i, batch in enumerate(batches_seg):
            out_path = os.path.join(case_dir,
                                    "batch_seg." + str(i))
            np.savez_compressed(out_path, data=batch)

# Load a MRI object from a npz for fast access 
開發者ID:muellerdo,項目名稱:kits19.MIScnn,代碼行數:25,代碼來源:data_io.py

示例13: generate_large_matrix

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def generate_large_matrix():
    rows, cols = 1000000, 500
    print 'Test serializing a %i x %i matrix ...' % (rows, cols)
    t = time.time()
    vecs = numpy.random.normal(0,1,(rows,cols))
    print 'Matrix constructed, spent %.2f s' % (time.time() - t)

    f1 = open('test_data1', 'wb')
    t = time.time()
    print 'saving as numpy npz format ...'
    numpy.savez_compressed(f1, vecs)
    print 'save done, spent %.2f s' % (time.time() - t)
    f1.close()

    f2 = open('test_data2', 'wb')
    t = time.time()
    print 'saving as self-defined format ...'
    for v in vecs:
        f2.write(pickle.dumps(v, -1))
    f2.close()
    print 'save done, spent %.2f s' % (time.time() - t)
    pass 
開發者ID:ryanrhymes,項目名稱:panns,代碼行數:24,代碼來源:test_mmap.py

示例14: export_trimmed_glove_vectors

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def export_trimmed_glove_vectors(vocab, glove_filename, trimmed_filename, dim):
    """Saves glove vectors in numpy array

    Args:
        vocab: dictionary vocab[word] = index
        glove_filename: a path to a glove file
        trimmed_filename: a path where to store a matrix in npy
        dim: (int) dimension of embeddings

    """
    embeddings = np.zeros([len(vocab), dim])
    with open(glove_filename) as f:
        for line in f:
            line = line.strip().split(' ')
            word = line[0]
            embedding = [float(x) for x in line[1:]]
            if word in vocab:
                word_idx = vocab[word]
                embeddings[word_idx] = np.asarray(embedding)

    np.savez_compressed(trimmed_filename, embeddings=embeddings) 
開發者ID:ijmarshall,項目名稱:robotreviewer,代碼行數:23,代碼來源:ner_data_utils.py

示例15: encode

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import savez_compressed [as 別名]
def encode(self, unischema_field, value):
        expected_dtype = unischema_field.numpy_dtype
        if isinstance(value, np.ndarray):
            if expected_dtype != value.dtype.type:
                raise ValueError('Unexpected type of {} feature. '
                                 'Expected {}. Got {}'.format(unischema_field.name, expected_dtype, value.dtype))

            expected_shape = unischema_field.shape
            if not _is_compliant_shape(value.shape, expected_shape):
                raise ValueError('Unexpected dimensions of {} feature. '
                                 'Expected {}. Got {}'.format(unischema_field.name, expected_shape, value.shape))
        else:
            raise ValueError('Unexpected type of {} feature. '
                             'Expected ndarray of {}. Got {}'.format(unischema_field.name, expected_dtype, type(value)))

        memfile = BytesIO()
        np.savez_compressed(memfile, arr=value)
        return bytearray(memfile.getvalue()) 
開發者ID:uber,項目名稱:petastorm,代碼行數:20,代碼來源:codecs.py


注:本文中的numpy.savez_compressed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。