Skip to content

Commit

Permalink
Metadata fix (#29)
Browse files Browse the repository at this point in the history
* Fix metadata clone
  • Loading branch information
fiona-gladwin authored Aug 10, 2023
1 parent c84a5d8 commit 2723b33
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion rocAL/rocAL/include/meta_data/coco_meta_data_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class COCOMetaDataReader: public MetaDataReader
pMetaDataBatch _output;
std::string _path;
int meta_data_reader_type;
void add(std::string image_name, BoundingBoxCords bbox, Labels labels, ImgSize image_size, uint image_id = 0);
void add(std::string image_name, BoundingBoxCords bbox, Labels labels, ImgSize image_size, int image_id = 0);
void add(std::string image_name, BoundingBoxCords bbox, Labels labels, ImgSize image_size, MaskCords mask_cords, std::vector<int> polygon_count, std::vector<std::vector<int>> vertices_count); // To add Mask coordinates to Metadata struct
bool exists(const std::string &image_name) override;
std::map<std::string, std::shared_ptr<MetaData>> _map_content;
Expand Down
63 changes: 41 additions & 22 deletions rocAL/rocAL/include/meta_data/meta_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ typedef struct

typedef class MetaDataInfo {
public:
uint img_id = -1;
int img_id = -1;
std::string img_name = "";
ImgSize img_size = {};
} MetaDataInfo;
Expand All @@ -121,9 +121,9 @@ class MetaData
virtual void set_joints_data(JointsData *joints_data) = 0;
ImgSize& get_img_size() { return _info.img_size; }
std::string& get_image_name() { return _info.img_name; }
uint& get_image_id() { return _info.img_id; }
int& get_image_id() { return _info.img_id; }
void set_img_size(ImgSize img_size) { _info.img_size = std::move(img_size); }
void set_img_id(uint img_id) { _info.img_id = img_id; }
void set_img_id(int img_id) { _info.img_id = img_id; }
void set_img_name(std::string img_name) { _info.img_name = img_name; }
void set_metadata_info(MetaDataInfo info) { _info = std::move(info); }
protected:
Expand Down Expand Up @@ -155,7 +155,7 @@ class BoundingBox : public Label
{
public:
BoundingBox()= default;
BoundingBox(BoundingBoxCords bb_cords, Labels bb_label_ids, ImgSize img_size = ImgSize{0, 0}, uint img_id = 0)
BoundingBox(BoundingBoxCords bb_cords, Labels bb_label_ids, ImgSize img_size = ImgSize{0, 0}, int img_id = 0)
{
_bb_cords =std::move(bb_cords);
_label_ids = std::move(bb_label_ids);
Expand Down Expand Up @@ -208,7 +208,7 @@ class KeyPoint : public BoundingBox

class MetaDataInfoBatch {
public:
std::vector<uint> img_ids = {};
std::vector<int> img_ids = {};
std::vector<std::string> img_names = {};
std::vector<ImgSize> img_sizes = {};
void clear() {
Expand Down Expand Up @@ -252,7 +252,7 @@ class MetaDataBatch
virtual std::vector<std::vector<int>>& get_mask_polygons_count_batch() = 0;
virtual std::vector<std::vector<std::vector<int>>>& get_mask_vertices_count_batch() = 0;
virtual JointsDataBatch & get_joints_data_batch() = 0;
std::vector<uint>& get_image_id_batch() { return _info_batch.img_ids; }
std::vector<int>& get_image_id_batch() { return _info_batch.img_ids; }
std::vector<std::string>& get_image_names_batch() {return _info_batch.img_names; }
ImgSizes& get_img_sizes_batch() { return _info_batch.img_sizes; }
MetaDataInfoBatch& get_info_batch() { return _info_batch; }
Expand Down Expand Up @@ -292,10 +292,14 @@ class LabelBatch : public MetaDataBatch
}
std::shared_ptr<MetaDataBatch> clone(bool copy_contents) override
{
if(copy_contents)
return std::make_shared<LabelBatch>(*this);
else
return std::make_shared<LabelBatch>();
if(copy_contents) {
return std::make_shared<LabelBatch>(*this); // Copy the entire metadata batch with all the metadata values and info
} else {
std::shared_ptr<MetaDataBatch> label_batch_instance = std::make_shared<LabelBatch>();
label_batch_instance->resize(this->size());
label_batch_instance->get_info_batch() = this->get_info_batch(); // Copy only info to newly created instance excluding the metadata values
return label_batch_instance;
}
}
explicit LabelBatch(std::vector<Labels>& labels)
{
Expand All @@ -314,6 +318,7 @@ class LabelBatch : public MetaDataBatch
}
std::vector<size_t>& get_buffer_size() override
{
_buffer_size.clear();
size_t size = 0;
for (auto label : _label_ids)
size += label.size();
Expand Down Expand Up @@ -362,10 +367,14 @@ class BoundingBoxBatch: public LabelBatch
}
std::shared_ptr<MetaDataBatch> clone(bool copy_contents) override
{
if(copy_contents)
return std::make_shared<BoundingBoxBatch>(*this);
else
return std::make_shared<BoundingBoxBatch>();
if(copy_contents) {
return std::make_shared<BoundingBoxBatch>(*this); // Copy the entire metadata batch with all the metadata values and info
} else {
std::shared_ptr<MetaDataBatch> bbox_batch_instance = std::make_shared<BoundingBoxBatch>();
bbox_batch_instance->resize(this->size());
bbox_batch_instance->get_info_batch() = this->get_info_batch(); // Copy only info to newly created instance excluding the metadata values
return bbox_batch_instance;
}
}
void convert_ltrb_to_xywh(BoundingBoxCords& ltrb_bbox_list) {
for(unsigned i = 0; i < ltrb_bbox_list.size(); i++) {
Expand Down Expand Up @@ -393,6 +402,7 @@ class BoundingBoxBatch: public LabelBatch
}
std::vector<size_t>& get_buffer_size() override
{
_buffer_size.clear();
size_t size = 0;
for (auto label : _label_ids)
size += label.size();
Expand Down Expand Up @@ -444,10 +454,14 @@ struct PolygonMaskBatch: public BoundingBoxBatch {
int mask_size() override { return _mask_cords.size(); }
std::shared_ptr<MetaDataBatch> clone(bool copy_contents) override
{
if(copy_contents)
return std::make_shared<PolygonMaskBatch>(*this);
else
return std::make_shared<PolygonMaskBatch>();
if(copy_contents) {
return std::make_shared<PolygonMaskBatch>(*this); // Copy the entire metadata batch with all the metadata values and info
} else {
std::shared_ptr<MetaDataBatch> mask_batch_instance = std::make_shared<PolygonMaskBatch>();
mask_batch_instance->resize(this->size());
mask_batch_instance->get_info_batch() = this->get_info_batch(); // Copy only info to newly created instance excluding the metadata values
return mask_batch_instance;
}
}
void copy_data(std::vector<void*> buffer) override
{
Expand All @@ -470,6 +484,7 @@ struct PolygonMaskBatch: public BoundingBoxBatch {
}
std::vector<size_t>& get_buffer_size() override
{
_buffer_size.clear();
size_t size = 0;
for (auto label : _label_ids)
size += label.size();
Expand Down Expand Up @@ -530,10 +545,14 @@ class KeyPointBatch : public BoundingBoxBatch
}
std::shared_ptr<MetaDataBatch> clone(bool copy_contents) override
{
if(copy_contents)
return std::make_shared<KeyPointBatch>(*this);
else
return std::make_shared<KeyPointBatch>();
if(copy_contents) {
return std::make_shared<KeyPointBatch>(*this); // Copy the entire metadata batch with all the metadata values and info
} else {
std::shared_ptr<MetaDataBatch> joints_batch_instance = std::make_shared<KeyPointBatch>();
joints_batch_instance->resize(this->size());
joints_batch_instance->get_info_batch() = this->get_info_batch(); // Copy only info to newly created instance excluding the metadata values
return joints_batch_instance;
}
}
JointsDataBatch & get_joints_data_batch() override { return _joints_data; }
void copy_data(std::vector<void*> buffer) override {}
Expand Down
3 changes: 2 additions & 1 deletion rocAL/rocAL/source/meta_data/coco_meta_data_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void COCOMetaDataReader::lookup(const std::vector<std::string> &image_names)
_output->get_bb_cords_batch()[i] = it->second->get_bb_cords();
_output->get_labels_batch()[i] = it->second->get_labels();
_output->get_img_sizes_batch()[i] = it->second->get_img_size();
_output->get_image_id_batch()[i] = it->second->get_image_id();
if (_output->get_metadata_type() == MetaDataType::PolygonMask)
{
auto mask_cords = it->second->get_mask_cords();
Expand All @@ -87,7 +88,7 @@ void COCOMetaDataReader::add(std::string image_name, BoundingBoxCords bb_coords,
_map_content.insert(pair<std::string, std::shared_ptr<PolygonMask>>(image_name, info));
}

void COCOMetaDataReader::add(std::string image_name, BoundingBoxCords bb_coords, Labels bb_labels, ImgSize image_size, uint image_id)
void COCOMetaDataReader::add(std::string image_name, BoundingBoxCords bb_coords, Labels bb_labels, ImgSize image_size, int image_id)
{
if (exists(image_name))
{
Expand Down
1 change: 0 additions & 1 deletion rocAL/rocAL/source/pipeline/master_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,6 @@ void MasterGraph::output_routine()
output_meta_data = _augmented_meta_data->clone(!_augmentation_metanode); // copy the data if metadata is not processed by the nodes, else create an empty instance
if (_meta_data_graph)
{
if(_augmentation_metanode) output_meta_data->resize(_user_batch_size);
if(_is_random_bbox_crop)
{
_meta_data_graph->update_random_bbox_meta_data(_augmented_meta_data, output_meta_data, decode_image_info, crop_image_info);
Expand Down

0 comments on commit 2723b33

Please sign in to comment.