LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
data_reader_mesh.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.
25 //
26 // data_reader_mesh .hpp .cpp - data reader for mesh data
28 
29 #ifndef LBANN_DATA_READER_MESH_HPP
30 #define LBANN_DATA_READER_MESH_HPP
31 
32 #include "data_reader.hpp"
33 
34 namespace lbann {
35 
43 {
44 public:
45  mesh_reader(bool shuffle = true);
46  ~mesh_reader() override {}
47 
48  mesh_reader* copy() const override { return new mesh_reader(*this); }
49  std::string get_type() const override { return "mesh_reader"; }
50 
52  void set_suffix(const std::string suffix) { m_suffix = suffix; }
54  void set_data_shape(int height, int width)
55  {
56  m_data_height = height;
57  m_data_width = width;
58  }
60  void set_index_length(int l) { m_index_length = l; }
62  void set_random_flips(bool b) { m_random_flips = b; }
63 
64  void load() override;
65  void setup(int num_io_threads,
66  observer_ptr<thread_pool> io_thread_pool) override;
67  int get_linearized_data_size() const override
68  {
69  return m_channels.size() * m_data_height * m_data_width;
70  }
71  int get_linearized_response_size() const override
72  {
73  return m_data_height * m_data_width;
74  }
75  const std::vector<El::Int> get_data_dims() const override
76  {
77  return {static_cast<El::Int>(m_channels.size()), m_data_height, m_data_width};
78  }
79 
80 protected:
81  bool fetch_datum(CPUMat& X, int data_id, int mb_idx) override;
82  bool fetch_response(CPUMat& Y, int data_id, int mb_idx) override;
83 
89  void load_file(int data_id, const std::string channel, Mat& mat);
91  std::string construct_filename(std::string channel, int data_id);
92 
94  void horizontal_flip(CPUMat& mat);
96  void vertical_flip(CPUMat& mat);
97 
99  std::string m_suffix = "128";
101  std::string m_target_name = "mask";
103  std::vector<std::string> m_channels = {"Density",
104  "Pressure",
105  "VectorComp_AvgVelocity_R",
106  "VolumeFractions_bubble",
107  "aspectRatio",
108  "conditionNumber",
109  "distortion",
110  "jacobian",
111  "largestAngle",
112  "oddy",
113  "scaledJacobian",
114  "shape",
115  //"shapeAndSize",
116  "shear",
117  //"shearAndSize",
118  "skew",
119  "smallestAngle",
120  "stretch",
121  "taper",
122  "volume"};
127  int m_index_length = 4;
129  std::string m_index_format_str;
131  int m_data_height = 128;
133  int m_data_width = 128;
135  int m_num_samples = 0;
137  std::vector<std::vector<DataType>> m_load_bufs;
139  bool m_random_flips = false;
145  std::vector<std::pair<bool, bool>> m_flip_choices;
146 };
147 
148 } // namespace lbann
149 
150 #endif // LBANN_DATA_READER_MESH_HPP
std::vector< std::string > m_channels
Names of each channel to load as data.
void set_suffix(const std::string suffix)
Set a suffix to append to the channel directories.
std::string m_target_name
Target channel; contains the relaxation information.
std::string m_suffix
A suffix to append to each channel directory (e.g. "128").
int get_linearized_data_size() const override
Get the linearized size (i.e. number of elements) in a sample.
const std::vector< El::Int > get_data_dims() const override
Get the dimensions of the data.
std::string m_index_format_str
Format string for the index.
std::vector< std::pair< bool, bool > > m_flip_choices
bool fetch_datum(CPUMat &X, int data_id, int mb_idx) override
void horizontal_flip(CPUMat &mat)
Flip mat horizontally (i.e. about its vertical axis).
void set_data_shape(int height, int width)
Set the shape (height and width) of the data.
void set_index_length(int l)
Set the index length for filenames.
El::Matrix< DataType, El::Device::CPU > CPUMat
Definition: base.hpp:116
typename std::add_pointer< T >::type observer_ptr
Creating an observer_ptr to complement the unique_ptr and shared_ptr.
Definition: base.hpp:54
int get_linearized_response_size() const override
Get the linearized size (i.e. number of elements) in a response.
bool fetch_response(CPUMat &Y, int data_id, int mb_idx) override
bool m_random_flips
Whether to do random horizontal/vertical flips.
int m_data_height
X dimension of the mesh data.
std::string get_type() const override
El::Matrix< DataType, El::Device::CPU > Mat
Definition: base.hpp:185
void set_random_flips(bool b)
Set whether to do random horizontal and vertical flips.
std::vector< std::vector< DataType > > m_load_bufs
Buffers for loading data into.
mesh_reader(bool shuffle=true)
void load() override
void load_file(int data_id, const std::string channel, Mat &mat)
void vertical_flip(CPUMat &mat)
Flip mat vertically (i.e. about its horizontal axis).
void setup(int num_io_threads, observer_ptr< thread_pool > io_thread_pool) override
mesh_reader * copy() const override
int m_data_width
Y dimension of the mesh data.
int m_num_samples
Number of samples.
std::string construct_filename(std::string channel, int data_id)
Return the full path to the data file for datum data_id&#39;s channel.