22 #ifndef SINGA_UTILS_SNAPSHOT_H_ 23 #define SINGA_UTILS_SNAPSHOT_H_ 25 #include "singa/io/reader.h" 26 #include "singa/io/writer.h" 27 #include "singa/utils/logging.h" 28 #include "singa/proto/core.pb.h" 29 #include "singa/core/tensor.h" 32 #include <unordered_set> 33 #include <unordered_map> 46 enum Mode { kRead, kWrite };
53 Snapshot(
const std::string& prefix, Mode mode,
int max_param_size = 10);
56 std::vector<std::pair<std::string, Tensor>>
Read();
58 std::vector<std::pair<std::string, Shape>>
ReadShape();
66 void Write(
const std::string& key,
const Tensor& param);
77 std::unique_ptr<io::BinFileWriter> bin_writer_ptr_;
78 std::unique_ptr<io::Writer> text_writer_ptr_;
79 std::unique_ptr<io::BinFileReader> bin_reader_ptr_;
81 std::unordered_set<std::string> param_names_;
83 std::unordered_map<std::string, Tensor> param_map_;
87 #endif // SINGA_UTILS_SNAPSHOT_H_ std::vector< std::pair< std::string, Tensor > > Read()
Read parameters saved as tensors from checkpoint file.
Snapshot(const std::string &prefix, Mode mode, int max_param_size=10)
<prefix>.model is the binary file for parameter key-value pair.
int version() const
available for singa > 1.0.1
Definition: snapshot.h:68
A Tensor instance is a multi-dimensional array resident on a Device (default device is the host CPU)...
Definition: tensor.h:56
std::vector< std::pair< std::string, Shape > > ReadShape()
Read parameter shapes from description file.
void Write(const std::string &key, const Tensor ¶m)
Serialize and dump out parameter.
The snapshot management.
Definition: snapshot.h:44
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: common.h:48