Class DataHelper
Defined in File data_helper.h
Class Documentation
-
class DataHelper
Simple class to do data manipulation, contains helper function to update json files in dataset.
Public Functions
-
DataHelper() = default
constructor
-
~DataHelper() = default
Destructor.
-
inline Status CreateAlbum(const std::string &in_dir, const std::string &out_dir)
Create an Album dataset while taking in a path to a image folder Creates the output directory if doesn’t exist.
- Parameters
in_dir – [in] Image folder directory that takes in images
out_dir – [in] Directory containing output json files
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<std::string> &value, const std::string &out_file = "")
Update a json file field with a vector of string values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional input for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<bool> &value, const std::string &out_file = "")
Update a json file field with a vector of bool values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<int8_t> &value, const std::string &out_file = "")
Update a json file field with a vector of int8 values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<uint8_t> &value, const std::string &out_file = "")
Update a json file field with a vector of uint8 values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<int16_t> &value, const std::string &out_file = "")
Update a json file field with a vector of int16 values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<uint16_t> &value, const std::string &out_file = "")
Update a json file field with a vector of uint16 values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<int32_t> &value, const std::string &out_file = "")
Update a json file field with a vector of int32 values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<uint32_t> &value, const std::string &out_file = "")
Update a json file field with a vector of uint32 values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<int64_t> &value, const std::string &out_file = "")
Update a json file field with a vector of int64 values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<uint64_t> &value, const std::string &out_file = "")
Update a json file field with a vector of uint64 values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<float> &value, const std::string &out_file = "")
Update a json file field with a vector of float values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateArray(const std::string &in_file, const std::string &key, const std::vector<double> &value, const std::string &out_file = "")
Update a json file field with a vector of double values.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value array to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const std::string &value, const std::string &out_file = "")
Update a json file field with a string value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const bool &value, const std::string &out_file = "")
Update a json file field with a bool value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const int8_t &value, const std::string &out_file = "")
Update a json file field with an int8 value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const uint8_t &value, const std::string &out_file = "")
Update a json file field with an uint8 value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const int16_t &value, const std::string &out_file = "")
Update a json file field with an int16 value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const uint16_t &value, const std::string &out_file = "")
Update a json file field with an uint16 value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const int32_t &value, const std::string &out_file = "")
Update a json file field with an int32 value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const uint32_t &value, const std::string &out_file = "")
Update a json file field with an uint32 value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const int64_t &value, const std::string &out_file = "")
Update a json file field with an int64 value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const uint64_t &value, const std::string &out_file = "")
Update a json file field with an uint64 value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const float &value, const std::string &out_file = "")
Update a json file field with a float value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
inline Status UpdateValue(const std::string &in_file, const std::string &key, const double &value, const std::string &out_file = "")
Update a json file field with a double value.
- Parameters
in_file – The input file name to read in
key – Key of field to write to
value – Value to write to file
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
template<typename T>
inline Status WriteBinFile(const std::string &in_file, const std::vector<T> &data) Template function to write tensor to file.
- Parameters
in_file – [in] File to write to
data – [in] Array of type T values
- Returns
Status The status code returned
-
template<typename T>
inline Status WriteBinFile(const std::string &in_file, T *data, size_t length) Write pointer to bin, use pointer to avoid memcpy.
Note
The value of
length
must be equal to the length of
data`- Parameters
in_file – [in] File name to write to
data – [in] Pointer to data
length – [in] Length of values to write from pointer
- Returns
Status The status code returned
-
size_t DumpData(const unsigned char *tensor_addr, const size_t &tensor_size, void *addr, const size_t &buffer_size)
Helper function to copy content of a tensor to buffer.
Note
This function iterates over the tensor in bytes, since
- Parameters
tensor_addr – [in] The memory held by a tensor
tensor_size – [in] The amount of data in bytes in tensor_addr, e.g. tensor->SizeInBytes()
addr – [out] The address to copy tensor data to
buffer_size – [in] The buffer size of addr
- Returns
The size of the tensor (bytes copied
-
inline Status RemoveKey(const std::string &in_file, const std::string &key, const std::string &out_file = "")
Helper function to delete key in json file.
Note
This function will return okay even if key not found
- Parameters
in_file – [in] Json file to remove key from
key – [in] The key to remove
out_file – Optional parameter for output file path, will write to input file if not specified
- Returns
Status The status code returned
-
void Print(std::ostream &out) const
A print method typically used for debugging.
- Parameters
out – - The output stream to write output to
-
DataHelper() = default