From 5842a4672238126e0b668c2d976deaa5afece843 Mon Sep 17 00:00:00 2001 From: Swetha B S Date: Wed, 12 Jul 2023 05:55:20 -0400 Subject: [PATCH 01/15] First Non Buildable commit --- .../include/api/rocal_api_data_loaders.h | 24 ++++++ .../include/api/rocal_api_data_transfer.h | 19 +++++ rocAL/rocAL/include/api/rocal_api_types.h | 7 ++ .../loaders/image/cifar10_data_loader.h | 3 + .../include/loaders/image/image_loader.h | 5 ++ .../loaders/image/image_loader_sharded.h | 3 + .../loaders/image/image_read_and_decode.h | 4 + .../include/loaders/image/node_image_loader.h | 2 +- .../image/node_image_loader_single_shard.h | 2 +- rocAL/rocAL/include/loaders/loader_module.h | 4 + .../meta_data/caffe2_meta_data_reader.h | 1 + .../caffe2_meta_data_reader_detection.h | 1 + .../meta_data/caffe_meta_data_reader.h | 1 + .../caffe_meta_data_reader_detection.h | 1 + .../meta_data/cifar10_meta_data_reader.h | 1 + .../include/meta_data/coco_meta_data_reader.h | 2 + .../coco_meta_data_reader_key_points.h | 1 + .../include/meta_data/label_reader_folders.h | 1 + .../include/meta_data/meta_data_reader.h | 5 +- .../meta_data/mxnet_meta_data_reader.h | 1 + .../meta_data/text_file_meta_data_reader.h | 1 + .../include/meta_data/tf_meta_data_reader.h | 1 + .../meta_data/tf_meta_data_reader_detection.h | 1 + .../include/meta_data/video_label_reader.h | 2 +- rocAL/rocAL/include/pipeline/master_graph.h | 6 ++ .../readers/image/caffe2_lmdb_record_reader.h | 7 +- .../readers/image/caffe_lmdb_record_reader.h | 8 +- .../readers/image/cifar10_data_reader.h | 8 +- .../readers/image/coco_file_source_reader.h | 8 +- .../readers/image/file_source_reader.h | 8 +- .../readers/image/mxnet_recordio_reader.h | 8 +- rocAL/rocAL/include/readers/image/reader.h | 24 +++++- .../include/readers/image/tf_record_reader.h | 8 +- .../video/sequence_file_source_reader.h | 8 +- .../source/api/rocal_api_data_loaders.cpp | 77 +++++++++++++++++++ 35 files changed, 247 insertions(+), 16 deletions(-) diff --git a/rocAL/rocAL/include/api/rocal_api_data_loaders.h b/rocAL/rocAL/include/api/rocal_api_data_loaders.h index bf4be38dc9..a638a3c0cb 100644 --- a/rocAL/rocAL/include/api/rocal_api_data_loaders.h +++ b/rocAL/rocAL/include/api/rocal_api_data_loaders.h @@ -692,4 +692,28 @@ extern "C" RocalTensor ROCAL_API_CALL rocalJpegCaffe2LMDBRecordSourcePartialSi RocalImageSizeEvaluationPolicy decode_size_policy = ROCAL_USE_MOST_FREQUENT_SIZE, unsigned max_width = 0, unsigned max_height = 0); +/// Creates JPEG external source image reader +/// \param rocal_context Rocal context +/// \param source_path A NULL terminated char string pointing to the location on the disk +/// \param rocal_color_format The color format the images will be decoded to. +/// \param is_output Determines if the user wants the loaded images to be part of the output or not. +/// \param shuffle Determines if the user wants to shuffle the dataset or not. +/// \param loop Determines if the user wants to indefinitely loops through images or not. +/// \param decode_size_policy is the RocalImageSizeEvaluationPolicy for decoding +/// \param max_width The maximum width of the decoded images, larger or smaller will be resized to closest +/// \param max_height The maximum height of the decoded images, larger or smaller will be resized to closest +/// \param rocal_decoder_type Determines the decoder_type, tjpeg or hwdec +/// \param external_source_mode Determines the mode of the source passed from the user - file_names / uncompressed data / compressed data +/// \return Reference to the output image +extern "C" RocalTensor ROCAL_API_CALL rocalJpegExternalFileSource(RocalContext p_context, + const char* source_path, + RocalImageColor rocal_color_format, + bool is_output = false, + bool shuffle = false, + bool loop = false, + RocalImageSizeEvaluationPolicy decode_size_policy = ROCAL_USE_MOST_FREQUENT_SIZE, + unsigned max_width = 0, unsigned max_height = 0, + RocalDecoderType rocal_decoder_type = RocalDecoderType::ROCAL_DECODER_TJPEG, + RocalExtSourceMode external_source_mode = RocalExtSourceMode::ROCAL_EXTSOURCE_FNAME); + #endif //MIVISIONX_ROCAL_API_DATA_LOADERS_H diff --git a/rocAL/rocAL/include/api/rocal_api_data_transfer.h b/rocAL/rocAL/include/api/rocal_api_data_transfer.h index 0c18f287a4..b10758d2f7 100644 --- a/rocAL/rocAL/include/api/rocal_api_data_transfer.h +++ b/rocAL/rocAL/include/api/rocal_api_data_transfer.h @@ -59,4 +59,23 @@ extern "C" RocalTensorList ROCAL_API_CALL rocalGetOutputTensors(RocalContext p_ /// \param output_images The buffer that will be filled with output images with set_output = True extern "C" void ROCAL_API_CALL rocalSetOutputs(RocalContext p_context, unsigned int num_of_outputs, std::vector &output_images); +/// Creates ExternalSourceFeedInput for data transfer +/// \param rocal_context Rocal context +/// \param input_images Strings pointing to the location on the disk +/// \param labels Labels whose values is passed by the user using an external source +/// \param input_buffer Compressed or uncompressed input buffer +/// \param roi_width The roi width of the images +/// \param roi_height The roi height of the images +/// \param max_width The maximum width of the decoded images, larger or smaller will be resized to closest +/// \param max_height The maximum height of the decoded images, larger or smaller will be resized to closest +/// \param channels The number of channels for the image +/// \param mode Determines the mode of the source passed from the user - file_names / uncompressed data / compressed data +/// \param layout Determines the layout of the images - NCHW / NHWC +/// \return Reference to the output image +extern "C" RocalStatus ROCAL_API_CALL rocalExternalSourceFeedInput(RocalContext p_context, std::vector input_images_names, + std::vector labels, std::vector input_buffer, + std::vector roi_width, std::vector roi_height, + unsigned int max_width, unsigned int max_height, int channels, + RocalExtSourceMode mode, RocalTensorLayout layout, bool eos); + #endif //MIVISIONX_ROCAL_API_DATA_TRANSFER_H diff --git a/rocAL/rocAL/include/api/rocal_api_types.h b/rocAL/rocAL/include/api/rocal_api_types.h index 968e96854d..22d1c9c498 100644 --- a/rocAL/rocAL/include/api/rocal_api_types.h +++ b/rocAL/rocAL/include/api/rocal_api_types.h @@ -174,4 +174,11 @@ enum RocalResizeInterpolationType { ROCAL_TRIANGULAR_INTERPOLATION = 5 }; +enum RocalExtSourceMode +{ + ROCAL_EXTSOURCE_FNAME = 0, // file mode (list of filename given as input) + ROCAL_EXTSOURCE_RAW_COMPRESSED = 1, // Compressed Raw buffer for set of images + ROCAL_EXTSOURCE_RAW_UNCOMPRESSED = 2, // Uncompressed Raw buffer for set of images +}; + #endif //MIVISIONX_ROCAL_API_TYPES_H diff --git a/rocAL/rocAL/include/loaders/image/cifar10_data_loader.h b/rocAL/rocAL/include/loaders/image/cifar10_data_loader.h index 6c5881fbac..aaf9266cb5 100644 --- a/rocAL/rocAL/include/loaders/image/cifar10_data_loader.h +++ b/rocAL/rocAL/include/loaders/image/cifar10_data_loader.h @@ -45,6 +45,9 @@ class CIFAR10DataLoader : public LoaderModule Timing timing() override; void set_prefetch_queue_depth(size_t prefetch_queue_depth) override; void shut_down() override; + void feed_external_input(std::vector input_images_names, std::vector labels, std::vector input_buffer, + std::vector roi_width, std::vector roi_height, + unsigned int max_width, unsigned int max_height, int channels, ExternalFileMode mode, bool eos) override { return; } private: void increment_loader_idx(); diff --git a/rocAL/rocAL/include/loaders/image/image_loader.h b/rocAL/rocAL/include/loaders/image/image_loader.h index f0451cbe70..0cfb79cfc2 100644 --- a/rocAL/rocAL/include/loaders/image/image_loader.h +++ b/rocAL/rocAL/include/loaders/image/image_loader.h @@ -52,6 +52,9 @@ class ImageLoader : public LoaderModule { crop_image_info get_crop_image_info() override; void set_prefetch_queue_depth(size_t prefetch_queue_depth) override; void shut_down() override; + void feed_external_input(std::vector input_images_names, std::vector labels, std::vectorinput_buffer, + std::vector roi_width, std::vector roi_height, + unsigned int max_width, unsigned int max_height, int channels, ExternalFileMode mode, bool eos) override; private: bool is_out_of_data(); void de_init(); @@ -85,5 +88,7 @@ class ImageLoader : public LoaderModule { bool _decoder_keep_original = false; int _device_id; size_t _max_decoded_width, _max_decoded_height; + bool _external_source_reader = false; //!< Set to true if external source reader + bool _external_input_eos = false; //!< Set to true for last batch for the sequence }; diff --git a/rocAL/rocAL/include/loaders/image/image_loader_sharded.h b/rocAL/rocAL/include/loaders/image/image_loader_sharded.h index b2406195e1..f8fc95322c 100644 --- a/rocAL/rocAL/include/loaders/image/image_loader_sharded.h +++ b/rocAL/rocAL/include/loaders/image/image_loader_sharded.h @@ -45,6 +45,9 @@ class ImageLoaderSharded : public LoaderModule Timing timing() override; void set_prefetch_queue_depth(size_t prefetch_queue_depth) override; void shut_down() override; + void feed_external_input(std::vector input_images_names, std::vector labels, std::vector input_buffer, + std::vector roi_width, std::vector roi_height, + unsigned int max_width, unsigned int max_height, int channels, ExternalFileMode mode, bool eos) override; private: void increment_loader_idx(); void *_dev_resources; diff --git a/rocAL/rocAL/include/loaders/image/image_read_and_decode.h b/rocAL/rocAL/include/loaders/image/image_read_and_decode.h index 3286e4a956..97d7fe54eb 100644 --- a/rocAL/rocAL/include/loaders/image/image_read_and_decode.h +++ b/rocAL/rocAL/include/loaders/image/image_read_and_decode.h @@ -52,6 +52,9 @@ class ImageReadAndDecode void set_random_bbox_data_reader(std::shared_ptr randombboxcrop_meta_data_reader); std::vector> get_batch_random_bbox_crop_coords(); void set_batch_random_bbox_crop_coords(std::vector> batch_crop_coords); + void feed_external_input(std::vector input_images_names, std::vector labels, std::vector input_buffer, + std::vector roi_width, std::vector roi_height, + unsigned int max_width, unsigned int max_height, int channels, ExternalFileMode mode, bool eos); //! Loads a decompressed batch of images into the buffer indicated by buff /// \param buff User's buffer provided to be filled with decoded image samples @@ -97,5 +100,6 @@ class ImageReadAndDecode std::shared_ptr _randombboxcrop_meta_data_reader = nullptr; pCropCord _CropCord; RocalRandomCropDecParam *_random_crop_dec_param = nullptr; + StorageType _storage_type; }; diff --git a/rocAL/rocAL/include/loaders/image/node_image_loader.h b/rocAL/rocAL/include/loaders/image/node_image_loader.h index 45193202bd..d03361b649 100644 --- a/rocAL/rocAL/include/loaders/image/node_image_loader.h +++ b/rocAL/rocAL/include/loaders/image/node_image_loader.h @@ -41,7 +41,7 @@ class ImageLoaderNode : public Node /// The loader will repeat images if necessary to be able to have images in multiples of the load_batch_count, /// for example if there are 10 images in the dataset and load_batch_count is 3, the loader repeats 2 images as if there are 12 images available. void init(unsigned internal_shard_count, unsigned cpu_num_threads, const std::string &source_path, const std::string &json_path, const std::map feature_key_map, StorageType storage_type, DecoderType decoder_type, bool shuffle, bool loop, - size_t load_batch_count, RocalMemType mem_type, std::shared_ptr meta_data_reader, bool decoder_keep_orig = false, const char *prefix = "", unsigned sequence_length = 0, unsigned step = 0, unsigned stride = 0); + size_t load_batch_count, RocalMemType mem_type, std::shared_ptr meta_data_reader, bool decoder_keep_orig = false, ExternalFileMode external_file_mode = ExternalFileMode::FILENAME, const char *prefix = "", unsigned sequence_length = 0, unsigned step = 0, unsigned stride = 0); std::shared_ptr get_loader_module(); protected: diff --git a/rocAL/rocAL/include/loaders/image/node_image_loader_single_shard.h b/rocAL/rocAL/include/loaders/image/node_image_loader_single_shard.h index e5e7177018..6c06882211 100644 --- a/rocAL/rocAL/include/loaders/image/node_image_loader_single_shard.h +++ b/rocAL/rocAL/include/loaders/image/node_image_loader_single_shard.h @@ -38,7 +38,7 @@ class ImageLoaderSingleShardNode : public Node /// The loader will repeat images if necessary to be able to have images in multiples of the load_batch_count, /// for example if there are 10 images in the dataset and load_batch_count is 3, the loader repeats 2 images as if there are 12 images available. void init(unsigned shard_id, unsigned shard_count, unsigned cpu_num_threads, const std::string &source_path, const std::string &json_path, StorageType storage_type, DecoderType decoder_type, - bool shuffle, bool loop, size_t load_batch_count, RocalMemType mem_type, std::shared_ptr meta_data_reader, bool decoder_keep_orig = false, + bool shuffle, bool loop, size_t load_batch_count, RocalMemType mem_type, std::shared_ptr meta_data_reader, bool decoder_keep_orig = false, ExternalFileMode external_file_mode = ExternalFileMode::FILENAME, const std::map feature_key_map = std::map(), unsigned sequence_length = 0, unsigned step = 0, unsigned stride = 0); std::shared_ptr get_loader_module(); diff --git a/rocAL/rocAL/include/loaders/loader_module.h b/rocAL/rocAL/include/loaders/loader_module.h index acf3d4cbe3..d713e175c9 100644 --- a/rocAL/rocAL/include/loaders/loader_module.h +++ b/rocAL/rocAL/include/loaders/loader_module.h @@ -62,6 +62,10 @@ class LoaderModule virtual void shut_down() = 0; virtual std::vector get_sequence_start_frame_number() { return {}; }; virtual std::vector> get_sequence_frame_timestamps() { return {}; }; + // External Source reader + virtual void feed_external_input(std::vector input_images_names, std::vector labels, std::vector input_buffer, + std::vector roi_width, std::vector roi_height, unsigned int max_width, unsigned int max_height, + int channels, ExternalFileMode mode, bool eos) = 0; }; using pLoaderModule = std::shared_ptr; \ No newline at end of file diff --git a/rocAL/rocAL/include/meta_data/caffe2_meta_data_reader.h b/rocAL/rocAL/include/meta_data/caffe2_meta_data_reader.h index 380dec1aaa..894be4a6a5 100644 --- a/rocAL/rocAL/include/meta_data/caffe2_meta_data_reader.h +++ b/rocAL/rocAL/include/meta_data/caffe2_meta_data_reader.h @@ -42,6 +42,7 @@ public : void print_map_contents(); bool set_timestamp_mode() override { return false; } MetaDataBatch * get_output() override { return _output; } + void add_labels(std::vector image_name, std::vector label) override { }; std::map> &get_map_content() override { return (_map_content);} Caffe2MetaDataReader(); ~Caffe2MetaDataReader() override { delete _output; } diff --git a/rocAL/rocAL/include/meta_data/caffe2_meta_data_reader_detection.h b/rocAL/rocAL/include/meta_data/caffe2_meta_data_reader_detection.h index 30ab0d85ea..36771436ab 100644 --- a/rocAL/rocAL/include/meta_data/caffe2_meta_data_reader_detection.h +++ b/rocAL/rocAL/include/meta_data/caffe2_meta_data_reader_detection.h @@ -43,6 +43,7 @@ public : std::map> &get_map_content() override{ return _map_content;} bool set_timestamp_mode() override { return false; } MetaDataBatch * get_output() override { return _output; } + void add_labels(std::vector image_name, std::vector label) override { }; Caffe2MetaDataReaderDetection(); ~Caffe2MetaDataReaderDetection() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/caffe_meta_data_reader.h b/rocAL/rocAL/include/meta_data/caffe_meta_data_reader.h index 3dd9d03db9..1493ca1eea 100644 --- a/rocAL/rocAL/include/meta_data/caffe_meta_data_reader.h +++ b/rocAL/rocAL/include/meta_data/caffe_meta_data_reader.h @@ -42,6 +42,7 @@ public : void print_map_contents(); std::map> &get_map_content() override { return _map_content;} MetaDataBatch * get_output() override { return _output; } + void add_labels(std::vector image_name, std::vector label) override { }; CaffeMetaDataReader(); ~CaffeMetaDataReader() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/caffe_meta_data_reader_detection.h b/rocAL/rocAL/include/meta_data/caffe_meta_data_reader_detection.h index 1f5066b7e1..3eecffc25f 100644 --- a/rocAL/rocAL/include/meta_data/caffe_meta_data_reader_detection.h +++ b/rocAL/rocAL/include/meta_data/caffe_meta_data_reader_detection.h @@ -45,6 +45,7 @@ public : void print_map_contents(); std::map> &get_map_content() override{ return _map_content;} MetaDataBatch * get_output() override { return _output; } + void add_labels(std::vector image_name, std::vector label) override { }; CaffeMetaDataReaderDetection(); ~CaffeMetaDataReaderDetection() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/cifar10_meta_data_reader.h b/rocAL/rocAL/include/meta_data/cifar10_meta_data_reader.h index 8801b92353..49234eedbb 100644 --- a/rocAL/rocAL/include/meta_data/cifar10_meta_data_reader.h +++ b/rocAL/rocAL/include/meta_data/cifar10_meta_data_reader.h @@ -39,6 +39,7 @@ public : bool set_timestamp_mode() override { return false; } MetaDataBatch * get_output() override { return _output; } std::map> &get_map_content() override { return _map_content;} + void add_labels(std::vector image_name, std::vector label) override { }; Cifar10MetaDataReader(); ~Cifar10MetaDataReader() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/coco_meta_data_reader.h b/rocAL/rocAL/include/meta_data/coco_meta_data_reader.h index ccd1313755..a38eb38ef1 100644 --- a/rocAL/rocAL/include/meta_data/coco_meta_data_reader.h +++ b/rocAL/rocAL/include/meta_data/coco_meta_data_reader.h @@ -32,6 +32,7 @@ class COCOMetaDataReader: public MetaDataReader public: void init(const MetaDataConfig& cfg) override; void lookup(const std::vector& image_names) override; + void add_labels(std::vector image_name, std::vector label) override { }; void read_all(const std::string& path) override; void release(std::string image_name); void release() override; @@ -39,6 +40,7 @@ class COCOMetaDataReader: public MetaDataReader bool set_timestamp_mode() override { return false; } MetaDataBatch * get_output() override { return _output; } const std::map> & get_map_content() override { return _map_content;} + void add_labels(std::vector image_name, std::vector label) override { }; COCOMetaDataReader(); ~COCOMetaDataReader() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/coco_meta_data_reader_key_points.h b/rocAL/rocAL/include/meta_data/coco_meta_data_reader_key_points.h index 096780b901..649be2754d 100644 --- a/rocAL/rocAL/include/meta_data/coco_meta_data_reader_key_points.h +++ b/rocAL/rocAL/include/meta_data/coco_meta_data_reader_key_points.h @@ -39,6 +39,7 @@ class COCOMetaDataReaderKeyPoints: public MetaDataReader bool set_timestamp_mode() override { return false; } MetaDataBatch * get_output() override { return _output; } const std::map> & get_map_content() override { return _map_content; } + void add_labels(std::vector image_name, std::vector label) override { }; COCOMetaDataReaderKeyPoints(); ~COCOMetaDataReaderKeyPoints() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/label_reader_folders.h b/rocAL/rocAL/include/meta_data/label_reader_folders.h index 5c999edb8e..c0f1b1cf64 100644 --- a/rocAL/rocAL/include/meta_data/label_reader_folders.h +++ b/rocAL/rocAL/include/meta_data/label_reader_folders.h @@ -39,6 +39,7 @@ public : bool set_timestamp_mode() override { return false; } const std::map> & get_map_content() override { return _map_content;} MetaDataBatch * get_output() override { return _output; } + void add_labels(std::vector image_name, std::vector label) override { }; LabelReaderFolders(); ~LabelReaderFolders() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/meta_data_reader.h b/rocAL/rocAL/include/meta_data/meta_data_reader.h index dbcbfb122f..9f983d0ffe 100644 --- a/rocAL/rocAL/include/meta_data/meta_data_reader.h +++ b/rocAL/rocAL/include/meta_data/meta_data_reader.h @@ -41,7 +41,8 @@ enum class MetaDataReaderType CAFFE2_DETECTION_META_DATA_READER, TF_DETECTION_META_DATA_READER, VIDEO_LABEL_READER, - MXNET_META_DATA_READER + MXNET_META_DATA_READER, + EXTERNAL_SOURCE_LABEL_READER }; enum class MetaDataType { @@ -65,7 +66,7 @@ struct MetaDataConfig unsigned _out_img_height; public: - MetaDataConfig(const MetaDataType& type, const MetaDataReaderType& reader_type, const std::string& path, const std::map &feature_key_map=std::map(), const std::string file_prefix=std::string(), const unsigned& sequence_length = 3, const unsigned& frame_step = 3, const unsigned& frame_stride = 1) + MetaDataConfig(const MetaDataType& type, const MetaDataReaderType& reader_type, const std::string& path = std::string(), const std::map &feature_key_map=std::map(), const std::string file_prefix=std::string(), const unsigned& sequence_length = 3, const unsigned& frame_step = 3, const unsigned& frame_stride = 1) :_type(type), _reader_type(reader_type), _path(path), _feature_key_map(feature_key_map), _file_prefix(file_prefix), _sequence_length(sequence_length), _frame_step(frame_step), _frame_stride(frame_stride){} MetaDataConfig() = delete; MetaDataType type() const { return _type; } diff --git a/rocAL/rocAL/include/meta_data/mxnet_meta_data_reader.h b/rocAL/rocAL/include/meta_data/mxnet_meta_data_reader.h index 2625241f2c..de4e293cff 100644 --- a/rocAL/rocAL/include/meta_data/mxnet_meta_data_reader.h +++ b/rocAL/rocAL/include/meta_data/mxnet_meta_data_reader.h @@ -45,6 +45,7 @@ public : bool set_timestamp_mode() override { return false; } const std::map> & get_map_content() override { return _map_content;} MetaDataBatch * get_output() override { return _output; } + void add_labels(std::vector image_name, std::vector label) override { }; MXNetMetaDataReader(); ~MXNetMetaDataReader() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/text_file_meta_data_reader.h b/rocAL/rocAL/include/meta_data/text_file_meta_data_reader.h index 60212a225e..2b06dd4963 100644 --- a/rocAL/rocAL/include/meta_data/text_file_meta_data_reader.h +++ b/rocAL/rocAL/include/meta_data/text_file_meta_data_reader.h @@ -36,6 +36,7 @@ class TextFileMetaDataReader: public MetaDataReader bool set_timestamp_mode() override { return false; } MetaDataBatch * get_output() override { return _output; } const std::map> & get_map_content() override{ return _map_content;} + void add_labels(std::vector image_name, std::vector label) override { }; TextFileMetaDataReader(); ~TextFileMetaDataReader() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/tf_meta_data_reader.h b/rocAL/rocAL/include/meta_data/tf_meta_data_reader.h index b95453b294..22af7b1991 100644 --- a/rocAL/rocAL/include/meta_data/tf_meta_data_reader.h +++ b/rocAL/rocAL/include/meta_data/tf_meta_data_reader.h @@ -41,6 +41,7 @@ public : bool set_timestamp_mode() override { return false; } MetaDataBatch * get_output() override { return _output; } const std::map> & get_map_content() override{ return _map_content;} + void add_labels(std::vector image_name, std::vector label) override { }; TFMetaDataReader(); ~TFMetaDataReader() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/tf_meta_data_reader_detection.h b/rocAL/rocAL/include/meta_data/tf_meta_data_reader_detection.h index d023fd9eba..d995c91628 100644 --- a/rocAL/rocAL/include/meta_data/tf_meta_data_reader_detection.h +++ b/rocAL/rocAL/include/meta_data/tf_meta_data_reader_detection.h @@ -43,6 +43,7 @@ public : bool set_timestamp_mode() override { return false; } MetaDataBatch * get_output() override { return _output; } const std::map> & get_map_content() override{ return _map_content;} + void add_labels(std::vector image_name, std::vector label) override { }; TFMetaDataReaderDetection(); ~TFMetaDataReaderDetection() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/video_label_reader.h b/rocAL/rocAL/include/meta_data/video_label_reader.h index 11baca5d5f..a2a3bb698f 100644 --- a/rocAL/rocAL/include/meta_data/video_label_reader.h +++ b/rocAL/rocAL/include/meta_data/video_label_reader.h @@ -40,8 +40,8 @@ class VideoLabelReader : public MetaDataReader bool set_timestamp_mode() override { _file_list_frame_num = false; return _file_list_frame_num;} void print_map_contents(); const std::map> & get_map_content() override{ return _map_content;} - MetaDataBatch *get_output() override { return _output; } + void add_labels(std::vector image_name, std::vector label) override { }; VideoLabelReader(); ~VideoLabelReader() override { delete _output; } private: diff --git a/rocAL/rocAL/include/pipeline/master_graph.h b/rocAL/rocAL/include/pipeline/master_graph.h index d1d0773781..e3c3226164 100644 --- a/rocAL/rocAL/include/pipeline/master_graph.h +++ b/rocAL/rocAL/include/pipeline/master_graph.h @@ -105,6 +105,10 @@ class MasterGraph bool is_sequence_reader_output() {return _is_sequence_reader_output; } void set_sequence_reader_output() { _is_sequence_reader_output = true; } void set_sequence_batch_size(size_t sequence_length) { _sequence_batch_size = _user_batch_size * sequence_length; } + void feed_external_input(std::vector input_images_names, std::vector labels, std::vectorinput_buffer, + std::vector roi_width, std::vector roi_height, unsigned int max_width, + unsigned int max_height, int channels, ExternalFileMode mode, RocalTensorFormat layout, bool eos); + void set_external_source_reader_flag() { _external_source_reader = true; } std::vector get_bbox_encoded_buffers(size_t num_encoded_boxes); size_t bounding_box_batch_count(int* buf, pMetaDataBatch meta_data_batch); #if ENABLE_OPENCL @@ -182,6 +186,8 @@ class MasterGraph float _scale; // Rescales the box and anchor values before the offset is calculated (for example, to return to the absolute values). bool _offset; // Returns normalized offsets ((encoded_bboxes*scale - anchors*scale) - mean) / stds in EncodedBBoxes that use std and the mean and scale arguments if offset="True" std::vector _means, _stds; //_means: [x y w h] mean values for normalization _stds: [x y w h] standard deviations for offset normalization. + bool _external_source_eos = false; //If last batch, _external_source_eos will true + bool _external_source_reader = false; //Set to true if external source reader on float _high_threshold = 0.5; float _low_threshold = 0.4; bool _allow_low_quality_matches = true; diff --git a/rocAL/rocAL/include/readers/image/caffe2_lmdb_record_reader.h b/rocAL/rocAL/include/readers/image/caffe2_lmdb_record_reader.h index 9277f24fd3..48b9fa4d1b 100644 --- a/rocAL/rocAL/include/readers/image/caffe2_lmdb_record_reader.h +++ b/rocAL/rocAL/include/readers/image/caffe2_lmdb_record_reader.h @@ -58,7 +58,7 @@ class Caffe2LMDBRecordReader : public Reader void reset() override; //! Returns the id of the latest file opened - std::string id() override { return _last_id;}; + std::string id() override { return _last_id;} unsigned count_items() override; @@ -67,6 +67,11 @@ class Caffe2LMDBRecordReader : public Reader int close() override; Caffe2LMDBRecordReader(); + //! return feed_data: not implemented + void feed_file_names(const std::vector& file_names, size_t num_images, bool eos = false) override { return; } + + //! return feed_data: not implemented + void feed_data(const std::vector& images, const std::vector& image_size, ExternalFileMode mode, bool eos = false, int width = 0, int height = 0, int channels = 0) override { return; } private: //! opens the folder containnig the images diff --git a/rocAL/rocAL/include/readers/image/caffe_lmdb_record_reader.h b/rocAL/rocAL/include/readers/image/caffe_lmdb_record_reader.h index 1aa83564af..2e6cc54e6d 100644 --- a/rocAL/rocAL/include/readers/image/caffe_lmdb_record_reader.h +++ b/rocAL/rocAL/include/readers/image/caffe_lmdb_record_reader.h @@ -57,7 +57,7 @@ class CaffeLMDBRecordReader : public Reader{ void reset() override; //! Returns the id of the latest file opened - std::string id() override { return _last_id;}; + std::string id() override { return _last_id;} unsigned count_items() override; @@ -67,6 +67,12 @@ class CaffeLMDBRecordReader : public Reader{ CaffeLMDBRecordReader(); + //! return feed_data: not implemented + void feed_file_names(const std::vector& file_names, size_t num_images, bool eos = false) override { return; } + + //! return feed_raw_data: not implemented + void feed_data(const std::vector& images, const std::vector& image_size, ExternalFileMode mode, bool eos = false, int width = 0, int height = 0, int channels = 0) override { return; } + private: //! opens the folder containnig the images Reader::Status folder_reading(); diff --git a/rocAL/rocAL/include/readers/image/cifar10_data_reader.h b/rocAL/rocAL/include/readers/image/cifar10_data_reader.h index aca98bdc40..bb54ca0883 100644 --- a/rocAL/rocAL/include/readers/image/cifar10_data_reader.h +++ b/rocAL/rocAL/include/readers/image/cifar10_data_reader.h @@ -51,7 +51,7 @@ class CIFAR10DataReader : public Reader { void reset() override; //! Returns the name of the latest data_id opened - std::string id() override { return _last_id;}; + std::string id() override { return _last_id;} unsigned count_items() override; @@ -61,6 +61,12 @@ class CIFAR10DataReader : public Reader { CIFAR10DataReader(); + //! return feed_data: not implemented + void feed_file_names(const std::vector& file_names, size_t num_images, bool eos = false) override { return; } + + //! return feed_data: not implemented + void feed_data(const std::vector& images, const std::vector& image_size, ExternalFileMode mode, bool eos = false, int width = 0, int height = 0, int channels = 0) override { return; } + unsigned get_file_index() { return _last_file_idx;} private: diff --git a/rocAL/rocAL/include/readers/image/coco_file_source_reader.h b/rocAL/rocAL/include/readers/image/coco_file_source_reader.h index 3b1fe842aa..12fdf9e5c3 100644 --- a/rocAL/rocAL/include/readers/image/coco_file_source_reader.h +++ b/rocAL/rocAL/include/readers/image/coco_file_source_reader.h @@ -56,7 +56,7 @@ class COCOFileSourceReader : public Reader { void reset() override; //! Returns the name of the latest file opened - std::string id() override { return _last_id;}; + std::string id() override { return _last_id;} unsigned count_items() override; @@ -66,6 +66,12 @@ class COCOFileSourceReader : public Reader { COCOFileSourceReader(); + //! return feed_file_names: not implemented + void feed_file_names(const std::vector& file_names, size_t num_images, bool eos = false) override { return; } + + //! return feed_data: not implemented + void feed_data(const std::vector& images, const std::vector& image_size, ExternalFileMode mode, bool eos = false, int width = 0, int height = 0, int channels = 0) override { return; } + private: std::shared_ptr _meta_data_reader = nullptr; //! opens the folder containnig the images diff --git a/rocAL/rocAL/include/readers/image/file_source_reader.h b/rocAL/rocAL/include/readers/image/file_source_reader.h index d7e1d37c87..eb5ceddb6a 100644 --- a/rocAL/rocAL/include/readers/image/file_source_reader.h +++ b/rocAL/rocAL/include/readers/image/file_source_reader.h @@ -53,7 +53,7 @@ class FileSourceReader : public Reader { void reset() override; //! Returns the name of the latest file opened - std::string id() override { return _last_id;}; + std::string id() override { return _last_id;} unsigned count_items() override; @@ -63,6 +63,12 @@ class FileSourceReader : public Reader { FileSourceReader(); + //! return feed_data: not implemented + void feed_file_names(const std::vector& file_names, size_t num_images, bool eos = false) override { return; } + + //! return feed_data: not implemented + void feed_data(const std::vector& images, const std::vector& image_size, ExternalFileMode mode, bool eos = false, int width = 0, int height = 0, int channels = 0) override { return; } + private: //! opens the folder containnig the images Reader::Status open_folder(); diff --git a/rocAL/rocAL/include/readers/image/mxnet_recordio_reader.h b/rocAL/rocAL/include/readers/image/mxnet_recordio_reader.h index 730c01898d..5c8a98d1fd 100644 --- a/rocAL/rocAL/include/readers/image/mxnet_recordio_reader.h +++ b/rocAL/rocAL/include/readers/image/mxnet_recordio_reader.h @@ -54,7 +54,7 @@ class MXNetRecordIOReader : public Reader{ void reset() override; //! Returns the id of the latest file opened - std::string id() override { return _last_id;}; + std::string id() override { return _last_id;} unsigned count_items() override; @@ -64,6 +64,12 @@ class MXNetRecordIOReader : public Reader{ MXNetRecordIOReader(); + //! return feed_data: not implemented + void feed_file_names(const std::vector& file_names, size_t num_images, bool eos = false) override { return; } + + //! return feed_data: not implemented + void feed_data(const std::vector& images, const std::vector& image_size, ExternalFileMode mode, bool eos = false, int width = 0, int height = 0, int channels = 0) override { return; } + private: //! opens the folder containnig the images Reader::Status record_reading(); diff --git a/rocAL/rocAL/include/readers/image/reader.h b/rocAL/rocAL/include/readers/image/reader.h index 9d53926124..1b7c9adad1 100644 --- a/rocAL/rocAL/include/readers/image/reader.h +++ b/rocAL/rocAL/include/readers/image/reader.h @@ -46,13 +46,21 @@ enum class StorageType SEQUENCE_FILE_SYSTEM = 6, MXNET_RECORDIO = 7, VIDEO_FILE_SYSTEM = 8, + EXTERNAL_FILE_SOURCE = 9, // to support reading from external source +}; + +enum class ExternalFileMode +{ + FILENAME = 0, + RAWDATA_COMPRESSED = 1, + RAWDATA_UNCOMPRESSED = 2, }; struct ReaderConfig { explicit ReaderConfig(StorageType type, std::string path = "", std::string json_path = "", const std::map feature_key_map = std::map(), - bool shuffle = false, bool loop = false) : _type(type), _path(path), _json_path(json_path), _feature_key_map(feature_key_map), _shuffle(shuffle), _loop(loop) {} + bool shuffle = false, bool loop = false, ExternalFileMode mode = ExternalFileMode::FILENAME) : _type(type), _path(path), _json_path(json_path), _feature_key_map(feature_key_map), _shuffle(shuffle), _loop(loop, _file_mode(mode)) {} virtual StorageType type() { return _type; }; void set_path(const std::string &path) { _path = path; } void set_shard_id(size_t shard_id) { _shard_id = shard_id; } @@ -71,6 +79,7 @@ struct ReaderConfig void set_sequence_length(unsigned sequence_length) { _sequence_length = sequence_length; } void set_frame_step(unsigned step) { _sequence_frame_step = step; } void set_frame_stride(unsigned stride) { _sequence_frame_stride = stride; } + void set_external_filemode(ExternalFileMode mode) { _file_mode = mode; } size_t get_shard_count() { return _shard_count; } size_t get_shard_id() { return _shard_id; } size_t get_cpu_num_threads() { return _cpu_num_threads; } @@ -90,8 +99,9 @@ struct ReaderConfig void set_file_prefix(const std::string &prefix) { _file_prefix = prefix; } std::string file_prefix() { return _file_prefix; } std::shared_ptr meta_data_reader() { return _meta_data_reader; } + virtual ExternalFileMode mode() { return _file_mode; } private: - StorageType _type = StorageType::FILE_SYSTEM; + StorageType _storage_type = StorageType::FILE_SYSTEM; std::string _path = ""; std::string _json_path = ""; std::map _feature_key_map; @@ -106,6 +116,7 @@ struct ReaderConfig bool _loop = false; std::string _file_prefix = ""; //!< to read only files with prefix. supported only for cifar10_data_reader and tf_record_reader std::shared_ptr _meta_data_reader = nullptr; + ExternalFileMode _file_mode; #ifdef ROCAL_VIDEO VideoProperties _video_prop; // size_t _total_frames_count; @@ -122,6 +133,7 @@ struct ImageRecordIOHeader { * image_id[0] is used to store image id */ }; + class Reader { public: enum class Status @@ -162,6 +174,12 @@ class Reader { virtual std::string id() = 0; //! Returns the number of items remained in this resource virtual unsigned count_items() = 0; - + + //! return feed_file_names: needed if an external_source is feeding into the reader + virtual void feed_file_names(const std::vector& file_names, size_t num_images, bool eos = false) = 0; + + //! return feed_data: use this for feeding raw data into the reader (mode specified compressed jpegs or raw) + virtual void feed_data(const std::vector& images, const std::vector& image_size, ExternalFileMode mode, bool eos = false, int width = 0, int height = 0, int channels = 0) = 0; + virtual ~Reader() = default; }; diff --git a/rocAL/rocAL/include/readers/image/tf_record_reader.h b/rocAL/rocAL/include/readers/image/tf_record_reader.h index 70b9506256..ca50bfadd0 100644 --- a/rocAL/rocAL/include/readers/image/tf_record_reader.h +++ b/rocAL/rocAL/include/readers/image/tf_record_reader.h @@ -58,7 +58,7 @@ class TFRecordReader : public Reader void reset() override; //! Returns the id of the latest file opened - std::string id() override { return _last_id;}; + std::string id() override { return _last_id;} unsigned count_items() override; @@ -67,6 +67,12 @@ class TFRecordReader : public Reader int close() override; TFRecordReader(); + + //! return feed_data: not implemented + void feed_file_names(const std::vector& file_names, size_t num_images, bool eos = false) override { return; } + + //! return feed_data: not implemented + void feed_data(const std::vector& images, const std::vector& image_size, ExternalFileMode mode, bool eos = false, int width = 0, int height = 0, int channels = 0) override { return; } private: //! opens the folder containnig the images Reader::Status tf_record_reader(); diff --git a/rocAL/rocAL/include/readers/video/sequence_file_source_reader.h b/rocAL/rocAL/include/readers/video/sequence_file_source_reader.h index f2503b920e..99fa7daeeb 100644 --- a/rocAL/rocAL/include/readers/video/sequence_file_source_reader.h +++ b/rocAL/rocAL/include/readers/video/sequence_file_source_reader.h @@ -53,7 +53,7 @@ class SequenceFileSourceReader : public Reader { void reset() override; //! Returns the name of the latest file opened - std::string id() override { return _last_id;}; + std::string id() override { return _last_id;} unsigned count_items() override; @@ -63,6 +63,12 @@ class SequenceFileSourceReader : public Reader { SequenceFileSourceReader(); + //! return feed_data: not implemented + void feed_file_names(const std::vector& file_names, size_t num_images, bool eos = false) override { return; } + + //! return feed_data: not implemented + void feed_data(const std::vector& images, const std::vector& image_size, ExternalFileMode mode, bool eos = false, int width = 0, int height = 0, int channels = 0) override { return; } + private: //! opens the folder containnig the images Reader::Status open_folder(); diff --git a/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp b/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp index 22dbc5c559..83d07c5a10 100644 --- a/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp +++ b/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp @@ -2244,6 +2244,83 @@ rocalVideoFileResizeSingleShard( return resize_output; } +RocalTensor ROCAL_API_CALL +rocalJpegExternalFileSource( + RocalContext p_context, + const char* source_path, + RocalImageColor rocal_color_format, + bool is_output, + bool shuffle, + bool loop, + RocalImageSizeEvaluationPolicy decode_size_policy, + unsigned max_width, + unsigned max_height, + RocalDecoderType dec_type, + RocalExtSourceMode external_source_mode) +{ + rocalTensor* output = nullptr; + auto context = static_cast(p_context); + try + { + uint internal_shard_count = 1; + bool decoder_keep_original = (decode_size_policy == ROCAL_USE_USER_GIVEN_SIZE_RESTRICTED) || (decode_size_policy == ROCAL_USE_MAX_SIZE_RESTRICTED); + DecoderType decType = DecoderType::TURBO_JPEG; // default + if (dec_type == ROCAL_DECODER_OPENCV) decType = DecoderType::OPENCV_DEC; + if ((decode_size_policy == ROCAL_USE_MAX_SIZE) || (decode_size_policy == ROCAL_USE_MAX_SIZE_RESTRICTED)) + THROW("use_max_size is not supported in external source reader"); + + // user need to specify this + if(max_width == 0 || max_height == 0) { THROW("Invalid input max width and height"); } + else { LOG("User input size " + TOSTR(max_width) + " x " + TOSTR(max_height)) } + + auto [width, height] = std::make_tuple(max_width, max_height); + auto [color_format, num_of_planes] = convert_color_format(rocal_color_format); + + INFO("Internal buffer size width = "+ TOSTR(width)+ " height = "+ TOSTR(height) + " depth = "+ TOSTR(num_of_planes)) + // Change the way ImageInfo is created for TensorInfo + std::vector dims = {context->user_batch_size(), height, width, num_of_planes}; + auto info = rocalTensorInfo(std::move(dims), + context->master_graph->mem_type(), + RocalTensorDataType::UINT8); + info.set_color_format(color_format); + info.set_tensor_layout(RocalTensorlayout::NHWC); + info.set_max_shape(); + // auto info = ImageInfo(width, height, + // context->user_batch_size(), + // num_of_planes, + // context->master_graph->mem_type(), + // color_format ); + output = context->master_graph->create_loader_output_tensor(info); + context->master_graph->set_external_source_reader_flag(); + context->master_graph->add_node({}, {output})->init(internal_shard_count, + source_path, "", + std::map(), + StorageType::EXTERNAL_FILE_SOURCE, + decType, + shuffle, + loop, + context->user_batch_size(), + context->master_graph->mem_type(), + context->master_graph->meta_data_reader(), + decoder_keep_original, + ExternalFileMode(external_source_mode)); + context->master_graph->set_loop(loop); + + if(is_output) + { + auto actual_output = context->master_graph->create_tensor(info, is_output); + context->master_graph->add_node({output}, {actual_output}); + } + + } + catch(const std::exception& e) + { + context->capture_error(e.what()); + std::cerr << e.what() << '\n'; + } + return output; +} + RocalStatus ROCAL_API_CALL rocalResetLoaders(RocalContext p_context) { From dca94a756b14b3763babaed325fe66a63fcb4676 Mon Sep 17 00:00:00 2001 From: Swetha B S Date: Wed, 12 Jul 2023 23:31:19 -0400 Subject: [PATCH 02/15] Second Non Buildable commit --- .../source/api/rocal_api_data_loaders.cpp | 26 ++++--- .../source/api/rocal_api_data_transfer.cpp | 30 ++++++++ .../source/loaders/image/image_loader.cpp | 18 +++++ .../loaders/image/image_loader_sharded.cpp | 6 ++ .../loaders/image/image_read_and_decode.cpp | 75 ++++++++++++++++++- .../loaders/image/node_image_loader.cpp | 3 +- .../image/node_image_loader_single_shard.cpp | 3 +- .../meta_data/meta_data_reader_factory.cpp | 10 +++ rocAL/rocAL/source/pipeline/master_graph.cpp | 24 ++++++ .../source/readers/image/reader_factory.cpp | 10 ++- rocAL/rocAL_pybind/amd/rocal/fn.py | 14 +++- rocAL/rocAL_pybind/amd/rocal/pipeline.py | 3 + .../rocAL_pybind/amd/rocal/plugin/generic.py | 31 +++++++- .../rocAL_pybind/amd/rocal/plugin/pytorch.py | 32 +++++++- rocAL/rocAL_pybind/amd/rocal/types.py | 9 +++ rocAL/rocAL_pybind/rocal_pybind.cpp | 9 +++ 16 files changed, 284 insertions(+), 19 deletions(-) diff --git a/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp b/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp index 83d07c5a10..fdd1e4dabb 100644 --- a/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp +++ b/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp @@ -258,7 +258,8 @@ rocalJpegFileSource( context->user_batch_size(), context->master_graph->mem_type(), context->master_graph->meta_data_reader(), - decoder_keep_original); + decoder_keep_original, + ExternalFileMode::FILENAME); context->master_graph->set_loop(loop); if(is_output) @@ -335,7 +336,7 @@ rocalSequenceReader( auto cpu_num_threads = context->master_graph->calculate_cpu_num_threads(1); context->master_graph->add_node({}, {output})->init(internal_shard_count, cpu_num_threads, - source_path, "", + source_path, ExternalFileMode::FILENAME, "", std::map(), StorageType::SEQUENCE_FILE_SYSTEM, DecoderType::TURBO_JPEG, @@ -528,7 +529,8 @@ rocalJpegCaffe2LMDBRecordSource( context->user_batch_size(), context->master_graph->mem_type(), context->master_graph->meta_data_reader(), - decoder_keep_original); + decoder_keep_original, + ExternalFileMode::FILENAME); context->master_graph->set_loop(loop); if(is_output) @@ -623,7 +625,8 @@ rocalJpegCaffe2LMDBRecordSourceSingleShard( context->user_batch_size(), context->master_graph->mem_type(), context->master_graph->meta_data_reader(), - decoder_keep_original); + decoder_keep_original, + ExternalFileMode::FILENAME); context->master_graph->set_loop(loop); if(is_output) @@ -715,7 +718,8 @@ rocalJpegCaffeLMDBRecordSource( context->user_batch_size(), context->master_graph->mem_type(), context->master_graph->meta_data_reader(), - decoder_keep_original); + decoder_keep_original, + ExternalFileMode::FILENAME); context->master_graph->set_loop(loop); @@ -811,7 +815,8 @@ rocalJpegCaffeLMDBRecordSourceSingleShard( context->user_batch_size(), context->master_graph->mem_type(), context->master_graph->meta_data_reader(), - decoder_keep_original); + decoder_keep_original, + ExternalFileMode::FILENAME); context->master_graph->set_loop(loop); if(is_output) @@ -908,7 +913,8 @@ rocalMXNetRecordSource( context->user_batch_size(), context->master_graph->mem_type(), context->master_graph->meta_data_reader(), - decoder_keep_original); + decoder_keep_original, + ExternalFileMode::FILENAME); context->master_graph->set_loop(loop); @@ -1004,7 +1010,8 @@ rocalJpegCOCOFileSource( context->user_batch_size(), context->master_graph->mem_type(), context->master_graph->meta_data_reader(), - decoder_keep_original); + decoder_keep_original, + ExternalFileMode::FILENAME); context->master_graph->set_loop(loop); @@ -1103,7 +1110,8 @@ rocalJpegCOCOFileSourceSingleShard( context->user_batch_size(), context->master_graph->mem_type(), context->master_graph->meta_data_reader(), - decoder_keep_original); + decoder_keep_original, + ExternalFileMode::FILENAME); context->master_graph->set_loop(loop); if(is_output) diff --git a/rocAL/rocAL/source/api/rocal_api_data_transfer.cpp b/rocAL/rocAL/source/api/rocal_api_data_transfer.cpp index f3c4d2f869..41aa8bf25e 100644 --- a/rocAL/rocAL/source/api/rocal_api_data_transfer.cpp +++ b/rocAL/rocAL/source/api/rocal_api_data_transfer.cpp @@ -67,6 +67,36 @@ rocalToTensor(RocalContext p_context, void *out_ptr, RocalTensorlayout tensor_fo return ROCAL_OK; } +RocalStatus ROCAL_API_CALL +rocalExternalSourceFeedInput( + RocalContext p_context, + std::vector input_images_names, + std::vector labels, + std::vectorinput_buffer, + std::vector roi_width, + std::vector roi_height, + unsigned int max_width, + unsigned int max_height, + int channels, + RocalExtSourceMode mode, + RocalTensorLayout layout,p + bool eos) { + auto context = static_cast(p_context); + try { + ExternalFileMode external_file_mode = (ExternalFileMode) mode; + RocalTensorFormat format = (RocalTensorFormat) layout; + context->master_graph->feed_external_input(input_images_names, labels, input_buffer, + roi_width, roi_height, max_width, max_height, channels, + external_file_mode, format, eos); + } + catch(const std::exception& e) { + context->capture_error(e.what()); + ERR(e.what()) + return ROCAL_RUNTIME_ERROR; + } + return ROCAL_OK; +} + void ROCAL_API_CALL rocalSetOutputs(RocalContext p_context, unsigned int num_of_outputs, std::vector &output_images) { diff --git a/rocAL/rocAL/source/loaders/image/image_loader.cpp b/rocAL/rocAL/source/loaders/image/image_loader.cpp index 50522e6c24..90e31b058c 100644 --- a/rocAL/rocAL/source/loaders/image/image_loader.cpp +++ b/rocAL/rocAL/source/loaders/image/image_loader.cpp @@ -70,6 +70,16 @@ void ImageLoader::set_gpu_device_id(int device_id) size_t ImageLoader::remaining_count() { + if(_external_source_reader) + { + if(_image_loader->count() != 0) + return _batch_size; + else + { + if(_external_input_eos) + return 0; + } + } return _remaining_image_count; } @@ -179,6 +189,7 @@ void ImageLoader::start_loading() THROW("start_loading() should be called after initialize() function is called") _remaining_image_count = _image_loader->count(); + INFO("Remaining Image count in ImageLoader::start_loading " + TOSTR(_remaining_image_count)); _internal_thread_running = true; _load_thread = std::thread(&ImageLoader::load_routine, this); } @@ -347,3 +358,10 @@ crop_image_info ImageLoader::get_crop_image_info() { return _output_cropped_img_info; } + +void ImageLoader::feed_external_input(std::vector input_images_names, std::vector labels, std::vectorinput_buffer, std::vector roi_width, std::vector roi_height, unsigned int max_width, unsigned int max_height, int channels, ExternalFileMode mode, bool eos) +{ + _external_source_reader = true; + _external_input_eos = eos; + _image_loader->feed_external_input(input_images_names, labels, input_buffer, roi_width, roi_height, max_width, max_height, channels, mode, eos); +} diff --git a/rocAL/rocAL/source/loaders/image/image_loader_sharded.cpp b/rocAL/rocAL/source/loaders/image/image_loader_sharded.cpp index c2e6837a75..00c8ef0169 100644 --- a/rocAL/rocAL/source/loaders/image/image_loader_sharded.cpp +++ b/rocAL/rocAL/source/loaders/image/image_loader_sharded.cpp @@ -186,3 +186,9 @@ Timing ImageLoaderSharded::timing() t.image_process_time = swap_handle_time; return t; } + +void ImageLoaderSharded::feed_external_input(std::vector input_images_names, std::vector labels, std::vector input_buffer, std::vector roi_width, std::vector roi_height, unsigned int max_width, unsigned int max_height, int channels, ExternalFileMode mode, bool eos) +{ + for(auto& loader: _loaders) + loader->feed_external_input(input_images_names, labels, input_buffer, roi_width, roi_height, max_width, max_height, channels, mode, eos); +} diff --git a/rocAL/rocAL/source/loaders/image/image_read_and_decode.cpp b/rocAL/rocAL/source/loaders/image/image_read_and_decode.cpp index 3772a0574a..45309f0075 100644 --- a/rocAL/rocAL/source/loaders/image/image_read_and_decode.cpp +++ b/rocAL/rocAL/source/loaders/image/image_read_and_decode.cpp @@ -23,8 +23,10 @@ THE SOFTWARE. #include #include +#include #include "decoder_factory.h" #include "image_read_and_decode.h" +#include "external_source_reader.h" std::tuple interpret_color_format(RocalColorFormat color_format ) @@ -98,6 +100,26 @@ ImageReadAndDecode::create(ReaderConfig reader_config, DecoderConfig decoder_con } _num_threads = reader_config.get_cpu_num_threads(); _reader = create_reader(reader_config); + _storage_type = reader_config.storage_type(); +} + +void ImageReadAndDecode::feed_external_input(std::vector input_images_names, std::vector labels, std::vector input_buffer, + std::vector roi_width, std::vector roi_height, + unsigned int max_width, unsigned int max_height, int channels, ExternalFileMode mode, bool eos) +{ + std::vector image_size; + image_size.reserve(roi_height.size()); + for(unsigned int i = 0; i < roi_height.size(); i++) { + if (mode == ExternalFileMode::RAWDATA_UNCOMPRESSED) + image_size[i] = (roi_width[i] * roi_height[i] * channels); + else if (mode == ExternalFileMode::RAWDATA_COMPRESSED) + image_size[i] = roi_height[i]; + } + if(mode == ExternalFileMode::FILENAME) + _reader->feed_file_names(input_images_names, input_images_names.size(), eos); + else if(mode == ExternalFileMode::RAWDATA_COMPRESSED || mode == ExternalFileMode::RAWDATA_UNCOMPRESSED) + _reader->feed_data(input_buffer, image_size, mode, eos, max_width, max_height, channels); + } void @@ -156,6 +178,8 @@ ImageReadAndDecode::load(unsigned char* buff, const unsigned output_planes = std::get<1>(ret); const bool keep_original = decoder_keep_original; const size_t image_size = max_decoded_width * max_decoded_height * output_planes * sizeof(unsigned char); + bool is_external_source = (_storage_type == StorageType::EXTERNAL_FILE_SOURCE); + bool skip_decode = false; // Decode with the height and size equal to a single image // File read is done serially since I/O parallelization does not work very well. @@ -184,9 +208,54 @@ ImageReadAndDecode::load(unsigned char* buff, actual_height[file_counter] = max_decoded_height; file_counter++; } + skip_decode = true; //_file_load_time.end();// Debug timing - //return LoaderModuleStatus::OK; - } else { + } else if (is_external_source) { + auto ext_reader = std::static_pointer_cast(_reader); + if (ext_reader->mode() == ExternalFileMode::RAWDATA_UNCOMPRESSED) { + while ((file_counter != _batch_size) && _reader->count_items() > 0) { + int width, height, channels; + auto read_ptr = buff + image_size * file_counter; + size_t fsize = _reader->open(); + if (fsize == 0) { + WRN("Opened file " + _reader->id() + " of size 0"); + continue; + } + + _actual_read_size[file_counter] = _reader->read_data(read_ptr, fsize); + if(_actual_read_size[file_counter] < fsize) + LOG("Reader read less than requested bytes of size: " + _actual_read_size[file_counter]); + + _image_names[file_counter] = _reader->id(); + ext_reader->get_dims(file_counter, width, height, channels); + names[file_counter] = _image_names[file_counter]; + roi_width[file_counter] = width; + roi_height[file_counter] = height; + actual_width[file_counter] = width; + actual_height[file_counter] = height; + _reader->close(); + file_counter++; + } + skip_decode = true; + } + else { + while ((file_counter != _batch_size) && _reader->count_items() > 0) { + _reader->count_items(); + size_t fsize = _reader->open(); + if (fsize == 0) { + WRN("Opened file " + _reader->id() + " of size 0"); + continue; + } + _compressed_buff[file_counter].reserve(fsize); + _actual_read_size[file_counter] = _reader->read_data(_compressed_buff[file_counter].data(), fsize); + _image_names[file_counter] = _reader->id(); + _reader->close(); + _compressed_image_size[file_counter] = fsize; + file_counter++; + } + } + } + else { while ((file_counter != _batch_size) && _reader->count_items() > 0) { size_t fsize = _reader->open(); if (fsize == 0) { @@ -212,7 +281,7 @@ ImageReadAndDecode::load(unsigned char* buff, _file_load_time.end();// Debug timing _decode_time.start();// Debug timing - if (_decoder_config._type != DecoderType::SKIP_DECODE) { + if (!skip_decode) { for (size_t i = 0; i < _batch_size; i++) _decompressed_buff_ptrs[i] = buff + image_size * i; diff --git a/rocAL/rocAL/source/loaders/image/node_image_loader.cpp b/rocAL/rocAL/source/loaders/image/node_image_loader.cpp index 108f7248a8..dbf63caf4b 100644 --- a/rocAL/rocAL/source/loaders/image/node_image_loader.cpp +++ b/rocAL/rocAL/source/loaders/image/node_image_loader.cpp @@ -31,7 +31,7 @@ ImageLoaderNode::ImageLoaderNode(rocalTensor *output, void *device_resources): void ImageLoaderNode::init(unsigned internal_shard_count, unsigned cpu_num_threads, const std::string &source_path, const std::string &json_path, const std::map feature_key_map, StorageType storage_type, DecoderType decoder_type, bool shuffle, bool loop, - size_t load_batch_count, RocalMemType mem_type, std::shared_ptr meta_data_reader, bool decoder_keep_orig, const char* file_prefix, unsigned sequence_length, unsigned step, unsigned stride) + size_t load_batch_count, RocalMemType mem_type, std::shared_ptr meta_data_reader, bool decoder_keep_orig, ExternalFileMode external_file_mode, const char* file_prefix, unsigned sequence_length, unsigned step, unsigned stride) { if(!_loader_module) THROW("ERROR: loader module is not set for ImageLoaderNode, cannot initialize") @@ -49,6 +49,7 @@ void ImageLoaderNode::init(unsigned internal_shard_count, unsigned cpu_num_threa reader_cfg.set_sequence_length(sequence_length); reader_cfg.set_frame_step(step); reader_cfg.set_frame_stride(stride); + reader_cfg.set_external_filemode(external_file_mode); _loader_module->initialize(reader_cfg, DecoderConfig(decoder_type), mem_type, _batch_size, decoder_keep_orig); diff --git a/rocAL/rocAL/source/loaders/image/node_image_loader_single_shard.cpp b/rocAL/rocAL/source/loaders/image/node_image_loader_single_shard.cpp index dd6286adcf..7caf5f27bb 100644 --- a/rocAL/rocAL/source/loaders/image/node_image_loader_single_shard.cpp +++ b/rocAL/rocAL/source/loaders/image/node_image_loader_single_shard.cpp @@ -32,7 +32,7 @@ ImageLoaderSingleShardNode::ImageLoaderSingleShardNode(rocalTensor *output, void void ImageLoaderSingleShardNode::init(unsigned shard_id, unsigned shard_count, unsigned cpu_num_threads, const std::string &source_path, const std::string &json_path, StorageType storage_type, DecoderType decoder_type, bool shuffle, bool loop, size_t load_batch_count, RocalMemType mem_type, std::shared_ptr meta_data_reader, - bool decoder_keep_original, const std::map feature_key_map, unsigned sequence_length, unsigned step, unsigned stride) + bool decoder_keep_original, ExternalFileMode external_file_mode, const std::map feature_key_map, unsigned sequence_length, unsigned step, unsigned stride) { if(!_loader_module) THROW("ERROR: loader module is not set for ImageLoaderNode, cannot initialize") @@ -52,6 +52,7 @@ ImageLoaderSingleShardNode::init(unsigned shard_id, unsigned shard_count, unsign reader_cfg.set_sequence_length(sequence_length); reader_cfg.set_frame_step(step); reader_cfg.set_frame_stride(stride); + reader_cfg.set_external_filemode(external_file_mode); _loader_module->initialize(reader_cfg, DecoderConfig(decoder_type), mem_type, _batch_size, decoder_keep_original); diff --git a/rocAL/rocAL/source/meta_data/meta_data_reader_factory.cpp b/rocAL/rocAL/source/meta_data/meta_data_reader_factory.cpp index fd6dfe0949..a4e7fa4243 100644 --- a/rocAL/rocAL/source/meta_data/meta_data_reader_factory.cpp +++ b/rocAL/rocAL/source/meta_data/meta_data_reader_factory.cpp @@ -37,6 +37,7 @@ THE SOFTWARE. #include "tf_meta_data_reader_detection.h" #include "video_label_reader.h" #include "mxnet_meta_data_reader.h" +#include "external_source_label_reader.h" std::shared_ptr create_meta_data_reader(const MetaDataConfig& config) { switch(config.reader_type()) { @@ -159,6 +160,15 @@ std::shared_ptr create_meta_data_reader(const MetaDataConfig& co return ret; } break; + case MetaDataReaderType::EXTERNAL_SOURCE_LABEL_READER: + { + if(config.type() != MetaDataType::Label) + THROW("ExternalSourceLabelReader can only be used to load labels") + auto ret = std::make_shared(); + ret->init(config); + return ret; + } + break; default: THROW("MetaDataReader type is unsupported : "+ TOSTR(config.reader_type())); } diff --git a/rocAL/rocAL/source/pipeline/master_graph.cpp b/rocAL/rocAL/source/pipeline/master_graph.cpp index 84ea581221..e1cad2d343 100644 --- a/rocAL/rocAL/source/pipeline/master_graph.cpp +++ b/rocAL/rocAL/source/pipeline/master_graph.cpp @@ -440,6 +440,8 @@ MasterGraph::reset() size_t MasterGraph::remaining_count() { + if(!_external_source_eos && _external_source_reader) + return _user_batch_size; return (_remaining_count >= 0) ? _remaining_count:0; } @@ -1512,3 +1514,25 @@ MasterGraph::get_bbox_encoded_buffers(size_t num_encoded_boxes) } return bbox_encoded_output; } + +void MasterGraph::feed_external_input(std::vector input_images_names, std::vector labels, std::vectorinput_buffer, + std::vector roi_width, std::vector roi_height, unsigned int max_width, unsigned int max_height, int channels, + ExternalFileMode mode, RocalTensorFormat layout, bool eos) +{ + _external_source_eos = eos; + _loader_module->feed_external_input(input_images_names, labels, input_buffer, roi_width, roi_height, max_width, max_height, channels, mode, eos); + if(!labels.empty() && !_meta_data_reader) + { + MetaDataConfig config(MetaDataType::Label, MetaDataReaderType::EXTERNAL_SOURCE_LABEL_READER); + _meta_data_reader = create_meta_data_reader(config); + _meta_data_reader->add_labels(input_images_names, labels); + if (_augmented_meta_data) + THROW("Metadata can only have a single output") + else + _augmented_meta_data = _meta_data_reader->get_output(); + } + else if(!labels.empty() && _meta_data_reader) + { + _meta_data_reader->add_labels(input_images_names, labels); + } +} diff --git a/rocAL/rocAL/source/readers/image/reader_factory.cpp b/rocAL/rocAL/source/readers/image/reader_factory.cpp index 01f4e87588..59da08b0f5 100644 --- a/rocAL/rocAL/source/readers/image/reader_factory.cpp +++ b/rocAL/rocAL/source/readers/image/reader_factory.cpp @@ -31,9 +31,10 @@ THE SOFTWARE. #include "caffe_lmdb_record_reader.h" #include "caffe2_lmdb_record_reader.h" #include "mxnet_recordio_reader.h" +#include "external_source_reader.h" std::shared_ptr create_reader(ReaderConfig config) { - switch(config.type()) { + switch(config.storage_type()) { case StorageType ::FILE_SYSTEM: { auto ret = std::make_shared(); @@ -98,6 +99,13 @@ std::shared_ptr create_reader(ReaderConfig config) { return ret; } break; + case StorageType::EXTERNAL_FILE_SOURCE: + { + auto ret = std::make_shared(); + if(ret->initialize(config) != Reader::Status::OK) + throw std::runtime_error("ExternalSourceReader cannot access the storage"); + return ret; + } default: throw std::runtime_error ("Reader type is unsupported"); } diff --git a/rocAL/rocAL_pybind/amd/rocal/fn.py b/rocAL/rocAL_pybind/amd/rocal/fn.py index 113e8c420c..98e3a464a2 100644 --- a/rocAL/rocAL_pybind/amd/rocal/fn.py +++ b/rocAL/rocAL_pybind/amd/rocal/fn.py @@ -189,4 +189,16 @@ def box_iou_matcher(*inputs, anchors, criteria=0.5, high_threshold=0.5, low_thre kwargs_pybind ={"anchors":anchors, "criteria":criteria, "high_threshold":high_threshold, "low_threshold":low_threshold, "allow_low_quality_matches":allow_low_quality_matches} box_iou_matcher = b.BoxIOUMatcher(Pipeline._current_pipeline._handle ,*(kwargs_pybind.values())) Pipeline._current_pipeline._BoxIOUMatcher = True - return (box_iou_matcher , []) # check what should be the return type \ No newline at end of file + return (box_iou_matcher , []) # check what should be the return type + +def external_source(*inputs, source, device=None, color_format=types.RGB, random_shuffle=False,mode=types.EXTSOURCE_FNAME, max_width=2000, max_heigth=2000): + # pybind call arguments + Pipeline._current_pipeline._external_source_operator = True + Pipeline._current_pipeline._external_source = iter(source) + Pipeline._current_pipeline._external_source_mode = mode + Pipeline._current_pipeline._external_source_user_given_width = max_width + Pipeline._current_pipeline._external_source_user_given_height = max_heigth + kwargs_pybind = {"source_path" : source.images_dir, "rocal_color_format" : color_format, "is_output" : False, "shuffle" : random_shuffle, "loop" : False, "decode_size_policy" : types.USER_GIVEN_SIZE, + "max_width" : 2000, "max_height" : 2000, "dec_type" : types.DECODER_TJPEG, "external_source_mode" : mode} + external_source_operator = b.ExternalFileSource(Pipeline._current_pipeline._handle, *(kwargs_pybind.values())) + return (external_source_operator, []) # Labels is Empty \ No newline at end of file diff --git a/rocAL/rocAL_pybind/amd/rocal/pipeline.py b/rocAL/rocAL_pybind/amd/rocal/pipeline.py index 470191dc1b..345cc06125 100644 --- a/rocAL/rocAL_pybind/amd/rocal/pipeline.py +++ b/rocAL/rocAL_pybind/amd/rocal/pipeline.py @@ -147,6 +147,9 @@ def __init__(self, batch_size=-1, num_threads=0, device_id=-1, seed=1, self._reader = None self._define_graph_set = False self.set_seed(self._seed) + self._external_source_operator = False + self._external_source = None + self._external_source_mode = None def build(self): """Build the pipeline using rocalVerify call diff --git a/rocAL/rocAL_pybind/amd/rocal/plugin/generic.py b/rocAL/rocAL_pybind/amd/rocal/plugin/generic.py index 0405e16aef..c4a27aa07c 100644 --- a/rocAL/rocAL_pybind/amd/rocal/plugin/generic.py +++ b/rocAL/rocAL_pybind/amd/rocal/plugin/generic.py @@ -72,6 +72,8 @@ def __init__(self, pipeline, tensor_layout = types.NCHW, reverse_channels = Fals self.h = b.getOutputHeight(self.loader._handle) self.n = b.getOutputImageCount(self.loader._handle) self.bs = pipeline._batch_size + self.index = 0 + self.eos = False if self.loader._name is None: self.loader._name= self.loader._reader color_format = b.getOutputColorFormat(self.loader._handle) @@ -113,7 +115,8 @@ def __init__(self, pipeline, tensor_layout = types.NCHW, reverse_channels = Fals if self.bs != 0: self.len = b.getRemainingImages(self.loader._handle)//self.bs else: - self.len = b.getRemainingImages(self.loader._handle) + self.len = b.getRemainingImages(self.loader._handle) + self.num_batches = self.loader._external_source.n // self.bs if self.loader._external_source.n % self.bs == 0 else (self.loader._external_source.n // self.bs + 1) def next(self): return self.__next__() @@ -125,6 +128,32 @@ def __next__(self): if self.loader.run() != 0: raise StopIteration + if (self.loader._external_source_operator): + if (self.index + 1) == self.num_batches: + self.eos = True + if (self.index + 1) <= self.num_batches: + if self.loader._external_source_mode == types.EXTSOURCE_FNAME: + kwargs_pybind = { + "handle":self.loader._handle, + "source_input_images":next(self.loader._external_source)[0], + "labels":next(self.loader._external_source)[1], + "input_batch_buffer":[], + "roi_width":[], + "roi_height":[], + "decoded_width":self.loader._external_source_user_given_width, + "decoded_height":self.loader._external_source_user_given_height, + "channels":self.p, + "external_source_mode":self.loader._external_source_mode, + "rocal_tensor_layout":types.NCHW, + "eos":self.eos } + b.ExternalSourceFeedInput(*(kwargs_pybind.values())) + if self.loader._external_source_mode == types.EXTSOURCE_RAW_COMPRESSED: + print("Support for EXTSOURCE_RAW_COMPRESSED / Mode 1 does not exist ") + exit(0) + if self.loader._external_source_mode == types.EXTSOURCE_RAW_UNCOMPRESSED: + print("Support for EXTSOURCE_RAW_UNCOMPRESSED / Mode 2 does not exist ") + exit(0) + if(types.NCHW == self.tensor_format): self.loader.copyToExternalTensorNCHW(self.out, self.multiplier, self.offset, self.reverse_channels, int(self.tensor_dtype)) else: diff --git a/rocAL/rocAL_pybind/amd/rocal/plugin/pytorch.py b/rocAL/rocAL_pybind/amd/rocal/plugin/pytorch.py index 58b5fc8f75..101d21413a 100644 --- a/rocAL/rocAL_pybind/amd/rocal/plugin/pytorch.py +++ b/rocAL/rocAL_pybind/amd/rocal/plugin/pytorch.py @@ -83,7 +83,9 @@ def __init__(self, pipeline, tensor_layout = types.NCHW, reverse_channels = Fals self.out = None print("self.device", self.device) self.len = b.getRemainingImages(self.loader._handle) - + self.index = 0 + self.eos = False + self.num_batches = self.loader._external_source.n // self.bs if self.loader._external_source.n % self.bs == 0 else (self.loader._external_source.n // self.bs + 1) def next(self): return self.__next__() @@ -103,6 +105,32 @@ def __next__(self): if self.loader.rocalRun() != 0: raise StopIteration + + if (self.loader._external_source_operator): + if (self.index + 1) == self.num_batches: + self.eos = True + if (self.index + 1) <= self.num_batches: + if self.loader._external_source_mode == types.EXTSOURCE_FNAME: + kwargs_pybind = { + "handle":self.loader._handle, + "source_input_images":next(self.loader._external_source)[0], + "labels":next(self.loader._external_source)[1], + "input_batch_buffer":[], + "roi_width":[], + "roi_height":[], + "decoded_width":self.loader._external_source_user_given_width, + "decoded_height":self.loader._external_source_user_given_height, + "channels":self.p, + "external_source_mode":self.loader._external_source_mode, + "rocal_tensor_layout":types.NCHW, + "eos":self.eos } + b.ExternalSourceFeedInput(*(kwargs_pybind.values())) + if self.loader._external_source_mode == types.EXTSOURCE_RAW_COMPRESSED: + print("Support for EXTSOURCE_RAW_COMPRESSED / Mode 1 does not exist ") + exit(0) + if self.loader._external_source_mode == types.EXTSOURCE_RAW_UNCOMPRESSED: + print("Support for EXTSOURCE_RAW_UNCOMPRESSED / Mode 2 does not exist ") + exit(0) else: self.output_tensor_list = self.loader.rocalGetOutputTensors() @@ -144,7 +172,7 @@ def __next__(self): elif self.tensor_dtype == types.FLOAT16: self.out = torch.empty((self.batch_size, self.h, self.w, self.color_format), dtype=torch.float16, device=torch_gpu_device) self.labels_tensor = torch.empty(self.batch_size, dtype = torch.int32, device = torch_gpu_device) - + self.index = self.index + 1 self.loader.copyToExternalTensor( self.out, self.multiplier, self.offset, self.reverse_channels, self.tensor_format, self.tensor_dtype) self.labels = self.loader.rocalGetImageLabels() diff --git a/rocAL/rocAL_pybind/amd/rocal/types.py b/rocAL/rocAL_pybind/amd/rocal/types.py index d28fe14eee..c6ad2262e1 100644 --- a/rocAL/rocAL_pybind/amd/rocal/types.py +++ b/rocAL/rocAL_pybind/amd/rocal/types.py @@ -83,6 +83,11 @@ from rocal_pybind.types import GAUSSIAN_INTERPOLATION from rocal_pybind.types import TRIANGULAR_INTERPOLATION +# Rocal External Source Mode +from rocal_pybind.types import EXTSOURCE_FNAME +from rocal_pybind.types import EXTSOURCE_RAW_COMPRESSED +from rocal_pybind.types import EXTSOURCE_RAW_UNCOMPRESSED + _known_types = { OK: ("OK", OK), @@ -133,6 +138,10 @@ SCALING_MODE_STRETCH: ("SCALING_MODE_STRETCH", SCALING_MODE_STRETCH), SCALING_MODE_NOT_SMALLER: ("SCALING_MODE_NOT_SMALLER", SCALING_MODE_NOT_SMALLER), SCALING_MODE_NOT_LARGER: ("SCALING_MODE_NOT_LARGER", SCALING_MODE_NOT_LARGER), + + EXTSOURCE_FNAME : ("EXTSOURCE_FNAME", EXTSOURCE_FNAME), + EXTSOURCE_RAW_COMPRESSED : ("EXTSOURCE_RAW_COMPRESSED", EXTSOURCE_RAW_COMPRESSED), + EXTSOURCE_RAW_UNCOMPRESSED : ("EXTSOURCE_RAW_UNCOMPRESSED", EXTSOURCE_RAW_UNCOMPRESSED), } diff --git a/rocAL/rocAL_pybind/rocal_pybind.cpp b/rocAL/rocAL_pybind/rocal_pybind.cpp index f98a7ba16c..aef7e18d8a 100644 --- a/rocAL/rocAL_pybind/rocal_pybind.cpp +++ b/rocAL/rocAL_pybind/rocal_pybind.cpp @@ -343,6 +343,11 @@ namespace rocal .value("GAUSSIAN_INTERPOLATION",ROCAL_GAUSSIAN_INTERPOLATION) .value("TRIANGULAR_INTERPOLATION",ROCAL_TRIANGULAR_INTERPOLATION) .export_values(); + py::enum_(types_m,"RocalExtSourceMode", "Rocal Extrernal Source Mode") + .value("EXTSOURCE_FNAME",ROCAL_EXTSOURCE_FNAME) + .value("EXTSOURCE_RAW_COMPRESSED",ROCAL_EXTSOURCE_RAW_COMPRESSED) + .value("EXTSOURCE_RAW_UNCOMPRESSED",ROCAL_EXTSOURCE_RAW_UNCOMPRESSED) + .export_values(); // rocal_api_info.h m.def("getRemainingImages", &rocalGetRemainingImages); m.def("isEmpty", &rocalIsEmpty); @@ -498,6 +503,10 @@ namespace rocal py::return_value_policy::reference); m.def("COCO_ImageDecoderSliceShard",&rocalJpegCOCOFileSourcePartialSingleShard,"Reads file from the source given and decodes it according to the policy", py::return_value_policy::reference); + m.def("ExternalFileSource",&rocalJpegExternalFileSource, + py::return_value_policy::reference); + m.def("ExternalSourceFeedInput",&rocalExternalSourceFeedInput, + py::return_value_policy::reference); m.def("Resize",&rocalResize, "Resizes the image ",py::return_value_policy::reference); m.def("ColorTwist",&rocalColorTwist, py::return_value_policy::reference); m.def("rocalResetLoaders", &rocalResetLoaders); From 0db31a8e6c751fd23893aa5519e62dabf7779ffd Mon Sep 17 00:00:00 2001 From: Snehaa Giridharan Date: Sun, 16 Jul 2023 21:14:55 -0400 Subject: [PATCH 03/15] Fix build issues --- rocAL/rocAL/include/loaders/video/video_loader.h | 3 +++ .../include/loaders/video/video_loader_sharded.h | 3 +++ .../include/meta_data/coco_meta_data_reader.h | 1 - rocAL/rocAL/include/meta_data/meta_data_reader.h | 1 + rocAL/rocAL/include/pipeline/master_graph.h | 2 +- rocAL/rocAL/include/readers/image/reader.h | 4 ++-- rocAL/rocAL/source/api/rocal_api_data_loaders.cpp | 9 ++++++--- rocAL/rocAL/source/api/rocal_api_data_transfer.cpp | 14 ++++++++------ rocAL/rocAL/source/pipeline/master_graph.cpp | 2 +- .../source/readers/video/video_reader_factory.cpp | 2 +- utilities/rocAL/rocAL_unittests/CMakeLists.txt | 2 +- 11 files changed, 27 insertions(+), 16 deletions(-) diff --git a/rocAL/rocAL/include/loaders/video/video_loader.h b/rocAL/rocAL/include/loaders/video/video_loader.h index 0905cc8333..a9aab11c46 100644 --- a/rocAL/rocAL/include/loaders/video/video_loader.h +++ b/rocAL/rocAL/include/loaders/video/video_loader.h @@ -55,6 +55,9 @@ class VideoLoader : public LoaderModule void set_random_bbox_data_reader(std::shared_ptr randombboxcrop_meta_data_reader) override {}; std::vector get_sequence_start_frame_number(); std::vector> get_sequence_frame_timestamps(); + void feed_external_input(std::vector input_images_names, std::vector labels, std::vector input_buffer, + std::vector roi_width, std::vector roi_height, + unsigned int max_width, unsigned int max_height, int channels, ExternalFileMode mode, bool eos) override { return; } void shut_down() override; private: diff --git a/rocAL/rocAL/include/loaders/video/video_loader_sharded.h b/rocAL/rocAL/include/loaders/video/video_loader_sharded.h index 91dd3556c8..449ee23a73 100644 --- a/rocAL/rocAL/include/loaders/video/video_loader_sharded.h +++ b/rocAL/rocAL/include/loaders/video/video_loader_sharded.h @@ -47,6 +47,9 @@ class VideoLoaderSharded : public LoaderModule void set_random_bbox_data_reader(std::shared_ptr randombboxcrop_meta_data_reader) override {}; std::vector get_sequence_start_frame_number() override; std::vector> get_sequence_frame_timestamps() override; + void feed_external_input(std::vector input_images_names, std::vector labels, std::vector input_buffer, + std::vector roi_width, std::vector roi_height, + unsigned int max_width, unsigned int max_height, int channels, ExternalFileMode mode, bool eos) override { return; } Timing timing() override; private: void increment_loader_idx(); diff --git a/rocAL/rocAL/include/meta_data/coco_meta_data_reader.h b/rocAL/rocAL/include/meta_data/coco_meta_data_reader.h index a38eb38ef1..e1080077c1 100644 --- a/rocAL/rocAL/include/meta_data/coco_meta_data_reader.h +++ b/rocAL/rocAL/include/meta_data/coco_meta_data_reader.h @@ -40,7 +40,6 @@ class COCOMetaDataReader: public MetaDataReader bool set_timestamp_mode() override { return false; } MetaDataBatch * get_output() override { return _output; } const std::map> & get_map_content() override { return _map_content;} - void add_labels(std::vector image_name, std::vector label) override { }; COCOMetaDataReader(); ~COCOMetaDataReader() override { delete _output; } private: diff --git a/rocAL/rocAL/include/meta_data/meta_data_reader.h b/rocAL/rocAL/include/meta_data/meta_data_reader.h index 9f983d0ffe..4f4c144bd4 100644 --- a/rocAL/rocAL/include/meta_data/meta_data_reader.h +++ b/rocAL/rocAL/include/meta_data/meta_data_reader.h @@ -95,6 +95,7 @@ class MetaDataReader virtual void init(const MetaDataConfig& cfg) = 0; virtual void read_all(const std::string& path) = 0;// Reads all the meta data information virtual void lookup(const std::vector& image_names) = 0;// finds meta_data info associated with given names and fills the output + virtual void add_labels(std::vector image_name, std::vector label) = 0; virtual void release() = 0; // Deletes the loaded information virtual MetaDataBatch * get_output()= 0; virtual const std::map> & get_map_content()=0; diff --git a/rocAL/rocAL/include/pipeline/master_graph.h b/rocAL/rocAL/include/pipeline/master_graph.h index e3c3226164..2aa7448bea 100644 --- a/rocAL/rocAL/include/pipeline/master_graph.h +++ b/rocAL/rocAL/include/pipeline/master_graph.h @@ -107,7 +107,7 @@ class MasterGraph void set_sequence_batch_size(size_t sequence_length) { _sequence_batch_size = _user_batch_size * sequence_length; } void feed_external_input(std::vector input_images_names, std::vector labels, std::vectorinput_buffer, std::vector roi_width, std::vector roi_height, unsigned int max_width, - unsigned int max_height, int channels, ExternalFileMode mode, RocalTensorFormat layout, bool eos); + unsigned int max_height, int channels, ExternalFileMode mode, RocalTensorlayout layout, bool eos); void set_external_source_reader_flag() { _external_source_reader = true; } std::vector get_bbox_encoded_buffers(size_t num_encoded_boxes); size_t bounding_box_batch_count(int* buf, pMetaDataBatch meta_data_batch); diff --git a/rocAL/rocAL/include/readers/image/reader.h b/rocAL/rocAL/include/readers/image/reader.h index 1b7c9adad1..b169e5a478 100644 --- a/rocAL/rocAL/include/readers/image/reader.h +++ b/rocAL/rocAL/include/readers/image/reader.h @@ -60,8 +60,8 @@ struct ReaderConfig { explicit ReaderConfig(StorageType type, std::string path = "", std::string json_path = "", const std::map feature_key_map = std::map(), - bool shuffle = false, bool loop = false, ExternalFileMode mode = ExternalFileMode::FILENAME) : _type(type), _path(path), _json_path(json_path), _feature_key_map(feature_key_map), _shuffle(shuffle), _loop(loop, _file_mode(mode)) {} - virtual StorageType type() { return _type; }; + bool shuffle = false, bool loop = false, ExternalFileMode mode = ExternalFileMode::FILENAME) : _storage_type(type), _path(path), _json_path(json_path), _feature_key_map(feature_key_map), _shuffle(shuffle), _loop(loop), _file_mode(mode) {} + virtual StorageType storage_type() { return _storage_type; } void set_path(const std::string &path) { _path = path; } void set_shard_id(size_t shard_id) { _shard_id = shard_id; } void set_shard_count(size_t shard_count) { _shard_count = shard_count; } diff --git a/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp b/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp index fdd1e4dabb..ab4debbc59 100644 --- a/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp +++ b/rocAL/rocAL/source/api/rocal_api_data_loaders.cpp @@ -336,7 +336,7 @@ rocalSequenceReader( auto cpu_num_threads = context->master_graph->calculate_cpu_num_threads(1); context->master_graph->add_node({}, {output})->init(internal_shard_count, cpu_num_threads, - source_path, ExternalFileMode::FILENAME, "", + source_path, "", std::map(), StorageType::SEQUENCE_FILE_SYSTEM, DecoderType::TURBO_JPEG, @@ -345,7 +345,7 @@ rocalSequenceReader( context->master_graph->sequence_batch_size(), context->master_graph->mem_type(), context->master_graph->meta_data_reader(), - decoder_keep_original, "", + decoder_keep_original, ExternalFileMode::FILENAME, "", sequence_length, step, stride); context->master_graph->set_loop(loop); @@ -435,6 +435,7 @@ rocalSequenceReaderSingleShard( context->master_graph->mem_type(), context->master_graph->meta_data_reader(), decoder_keep_original, + ExternalFileMode::FILENAME, std::map(), sequence_length, step, stride); @@ -2300,7 +2301,9 @@ rocalJpegExternalFileSource( // color_format ); output = context->master_graph->create_loader_output_tensor(info); context->master_graph->set_external_source_reader_flag(); - context->master_graph->add_node({}, {output})->init(internal_shard_count, + unsigned shard_count = 1; // Hardcoding the shard count to 1 for now. Check with Shobana on this + auto cpu_num_threads = context->master_graph->calculate_cpu_num_threads(shard_count); + context->master_graph->add_node({}, {output})->init(internal_shard_count, cpu_num_threads, source_path, "", std::map(), StorageType::EXTERNAL_FILE_SOURCE, diff --git a/rocAL/rocAL/source/api/rocal_api_data_transfer.cpp b/rocAL/rocAL/source/api/rocal_api_data_transfer.cpp index 41aa8bf25e..a29b79b01b 100644 --- a/rocAL/rocAL/source/api/rocal_api_data_transfer.cpp +++ b/rocAL/rocAL/source/api/rocal_api_data_transfer.cpp @@ -79,17 +79,19 @@ rocalExternalSourceFeedInput( unsigned int max_height, int channels, RocalExtSourceMode mode, - RocalTensorLayout layout,p - bool eos) { + RocalTensorlayout layout, + bool eos) +{ auto context = static_cast(p_context); - try { + try + { ExternalFileMode external_file_mode = (ExternalFileMode) mode; - RocalTensorFormat format = (RocalTensorFormat) layout; context->master_graph->feed_external_input(input_images_names, labels, input_buffer, roi_width, roi_height, max_width, max_height, channels, - external_file_mode, format, eos); + external_file_mode, layout, eos); } - catch(const std::exception& e) { + catch(const std::exception& e) + { context->capture_error(e.what()); ERR(e.what()) return ROCAL_RUNTIME_ERROR; diff --git a/rocAL/rocAL/source/pipeline/master_graph.cpp b/rocAL/rocAL/source/pipeline/master_graph.cpp index e1cad2d343..a92c1c67fa 100644 --- a/rocAL/rocAL/source/pipeline/master_graph.cpp +++ b/rocAL/rocAL/source/pipeline/master_graph.cpp @@ -1517,7 +1517,7 @@ MasterGraph::get_bbox_encoded_buffers(size_t num_encoded_boxes) void MasterGraph::feed_external_input(std::vector input_images_names, std::vector labels, std::vectorinput_buffer, std::vector roi_width, std::vector roi_height, unsigned int max_width, unsigned int max_height, int channels, - ExternalFileMode mode, RocalTensorFormat layout, bool eos) + ExternalFileMode mode, RocalTensorlayout layout, bool eos) { _external_source_eos = eos; _loader_module->feed_external_input(input_images_names, labels, input_buffer, roi_width, roi_height, max_width, max_height, channels, mode, eos); diff --git a/rocAL/rocAL/source/readers/video/video_reader_factory.cpp b/rocAL/rocAL/source/readers/video/video_reader_factory.cpp index 0c517b2097..c7f7813452 100644 --- a/rocAL/rocAL/source/readers/video/video_reader_factory.cpp +++ b/rocAL/rocAL/source/readers/video/video_reader_factory.cpp @@ -27,7 +27,7 @@ THE SOFTWARE. #ifdef ROCAL_VIDEO std::shared_ptr create_video_reader(ReaderConfig config) { - switch(config.type()) { + switch(config.storage_type()) { case StorageType::VIDEO_FILE_SYSTEM: { auto ret = std::make_shared(); diff --git a/utilities/rocAL/rocAL_unittests/CMakeLists.txt b/utilities/rocAL/rocAL_unittests/CMakeLists.txt index 2ba2899c75..e28ca1b7b9 100644 --- a/utilities/rocAL/rocAL_unittests/CMakeLists.txt +++ b/utilities/rocAL/rocAL_unittests/CMakeLists.txt @@ -25,7 +25,7 @@ ################################################################################ cmake_minimum_required(VERSION 3.0) -project (rocAL_unittests) +project (rocAL_external_source) set(CMAKE_CXX_STANDARD 14) # ROCm Path From 2c6157d98565693f2ffc2ded53768bc40c86c6ee Mon Sep 17 00:00:00 2001 From: Snehaa Giridharan Date: Sun, 16 Jul 2023 21:58:13 -0400 Subject: [PATCH 04/15] Fix build issues --- .../meta_data/external_source_label_reader.h | 55 +++ .../readers/image/external_source_reader.h | 122 ++++++ .../external_source_label_reader.cpp | 90 +++++ .../readers/image/external_source_reader.cpp | 227 +++++++++++ .../rocAL_api_external_source_example.py | 84 ++++ utilities/rocAL/CMakeLists.txt | 63 +++ .../rocal_external_source.cpp | 380 ++++++++++++++++++ 7 files changed, 1021 insertions(+) create mode 100644 rocAL/rocAL/include/meta_data/external_source_label_reader.h create mode 100644 rocAL/rocAL/include/readers/image/external_source_reader.h create mode 100644 rocAL/rocAL/source/meta_data/external_source_label_reader.cpp create mode 100644 rocAL/rocAL/source/readers/image/external_source_reader.cpp create mode 100644 rocAL/rocAL_pybind/examples/rocAL_api_external_source_example.py create mode 100644 utilities/rocAL/CMakeLists.txt create mode 100644 utilities/rocAL/rocal_external_source/rocal_external_source.cpp diff --git a/rocAL/rocAL/include/meta_data/external_source_label_reader.h b/rocAL/rocAL/include/meta_data/external_source_label_reader.h new file mode 100644 index 0000000000..a5dbd63923 --- /dev/null +++ b/rocAL/rocAL/include/meta_data/external_source_label_reader.h @@ -0,0 +1,55 @@ +/* +Copyright (c) 2019 - 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#pragma once +#include +#include +#include "commons.h" +#include "meta_data.h" +#include "meta_data_reader.h" + +class ExternalSourceLabelReader: public MetaDataReader +{ +public: + void init(const MetaDataConfig& cfg) override; + void lookup(const std::vector& image_names) override; + void add_labels(std::vector image_name, std::vector label) override; + void read_all(const std::string& path) override { }; + void release(std::string image_name); + void release() override; + void print_map_contents(); + bool set_timestamp_mode() override { return false; } + MetaDataBatch * get_output() override { return _output; } + const std::map> & get_map_content() override { return _map_content; } + ExternalSourceLabelReader(); + ~ExternalSourceLabelReader() override { delete _output; } +private: + void read_files(const std::string& _path) { }; + bool exists(const std::string &image_name); + void add(std::string image_name, int label); + std::map> _map_content; + std::map>::iterator _itr; + LabelBatch* _output; + std::vector _file_names; + std::vector _subfolder_file_names; +}; + diff --git a/rocAL/rocAL/include/readers/image/external_source_reader.h b/rocAL/rocAL/include/readers/image/external_source_reader.h new file mode 100644 index 0000000000..327c5aca69 --- /dev/null +++ b/rocAL/rocAL/include/readers/image/external_source_reader.h @@ -0,0 +1,122 @@ +/* +Copyright (c) 2019 - 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#pragma once +#include +#include +#include +#include +#include +#include "reader.h" +#include "commons.h" +#include "timing_debug.h" + +class ExternalSourceReader : public Reader { +public: + //! Looks up the folder which contains the files, amd loads the image names + /*! + \param desc User provided descriptor containing the files' path. + */ + Reader::Status initialize(ReaderConfig desc) override; + //! Reads the next resource item + /*! + \param buf User's provided buffer to receive the loaded images + \return Size of the loaded resource + */ + size_t read_data(unsigned char* buf, size_t max_size) override; + //! Opens the next file in the folder + /*! + \return The size of the next file, 0 if couldn't access it + */ + size_t open() override; + + //! Resets the object's state to read from the first file in the list + void reset() override; + + //! Returns the name of the latest file opened + std::string id() override { return _last_id; } + + //! Return batch_size() for count_items unless end_of_sequence has been signalled + unsigned count_items() override; + + ~ExternalSourceReader() override; + + int close() override; + + ExternalSourceReader(); + + //! receive next set of filenames from external source + void feed_file_names(const std::vector& file_names, size_t num_images, bool eos = false) override; + + //! receive next set of file data from external source + void feed_data(const std::vector& images, const std::vector& image_size, ExternalFileMode mode, bool eos = false, int width = 0, int height = 0, int channels = 0) override; + + // mode(): returs the mode for the reader + ExternalFileMode mode() { return _file_mode; } + + // get image_dims + void get_dims(int cur_idx, int& width, int& height, int& channels); + + +private: + //! opens the folder containnig the images + std::string _folder_path; + std::queue _file_names_queue; + std::vector _file_sizes; + std::vector> _file_data; + std::queue> _images_data_queue; + std::mutex _lock; + std::condition_variable _wait_for_input; + + unsigned _curr_file_idx; + FILE* _current_fPtr; + unsigned _current_file_size; + std::string _last_id; + std::string _last_file_name; + size_t _shard_id = 0; + size_t _shard_count = 1;// equivalent of batch size + //!< _batch_count Defines the quantum count of the images to be read. It's usually equal to the user's batch size. + /// The loader will repeat images if necessary to be able to have images available in multiples of the load_batch_count, + /// for instance if there are 10 images in the dataset and _batch_count is 3, the loader repeats 2 images as if there are 12 images available. + size_t _batch_count = 1; + size_t _file_id = 0; + size_t _in_batch_read_count = 0; + bool _loop; + bool _shuffle; + int _read_counter = 0; + volatile bool _end_of_sequence; + //!< _file_count_all_shards total_number of files in to figure out the max_batch_size (usually needed for distributed training). + void push_file_name(const std::string& image_name); + bool pop_file_name(std::string& file_name); + void push_file_data(std::tuple& image); + bool pop_file_data(std::tuple& image); + size_t _file_count_all_shards; + void increment_read_ptr(); + int release(); + size_t get_file_shard_id(); + void increment_file_id() { _file_id++; } + void replicate_last_image_to_fill_last_shard(); + void replicate_last_batch_to_pad_partial_shard(); + ExternalFileMode _file_mode; +}; + + diff --git a/rocAL/rocAL/source/meta_data/external_source_label_reader.cpp b/rocAL/rocAL/source/meta_data/external_source_label_reader.cpp new file mode 100644 index 0000000000..58d52b705d --- /dev/null +++ b/rocAL/rocAL/source/meta_data/external_source_label_reader.cpp @@ -0,0 +1,90 @@ +/* +Copyright (c) 2019 - 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include +#include +#include +#include +#include "commons.h" +#include "exception.h" +#include "external_source_label_reader.h" + +ExternalSourceLabelReader::ExternalSourceLabelReader() {} + +void ExternalSourceLabelReader::init(const MetaDataConfig& cfg) { + _output = new LabelBatch(); +} + +bool ExternalSourceLabelReader::exists(const std::string& image_name) { + return _map_content.find(image_name) != _map_content.end(); +} + +void ExternalSourceLabelReader::add(std::string image_name, int label) { + pMetaData info = std::make_shared