LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
data_reader_hdf5_legacy.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
27 // may not use this file except in compliance with the License. You may
28 // obtain a copy of the License at:
29 //
30 // http://www.apache.org/licenses/LICENSE-2.0
31 //
32 // Unless required by applicable law or agreed to in writing, software
33 // distributed under the License is distributed on an "AS IS" BASIS,
34 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
35 // implied. See the License for the specific language governing
36 // permissions and limitations under the license.
37 //
39 #ifndef LBANN_DATA_READER_HDF5_HPP
40 #define LBANN_DATA_READER_HDF5_HPP
41 #include "conduit/conduit.hpp"
42 #include "data_reader_image.hpp"
43 #include "hdf5.h"
44 
45 namespace lbann {
63 template <typename TensorDataType>
65 {
66 public:
67  hdf5_reader(const bool shuffle,
68  const std::string key_data,
69  const std::string key_label,
70  const std::string key_responses,
71  const bool hyperslab_labels);
72  hdf5_reader(const hdf5_reader&);
74  ~hdf5_reader() override {}
75 
76  hdf5_reader* copy() const override { return new hdf5_reader(*this); }
77 
78  void copy_members(const hdf5_reader& rhs);
79 
80  std::string get_type() const override { return "data_reader_hdf5_images"; }
81  // void set_input_params(int width, int height, int depth, int num_ch, int
82  // num_labels);
83  void load() override;
84  void set_hdf5_paths(const std::vector<std::string> hdf5_paths)
85  {
86  m_file_paths = hdf5_paths;
87  }
88 
89  void set_num_responses(const size_t num_responses)
90  {
91  m_all_responses.resize(num_responses);
92  }
93 
94  int get_num_labels() const override
95  {
96  if (!this->has_labels()) {
98  }
99  // This data reader currently assumes that the shape of the label
100  // tensor is the same to the data tensor.
101  return m_num_features;
102  }
103  int get_num_responses() const override
104  {
105  if (!this->has_responses()) {
107  }
109  }
110  int get_linearized_data_size() const override { return m_num_features; }
111  int get_linearized_label_size() const override
112  {
113  if (!this->has_labels()) {
115  }
116  // This data reader currently assumes that the shape of the label
117  // tensor is the same to the data tensor.
118  return m_num_features;
119  }
120  int get_linearized_response_size() const override
121  {
122  if (!this->has_responses()) {
124  }
125  return m_all_responses.size();
126  }
127  const std::vector<El::Int> get_data_dims() const override { return m_data_dims; }
128 
129 #ifdef LBANN_HAS_DISTCONV
130  bool is_tensor_shuffle_required() const override { return false; }
131 #endif // LBANN_HAS_DISTCONV
132 
133 protected:
134  void read_hdf5_hyperslab(hsize_t h_data,
135  hsize_t filespace,
136  int rank,
137  TensorDataType* sample);
138  void
139  read_hdf5_sample(int data_id, TensorDataType* sample, TensorDataType* labels);
140  // void set_defaults() override;
141  void load_sample(conduit::Node& node, int data_id);
142  bool fetch_datum(CPUMat& X, int data_id, int mb_idx) override;
143  void fetch_datum_conduit(Mat& X, int data_id);
144  bool fetch_data_field(data_field_type data_field,
145  CPUMat& Y,
146  int data_id,
147  int mb_idx) override;
148  bool fetch_label(CPUMat& Y, int data_id, int mb_idx) override;
149  bool fetch_response(CPUMat& Y, int data_id, int mb_idx) override;
150  hid_t get_hdf5_data_type() const;
151  conduit::DataType get_conduit_data_type(conduit::index_t num_elements) const;
152 
153  int m_image_depth = 0;
155  std::vector<float> m_all_responses;
156  std::vector<std::string> m_file_paths;
157  MPI_Comm m_comm;
158  std::vector<El::Int> m_data_dims;
159  std::vector<hsize_t> m_hyperslab_dims;
160  hid_t m_fapl;
161  hid_t m_dxpl;
166 
167 private:
169 };
170 } // namespace lbann
171 #endif // LBANN_DATA_READER_HDF5_HPP
hdf5_reader * copy() const override
std::vector< float > m_all_responses
virtual int get_linearized_response_size() const
Get the linearized size (i.e. number of elements) in a response.
int get_num_labels() const override
Return the number of labels (classes) in this dataset.
bool fetch_response(CPUMat &Y, int data_id, int mb_idx) override
const std::vector< El::Int > get_data_dims() const override
Get the dimensions of the data.
hid_t get_hdf5_data_type() const
void set_hdf5_paths(const std::vector< std::string > hdf5_paths)
void read_hdf5_hyperslab(hsize_t h_data, hsize_t filespace, int rank, TensorDataType *sample)
static const std::string HDF5_KEY_LABELS
void load_sample(conduit::Node &node, int data_id)
virtual bool has_responses() const
std::string get_type() const override
std::vector< std::string > m_file_paths
bool fetch_label(CPUMat &Y, int data_id, int mb_idx) override
El::Matrix< DataType, El::Device::CPU > CPUMat
Definition: base.hpp:116
hdf5_reader & operator=(const hdf5_reader &)
void set_num_responses(const size_t num_responses)
hdf5_reader(const bool shuffle, const std::string key_data, const std::string key_label, const std::string key_responses, const bool hyperslab_labels)
int get_linearized_response_size() const override
Get the linearized size (i.e. number of elements) in a response.
void fetch_datum_conduit(Mat &X, int data_id)
int get_linearized_data_size() const override
Get the linearized size (i.e. number of elements) in a sample.
void copy_members(const hdf5_reader &rhs)
std::vector< hsize_t > m_hyperslab_dims
std::vector< El::Int > m_data_dims
El::Matrix< DataType, El::Device::CPU > Mat
Definition: base.hpp:185
bool fetch_data_field(data_field_type data_field, CPUMat &Y, int data_id, int mb_idx) override
Called by fetch_data, fetch_label, fetch_response.
virtual int get_num_labels() const
Return the number of labels (classes) in this dataset.
std::string data_field_type
void load() override
static const std::string HDF5_KEY_RESPONSES
virtual int get_linearized_label_size() const
Get the linearized size (i.e. number of elements) in a label.
virtual int get_num_responses() const
Return the number of responses in this dataset.
conduit::DataType get_conduit_data_type(conduit::index_t num_elements) const
void read_hdf5_sample(int data_id, TensorDataType *sample, TensorDataType *labels)
bool fetch_datum(CPUMat &X, int data_id, int mb_idx) override
virtual bool has_labels() const
int get_num_responses() const override
Return the number of responses in this dataset.
static const std::string HDF5_KEY_DATA
int get_linearized_label_size() const override
Get the linearized size (i.e. number of elements) in a label.