| 54 | using Operator<Backend>::spec_; |
| 55 | |
| 56 | bool SetupImpl(std::vector<OutputDesc>& output_desc, const Workspace &ws) override { |
| 57 | // If necessary start prefetching thread and wait for a consumable batch |
| 58 | DataReader<Backend, Target, Target, true>::SetupImpl(output_desc, ws); |
| 59 | |
| 60 | int batch_size = GetCurrBatchSize(); |
| 61 | const auto& file_0 = GetSample(0); |
| 62 | DALIDataType output_type = file_0.get_type(); |
| 63 | int ndim = file_0.get_shape().sample_dim(); |
| 64 | TensorListShape<> sh(batch_size, ndim); |
| 65 | |
| 66 | bool has_roi_args = slice_attr_.ProcessArguments(spec_, ws, batch_size, ndim); |
| 67 | rois_.clear(); |
| 68 | if (has_roi_args) |
| 69 | rois_.resize(batch_size); |
| 70 | |
| 71 | need_transpose_.clear(); |
| 72 | need_transpose_.resize(batch_size); |
| 73 | need_slice_.clear(); |
| 74 | need_slice_.resize(batch_size); |
| 75 | for (int i = 0; i < batch_size; i++) { |
| 76 | const auto& file_i = GetSample(i); |
| 77 | const auto& file_sh = file_i.get_shape(); |
| 78 | auto sample_sh = sh.tensor_shape_span(i); |
| 79 | |
| 80 | DALI_ENFORCE( |
| 81 | file_i.get_shape().sample_dim() == ndim, |
| 82 | make_string("Inconsistent data: All samples in the batch must have the same number of " |
| 83 | "dimensions. " |
| 84 | "Got \"", |
| 85 | file_0.filename, "\" with ", ndim, " dimensions and \"", file_i.filename, |
| 86 | "\" with ", file_i.get_shape().sample_dim(), " dimensions")); |
| 87 | DALI_ENFORCE( |
| 88 | file_i.get_type() == output_type, |
| 89 | make_string("Inconsistent data: All samples in the batch must have the same data type. " |
| 90 | "Got \"", |
| 91 | file_0.filename, "\" with data type ", output_type, " and \"", |
| 92 | file_i.filename, "\" with data type ", file_i.get_type())); |
| 93 | |
| 94 | bool is_transposed = file_i.fortran_order; |
| 95 | // Calculate the full transposed shape first |
| 96 | if (is_transposed) { |
| 97 | for (int d = 0; d < ndim; d++) |
| 98 | sample_sh[d] = file_sh[ndim - 1 - d]; |
| 99 | } else { |
| 100 | for (int d = 0; d < ndim; d++) |
| 101 | sample_sh[d] = file_sh[d]; |
| 102 | } |
| 103 | |
| 104 | bool need_slice = false; |
| 105 | if (has_roi_args) { |
| 106 | // Calculate the cropping window, based on the final layout (user provides axes in that |
| 107 | // layout) |
| 108 | auto full_sample_sh = sh.tensor_shape(i); // already permuted dims |
| 109 | auto tmp_roi = slice_attr_.GetCropWindowGenerator(i)(full_sample_sh, {}); |
| 110 | |
| 111 | ApplySliceBoundsPolicy( |
| 112 | out_of_bounds_policy_.shape_policy, full_sample_sh, tmp_roi.anchor, tmp_roi.shape); |
| 113 |
nothing calls this directly
no test coverage detected