Ejemplo n.º 1
0
 def dump_torch(file, data, **kwargs):
     import torch
     with as_file_descriptor(file, mode='wb') as writer:
         return torch.save(data, writer, **kwargs)
Ejemplo n.º 2
0
def dump_pickle(data, file, **kwargs):
    pickle = _import_pickle()
    with as_file_descriptor(file, mode='wb') as writer:
        pickle.dump(data, writer, **kwargs)
Ejemplo n.º 3
0
 def load_torch(file, **kwargs):
     import torch
     with as_file_descriptor(file, mode='rb') as reader:
         return torch.load(reader, **kwargs)
Ejemplo n.º 4
0
def load_pickle(file, **kwargs):
    pickle = _import_pickle()
    with as_file_descriptor(file, mode='rb') as reader:
        return pickle.load(reader, **kwargs)
Ejemplo n.º 5
0
def load_json(file, **kwargs):
    import json
    with as_file_descriptor(file, mode='r') as reader:
        return json.load(reader, **kwargs)
Ejemplo n.º 6
0
 def dump_yaml(file, data, **kwargs):
     with as_file_descriptor(file, mode='w') as writer:
         return yaml.dump(data, writer, **kwargs)
Ejemplo n.º 7
0
 def load_yaml(file, **kwargs):
     kwargs.setdefault('Loader', yaml.FullLoader)
     with as_file_descriptor(file, mode='r') as reader:
         return yaml.load(reader, **kwargs)
Ejemplo n.º 8
0
def dump_json(file, data, **kwargs):
    import json
    kwargs.setdefault('indent', 4)
    with as_file_descriptor(file, mode='w') as writer:
        json.dump(data, writer, **kwargs)