当前位置: 首页>>代码示例>>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;未经允许,请勿转载。