From fbd9e3d402b4db4604ce6d497b966ebe6353b469 Mon Sep 17 00:00:00 2001 From: xiefangqi Date: Wed, 15 Jul 2020 16:36:15 +0800 Subject: [PATCH] vocdataset output multi-columns --- .../engine/datasetops/source/coco_op.cc | 2 +- .../engine/datasetops/source/voc_op.cc | 86 ++++++++++++------ .../dataset/engine/datasetops/source/voc_op.h | 9 +- mindspore/dataset/engine/datasets.py | 12 +-- .../bounding_box_augment_crop_c_result.npz | Bin 1654 -> 1648 bytes ...bounding_box_augment_rotation_c_result.npz | Bin 1654 -> 1648 bytes ...unding_box_augment_valid_edge_c_result.npz | Bin 1654 -> 1648 bytes ...nding_box_augment_valid_ratio_c_result.npz | Bin 1654 -> 1648 bytes .../random_crop_with_bbox_01_c_result.npz | Bin 1654 -> 1648 bytes ..._horizontal_flip_with_bbox_01_c_result.npz | Bin 1654 -> 1648 bytes ...om_resize_with_bbox_op_01_c_voc_result.npz | Bin 1654 -> 1648 bytes ...dom_resized_crop_with_bbox_01_c_result.npz | Bin 1654 -> 1648 bytes ...om_vertical_flip_with_bbox_01_c_result.npz | Bin 1654 -> 1648 bytes .../resize_with_bbox_op_01_c_voc_result.npz | Bin 1654 -> 1648 bytes .../dataset/test_bounding_box_augment.py | 49 +++++----- tests/ut/python/dataset/test_datasets_coco.py | 13 +++ tests/ut/python/dataset/test_datasets_voc.py | 17 ++-- .../test_random_crop_and_resize_with_bbox.py | 36 ++++---- .../dataset/test_random_crop_with_bbox.py | 40 ++++---- .../test_random_horizontal_flip_with_bbox.py | 40 ++++---- .../dataset/test_random_resize_with_bbox.py | 18 ++-- .../test_random_vertical_flip_with_bbox.py | 30 +++--- .../python/dataset/test_resize_with_bbox.py | 18 ++-- tests/ut/python/dataset/util.py | 24 ++--- 24 files changed, 215 insertions(+), 179 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/coco_op.cc b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/coco_op.cc index daef2f284bb..da298dabf2b 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/coco_op.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/coco_op.cc @@ -215,7 +215,7 @@ Status CocoOp::LoadTensorRow(row_id_type row_id, const std::string &image_id, Te auto itr = coordinate_map_.find(image_id); if (itr == coordinate_map_.end()) RETURN_STATUS_UNEXPECTED("Invalid image_id found :" + image_id); - std::string kImageFile = image_folder_path_ + image_id; + std::string kImageFile = image_folder_path_ + std::string("/") + image_id; RETURN_IF_NOT_OK(ReadImageToTensor(kImageFile, data_schema_->column(0), &image)); auto bboxRow = itr->second; diff --git a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/voc_op.cc b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/voc_op.cc index e90d423ef42..fcc529b6bd9 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/voc_op.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/voc_op.cc @@ -34,7 +34,10 @@ namespace mindspore { namespace dataset { const char kColumnImage[] = "image"; const char kColumnTarget[] = "target"; -const char kColumnAnnotation[] = "annotation"; +const char kColumnBbox[] = "bbox"; +const char kColumnLabel[] = "label"; +const char kColumnDifficult[] = "difficult"; +const char kColumnTruncate[] = "truncate"; const char kJPEGImagesFolder[] = "/JPEGImages/"; const char kSegmentationClassFolder[] = "/SegmentationClass/"; const char kAnnotationsFolder[] = "/Annotations/"; @@ -70,7 +73,13 @@ Status VOCOp::Builder::Build(std::shared_ptr *ptr) { RETURN_IF_NOT_OK(builder_schema_->AddColumn( ColDescriptor(std::string(kColumnImage), DataType(DataType::DE_UINT8), TensorImpl::kFlexible, 1))); RETURN_IF_NOT_OK(builder_schema_->AddColumn( - ColDescriptor(std::string(kColumnAnnotation), DataType(DataType::DE_FLOAT32), TensorImpl::kFlexible, 1))); + ColDescriptor(std::string(kColumnBbox), DataType(DataType::DE_FLOAT32), TensorImpl::kFlexible, 1))); + RETURN_IF_NOT_OK(builder_schema_->AddColumn( + ColDescriptor(std::string(kColumnLabel), DataType(DataType::DE_UINT32), TensorImpl::kFlexible, 1))); + RETURN_IF_NOT_OK(builder_schema_->AddColumn( + ColDescriptor(std::string(kColumnDifficult), DataType(DataType::DE_UINT32), TensorImpl::kFlexible, 1))); + RETURN_IF_NOT_OK(builder_schema_->AddColumn( + ColDescriptor(std::string(kColumnTruncate), DataType(DataType::DE_UINT32), TensorImpl::kFlexible, 1))); } *ptr = std::make_shared(builder_task_type_, builder_task_mode_, builder_dir_, builder_labels_to_read_, builder_num_workers_, builder_rows_per_buffer_, builder_op_connector_size_, @@ -190,14 +199,16 @@ Status VOCOp::LoadTensorRow(row_id_type row_id, const std::string &image_id, Ten RETURN_IF_NOT_OK(ReadImageToTensor(kTargetFile, data_schema_->column(1), &target)); (*trow) = TensorRow(row_id, {std::move(image), std::move(target)}); } else if (task_type_ == TaskType::Detection) { - std::shared_ptr image, annotation; + std::shared_ptr image; + TensorRow annotation; const std::string kImageFile = folder_path_ + std::string(kJPEGImagesFolder) + image_id + std::string(kImageExtension); const std::string kAnnotationFile = folder_path_ + std::string(kAnnotationsFolder) + image_id + std::string(kAnnotationExtension); RETURN_IF_NOT_OK(ReadImageToTensor(kImageFile, data_schema_->column(0), &image)); - RETURN_IF_NOT_OK(ReadAnnotationToTensor(kAnnotationFile, data_schema_->column(1), &annotation)); - (*trow) = TensorRow(row_id, {std::move(image), std::move(annotation)}); + RETURN_IF_NOT_OK(ReadAnnotationToTensor(kAnnotationFile, &annotation)); + trow->push_back(std::move(image)); + trow->insert(trow->end(), annotation.begin(), annotation.end()); } return Status::OK(); } @@ -271,7 +282,7 @@ Status VOCOp::ParseAnnotationIds() { const std::string kAnnotationName = folder_path_ + std::string(kAnnotationsFolder) + id + std::string(kAnnotationExtension); RETURN_IF_NOT_OK(ParseAnnotationBbox(kAnnotationName)); - if (label_map_.find(kAnnotationName) != label_map_.end()) { + if (annotation_map_.find(kAnnotationName) != annotation_map_.end()) { new_image_ids.push_back(id); } } @@ -293,7 +304,7 @@ Status VOCOp::ParseAnnotationBbox(const std::string &path) { if (!Path(path).Exists()) { RETURN_STATUS_UNEXPECTED("File is not found : " + path); } - Bbox bbox; + Annotation annotation; XMLDocument doc; XMLError e = doc.LoadFile(common::SafeCStr(path)); if (e != XMLError::XML_SUCCESS) { @@ -332,13 +343,13 @@ Status VOCOp::ParseAnnotationBbox(const std::string &path) { } if (label_name != "" && (class_index_.empty() || class_index_.find(label_name) != class_index_.end()) && xmin > 0 && ymin > 0 && xmax > xmin && ymax > ymin) { - std::vector bbox_list = {xmin, ymin, xmax - xmin, ymax - ymin, truncated, difficult}; - bbox.emplace_back(std::make_pair(label_name, bbox_list)); + std::vector bbox_list = {xmin, ymin, xmax - xmin, ymax - ymin, difficult, truncated}; + annotation.emplace_back(std::make_pair(label_name, bbox_list)); label_index_[label_name] = 0; } object = object->NextSiblingElement("object"); } - if (bbox.size() > 0) label_map_[path] = bbox; + if (annotation.size() > 0) annotation_map_[path] = annotation; return Status::OK(); } @@ -374,31 +385,46 @@ Status VOCOp::ReadImageToTensor(const std::string &path, const ColDescriptor &co return Status::OK(); } -Status VOCOp::ReadAnnotationToTensor(const std::string &path, const ColDescriptor &col, - std::shared_ptr *tensor) { - Bbox bbox_info = label_map_[path]; - std::vector bbox_row; - dsize_t bbox_column_num = 0, bbox_num = 0; - for (auto box : bbox_info) { - if (label_index_.find(box.first) != label_index_.end()) { - std::vector bbox; - bbox.insert(bbox.end(), box.second.begin(), box.second.end()); - if (class_index_.find(box.first) != class_index_.end()) { - bbox.push_back(static_cast(class_index_[box.first])); +// When task is Detection, user can get bbox data with four columns: +// column ["bbox"] with datatype=float32 +// column ["label"] with datatype=uint32 +// column ["difficult"] with datatype=uint32 +// column ["truncate"] with datatype=uint32 +Status VOCOp::ReadAnnotationToTensor(const std::string &path, TensorRow *row) { + Annotation annotation = annotation_map_[path]; + std::shared_ptr bbox, label, difficult, truncate; + std::vector bbox_data; + std::vector label_data, difficult_data, truncate_data; + dsize_t bbox_num = 0; + for (auto item : annotation) { + if (label_index_.find(item.first) != label_index_.end()) { + if (class_index_.find(item.first) != class_index_.end()) { + label_data.push_back(static_cast(class_index_[item.first])); } else { - bbox.push_back(static_cast(label_index_[box.first])); - } - bbox_row.insert(bbox_row.end(), bbox.begin(), bbox.end()); - if (bbox_column_num == 0) { - bbox_column_num = static_cast(bbox.size()); + label_data.push_back(static_cast(label_index_[item.first])); } + CHECK_FAIL_RETURN_UNEXPECTED(item.second.size() == 6, "annotation only support 6 parameters."); + + std::vector tmp_bbox = {(item.second)[0], (item.second)[1], (item.second)[2], (item.second)[3]}; + bbox_data.insert(bbox_data.end(), tmp_bbox.begin(), tmp_bbox.end()); + difficult_data.push_back(static_cast((item.second)[4])); + truncate_data.push_back(static_cast((item.second)[5])); bbox_num++; } } - - std::vector bbox_dim = {bbox_num, bbox_column_num}; - RETURN_IF_NOT_OK(Tensor::CreateTensor(tensor, col.tensorImpl(), TensorShape(bbox_dim), col.type(), - reinterpret_cast(&bbox_row[0]))); + RETURN_IF_NOT_OK(Tensor::CreateTensor(&bbox, data_schema_->column(1).tensorImpl(), TensorShape({bbox_num, 4}), + data_schema_->column(1).type(), + reinterpret_cast(&bbox_data[0]))); + RETURN_IF_NOT_OK(Tensor::CreateTensor(&label, data_schema_->column(2).tensorImpl(), TensorShape({bbox_num, 1}), + data_schema_->column(2).type(), + reinterpret_cast(&label_data[0]))); + RETURN_IF_NOT_OK(Tensor::CreateTensor(&difficult, data_schema_->column(3).tensorImpl(), TensorShape({bbox_num, 1}), + data_schema_->column(3).type(), + reinterpret_cast(&difficult_data[0]))); + RETURN_IF_NOT_OK(Tensor::CreateTensor(&truncate, data_schema_->column(4).tensorImpl(), TensorShape({bbox_num, 1}), + data_schema_->column(4).type(), + reinterpret_cast(&truncate_data[0]))); + (*row) = TensorRow({std::move(bbox), std::move(label), std::move(difficult), std::move(truncate)}); return Status::OK(); } diff --git a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/voc_op.h b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/voc_op.h index 725e9c7b841..ef5578f4670 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/voc_op.h +++ b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/voc_op.h @@ -40,7 +40,7 @@ namespace dataset { template class Queue; -using Bbox = std::vector>>; +using Annotation = std::vector>>; class VOCOp : public ParallelOp, public RandomAccessOp { public: @@ -234,10 +234,9 @@ class VOCOp : public ParallelOp, public RandomAccessOp { Status ReadImageToTensor(const std::string &path, const ColDescriptor &col, std::shared_ptr *tensor); // @param const std::string &path - path to the image file - // @param const ColDescriptor &col - contains tensor implementation and datatype - // @param std::shared_ptr tensor - return + // @param TensorRow *row - return // @return Status - The error code return - Status ReadAnnotationToTensor(const std::string &path, const ColDescriptor &col, std::shared_ptr *tensor); + Status ReadAnnotationToTensor(const std::string &path, TensorRow *row); // @param const std::vector &keys - keys in ioblock // @param std::unique_ptr db @@ -287,7 +286,7 @@ class VOCOp : public ParallelOp, public RandomAccessOp { QueueList> io_block_queues_; std::map class_index_; std::map label_index_; - std::map label_map_; + std::map annotation_map_; }; } // namespace dataset } // namespace mindspore diff --git a/mindspore/dataset/engine/datasets.py b/mindspore/dataset/engine/datasets.py index 35f3bc497fa..4f7a5adf547 100644 --- a/mindspore/dataset/engine/datasets.py +++ b/mindspore/dataset/engine/datasets.py @@ -4122,13 +4122,11 @@ class VOCDataset(MappableDataset): """ A source dataset for reading and parsing VOC dataset. - The generated dataset has two columns : - task='Detection' : ['image', 'annotation']; - task='Segmentation' : ['image', 'target']. - The shape of both column 'image' and 'target' is [image_size] if decode flag is False, or [H, W, C] - otherwise. - The type of both tensor 'image' and 'target' is uint8. - The type of tensor 'annotation' is uint32. + The generated dataset has multi-columns : + + - task='Detection', column: [['image', dtype=uint8], ['bbox', dtype=float32], ['label', dtype=uint32], + ['difficult', dtype=uint32], ['truncate', dtype=uint32]]. + - task='Segmentation', column: [['image', dtype=uint8], ['target',dtype=uint8]]. This dataset can take in a sampler. sampler and shuffle are mutually exclusive. Table below shows what input args are allowed and their expected behavior. diff --git a/tests/ut/data/dataset/golden/bounding_box_augment_crop_c_result.npz b/tests/ut/data/dataset/golden/bounding_box_augment_crop_c_result.npz index 14ddc166e26c0f6966aec4270124a8d826991dbb..92a3970641f7dc8ca33de6cd17038c2d916e7301 100644 GIT binary patch delta 326 zcmeyy^MS`Cz?+#xgaHB+8Jx;D-+aN!zyQLW3?dAPMMd!jdU*wvj0^%`L6E{18%^dh zbFcteNlEz?lOHgv2z+Aqjh%bmrIBxQf6ns%?R}F)Sg;6s00qsv{1v}P$_C8bx}%-> zYFp*x8lWJ{#;;nZ?n*~jrd}`apC-#Pc>_?;lOy75bnKxgjOREWbxOosn*0PPIPu3+ zr%=K0TMXV8A1_F0=9?_Rsv?l#!fjb#wCJ6Dd99Pci=39pK0v|l(y}P8YfEn$o;d9rFu1~*LTs<+Rb@H~Z$?JfE72Y#yLmpSzd zYFp*x8lWJ{#;;nZ?n*~jrd}`apC-#Pc>_?;lOy75bnKxgjOREWbxOosn*0PPIPu3+ zr%=K0TMXV8A1_F0=9?_Rsv?l#!fjb#wCJ6Dd99Pci=39pK0v|l(y}P8YfEn$?p28~1SOWsXh1r&T}%kXRVo2ACy-||1n<)42# z`5sWP{g6Z4)rf5+!LD5sKkSgvnk>YsB2dB@TwguUWFp(upA&uMSgj_z0R>&va(1^j zg{kV?)Oz|~S}JvN6;SZUh0k3xx<370arMNM*2&wtCa(huR(Q{-4S8H;^Cj3@cB=Um zp2?3`Rm=n>0vomWD$d$g^m5u?y{(mnGfN6*C8eg86wXf43-D%S5@E&?c$00|^w>1n HKw$*{XZneA diff --git a/tests/ut/data/dataset/golden/bounding_box_augment_valid_edge_c_result.npz b/tests/ut/data/dataset/golden/bounding_box_augment_valid_edge_c_result.npz index a72643457b8184ebb37b60dbf951c9f57082794b..a46d24f5dc9a762d3fba9cfd86f8bf3ad9bfa9aa 100644 GIT binary patch delta 96 zcmeyy^MS`Cz?+#xgaHB+8E$2L-Ti`lkbR delta 102 zcmeys^Nq(Oz?+#xgaHB+8N_=Iv%X_xU;trG1`&qDqM~>My}W`-Mg{?}AV}f6jVAM$ k`M7|r#Js%xlEjkC{JhP#m?N1u;o2wLu<5aBvVl|s0IRVW6aWAK diff --git a/tests/ut/data/dataset/golden/bounding_box_augment_valid_ratio_c_result.npz b/tests/ut/data/dataset/golden/bounding_box_augment_valid_ratio_c_result.npz index 9a6ae1cb9904e5089327aa62882aa6b48d0b713d..efd2abe4ed1d99bb3c0bd986f0026af5fb4d9327 100644 GIT binary patch delta 326 zcmeyy^MS`Cz?+#xgaHB+87v>E@x5SWU;trG1`&qDqM~>My}W`-Mg{?}AV}ehjVAM$ zIaq+Kq@?_c$q$%S1U|9*#?C$O(#W^DKWF*>_P)s?ELa3RfP&^-{)*otWdmkz-ObA0Ee7w4j~Apg^G%juRT0Q=;kGO=TJ%o7yw*wJMNZ3PAE01&X<3xlwWT)=a(6B1 zeZk=~xdABnZ^GQIKJEHX^7dO8F3#l4o4f@mcvnXK)&^&f&+R&SQx*wHa!!5$6ujbn kDK2oyhy88x&gaYydbUiKVUy*A2hU_DHa#|FHc)5)05kJ;b^rhX delta 356 zcmeys^Nq(Oz?+#xgaHB+8A?@U)!(r)Fn};8g9t-nQBk~sUS2^ZBZB}~5Tx+kMw5BW zd|W_QVqRW;Nn%N6e%|C;%qjv$O80$tdwcX%#;Wk=HT5r!Oy*<3BIpDZG+8G7FXQGe zecubQ6ZW1FOPE{+6incF`7NzPz?j9DLF3T-l6R9=0Ro;d9rFu1~*LTs<+Rb@H~Z$?JfE72Y#yLmpSzd994TP{`$i^(-W!P577LhsYLyslemT`(v=d~5OspkTo3eUh#F z?w~qn{WkA8q^Ltu%KNYeuK5wx`<&Z$u*RGn z!AAifnT;jWY*(x6sY~8;wx0ZmRmDtb;;R(BDg}qrAz3_=8P0AgoLN#hD=9U#q;PhU XUVt|vlL#}Gz?*EtrpKnq1_~M diff --git a/tests/ut/data/dataset/golden/random_horizontal_flip_with_bbox_01_c_result.npz b/tests/ut/data/dataset/golden/random_horizontal_flip_with_bbox_01_c_result.npz index 416223ff4de858af0916906d6beb4a88141f232b..b256b3b8f72156062acacca05e345cdf8807afd2 100644 GIT binary patch delta 326 zcmeyy^MS`Cz?+#xgaHB+8RXPWPQGAeU;trG1`&qDqM~>My}W`-Mg{?}AV}ehjVAM$ zIaq+Kq@?_c$q$%S1U|9*#?C$O(#W^DKWF*>_P)s?ELa3RfPx-IZ>5+dr%E54G=Hw?p!PeH_OByYck;o?lryvbXDf_G)qZ*6e)_}s3OH)WBKB!TvVSd!zRlK51z?RY+M1ZEl!*>gGqk$wI6u0`s?Az4`EnnYVkwlx_0yAKy=Q0}8sT6 z3RBg&srB@~v{dTkDxlzx3!l4Ybbb20;_8Vht&_KPO{RnB zJd+=>s+c9l2;6_P?q2o+uFQK!FRMN+oLN#hD=9U#q;PhUUVt|vlL#}Gz?*EtrpKnq H1_~Rj$XplBUVF$l*0Ch)o94K^Nm{UVYSXBf(;?1)*`dP0&AphcDSx+tNWFMg5)WqwbBABaAcPDL; zUgr?QJ-GoWm^M{bbiOL2t3&#&`zCJz3d$+IYB>}0@l#LQlc&~IUvnnE01ApJ kDst_-_wUF2^hB6Pq5JG8-r~0BtvV>Hq)$ delta 356 zcmeys^Nq(Oz?+#xgaHB+8GZ)re*KP>fdPa$8AKQoi;Ch6^zsTS85sn?f*^(OHk!<1 z=Hmjg67%x%OA<>m^YbR(Vpb9Oe?#!~J(hgVGO0kho6lWZCiAgi5p)6yw#bUOd%GQG zt-RTv^zKl5|Ku{DAiwV2U6ri0YwgrxL|*z=3r}7J6l7ZG=x86c@0^#;mt)122`4At z0}3*%;bTp`7I)#1gD^|O%v7z(LaZtRD)K>V{_VN3@$|FYue04vnkTyf1$BRG6wRtN zxGN^wvv+BHzwhKKpx}XMy}W`-Mg{?}AV}ehjVAM$ zIaq+Kq@?_c$q$%S1Ty2^WqF^fzvk|G`|-ug=e#D1uwW7N017U<*s(v)G)i^P!4s+T z9w^jJt^o?(+tX!oUg5~w^FKfSthn{x z6u$Q?ZqoNA^*o;Uc*okw609l$Ndk2m-ySgicyAqNc)n)mzsWv8!TdujC-%1|8a?AE zyFIgZn#1GMy}W`-Mg{?}AV}f6jVAM$ z`M7|r#Js%xlEjkC{JhDxm{kPInymO$HMbaEF*|xMZt;}N$$TtW1f76_XZ!A+R5~0V zA~G$|dU^ER?UT!Zf=#~`@J&6w!8&%|;xwJLJ!O+u0R`>(j?I?g)p*R`uVNmuamVz@ z_ke;zt#`u;vRB+pYqIqXTK>povJk6^z>FEHS5CNh%slXT#`(!ttgR-y0R`>0>{sn} z$~x4YwL@M=&ar!P6;RN>;nJyWJ86bbbyMoH6XXs~UI!F>zWK)S`~Kb>vyI<3pU$jv zn*4}W#mtxIxmEqnrC-h$me1HOSR3vJNa^!>x%?Hv=1Ci?&dH#v6Ad-k`X{Hwz2 z_0vVaT%6nh6#O?~?pB|6{U>?*EescDa^_9m0u9dWvJ;ygn=%_HGyp(4e%=58 delta 356 zcmeys^Nq(Oz?+#xgaHB+8BCdY6W_5iFn};8g9t-nQBk~sUS2^ZBZB}~5Tx+kMw5BW zd|W_QVqRW;Nn%N6e%|C;%qjv;LIf0ixP_ySRCHWxNXp(cnU4jFpc7DV@8V5Om)75C zn(>L%$gk+`mdRy6!Oe~{=LbHw5uGC?Fx%_!@+Fg30R64cS&Z|v7%M>)(4Jg>!)Ldl} zadA=j({~T&%gZmCTm=;Tap7~QWZYE=*NAzVGzi zZ(Wlgv8tGH&;D3{hdc4c^i|6)|9icarEq3R;jE<8)RMy4NqPa^j7%cTSORad4VxaD ICL1WM02q9TKmY&$ diff --git a/tests/ut/data/dataset/golden/resize_with_bbox_op_01_c_voc_result.npz b/tests/ut/data/dataset/golden/resize_with_bbox_op_01_c_voc_result.npz index ca648849377448302093cf0eb0cad7518bc8a0a9..71c6a36a998b2310cc378d63a1df3ce8e3d3d50f 100644 GIT binary patch delta 326 zcmeyy^MS`Cz?+#xgaHB+86H2o;`f4;fdPa$8AKQoi;Ch6^zsTS85sn?f*^%2Hk!<1 z=3oJ`l9KW(CO=?S5vadEN9MY4_S!?f85jPX(3>$?gawPB2T)L__Fd#L-+Q~mtv<*t zZ0Ze|Tmuv|zvFVjDI@OLl}mf}uJe_9Jb439u#P2R-!#YVP11s`8$X<3)|~tVD5$nO z^&PMC%T05l9)`S3erzT$i6v13|x;tr$ z^g4$a?#T^6!L+Hes*B!;RnO;EUmenK-8Xp)P*6_sRm+)}kDq$do;My}W`-Mg{?}AV}f6jVAM$ z`M7|r#Js%xlEjkC{JhDxm{kP+-w=F#k0qb8Oe#?B=5v>p$$TtW1f76_EwUo+-fo9k zD{uBEy*t$2Ke-Gj$gg{MS0!uhT06BEk(d6}!jo441)0`4I@(9=JLjeIuh(E=E-hALEYaPMYC!R z?uv=_>|Gk)?>o5)D0txJj~DuVceV;Q<p6lEPU@si`G}vy=1!ycwB9n6U)jWE(a;Hcd8A GSOEZX^?*MB diff --git a/tests/ut/python/dataset/test_bounding_box_augment.py b/tests/ut/python/dataset/test_bounding_box_augment.py index 8924af968c1..90bfae7bb85 100644 --- a/tests/ut/python/dataset/test_bounding_box_augment.py +++ b/tests/ut/python/dataset/test_bounding_box_augment.py @@ -49,9 +49,9 @@ def test_bounding_box_augment_with_rotation_op(plot_vis=False): test_op = c_vision.BoundingBoxAugment(c_vision.RandomRotation(90), 1) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) filename = "bounding_box_augment_rotation_c_result.npz" @@ -88,9 +88,9 @@ def test_bounding_box_augment_with_crop_op(plot_vis=False): test_op = c_vision.BoundingBoxAugment(c_vision.RandomCrop(50), 0.9) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) filename = "bounding_box_augment_crop_c_result.npz" @@ -126,10 +126,11 @@ def test_bounding_box_augment_valid_ratio_c(plot_vis=False): test_op = c_vision.BoundingBoxAugment(c_vision.RandomHorizontalFlip(1), 0.9) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], - operations=[test_op]) # Add column for "annotation" + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], + operations=[test_op]) # Add column for "bbox" + filename = "bounding_box_augment_valid_ratio_c_result.npz" save_and_check_md5(dataVoc2, filename, generate_golden=GENERATE_GOLDEN) @@ -193,20 +194,20 @@ def test_bounding_box_augment_valid_edge_c(plot_vis=False): test_op = c_vision.BoundingBoxAugment(c_vision.RandomHorizontalFlip(1), 1) # map to apply ops - # Add column for "annotation" - dataVoc1 = dataVoc1.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + # Add column for "bbox" + dataVoc1 = dataVoc1.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=lambda img, bbox: (img, np.array([[0, 0, img.shape[1], img.shape[0], 0, 0, 0]]).astype(np.float32))) - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=lambda img, bbox: (img, np.array([[0, 0, img.shape[1], img.shape[0], 0, 0, 0]]).astype(np.float32))) - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) filename = "bounding_box_augment_valid_edge_c_result.npz" save_and_check_md5(dataVoc2, filename, generate_golden=GENERATE_GOLDEN) @@ -237,10 +238,10 @@ def test_bounding_box_augment_invalid_ratio_c(): # ratio range is from 0 - 1 test_op = c_vision.BoundingBoxAugment(c_vision.RandomHorizontalFlip(1), 1.5) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], - operations=[test_op]) # Add column for "annotation" + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], + operations=[test_op]) # Add column for "bbox" except ValueError as error: logger.info("Got an exception in DE: {}".format(str(error))) assert "Input ratio is not within the required interval of (0.0 to 1.0)." in str(error) diff --git a/tests/ut/python/dataset/test_datasets_coco.py b/tests/ut/python/dataset/test_datasets_coco.py index f5bf7caa6c4..3060c3c090a 100644 --- a/tests/ut/python/dataset/test_datasets_coco.py +++ b/tests/ut/python/dataset/test_datasets_coco.py @@ -17,6 +17,7 @@ import mindspore.dataset as ds import mindspore.dataset.transforms.vision.c_transforms as vision DATA_DIR = "../data/dataset/testCOCO/train/" +DATA_DIR_2 = "../data/dataset/testCOCO/train" ANNOTATION_FILE = "../data/dataset/testCOCO/annotations/train.json" KEYPOINT_FILE = "../data/dataset/testCOCO/annotations/key_point.json" PANOPTIC_FILE = "../data/dataset/testCOCO/annotations/panoptic.json" @@ -202,6 +203,17 @@ def test_coco_case_2(): num_iter += 1 assert num_iter == 24 +def test_coco_case_3(): + data1 = ds.CocoDataset(DATA_DIR_2, annotation_file=ANNOTATION_FILE, task="Detection", decode=True) + resize_op = vision.Resize((224, 224)) + + data1 = data1.map(input_columns=["image"], operations=resize_op) + data1 = data1.repeat(4) + num_iter = 0 + for _ in data1.__iter__(): + num_iter += 1 + assert num_iter == 24 + def test_coco_case_exception(): try: data1 = ds.CocoDataset("path_not_exist/", annotation_file=ANNOTATION_FILE, task="Detection") @@ -271,4 +283,5 @@ if __name__ == '__main__': test_coco_case_0() test_coco_case_1() test_coco_case_2() + test_coco_case_3() test_coco_case_exception() diff --git a/tests/ut/python/dataset/test_datasets_voc.py b/tests/ut/python/dataset/test_datasets_voc.py index 37f4a8c1233..1978b7005f4 100644 --- a/tests/ut/python/dataset/test_datasets_voc.py +++ b/tests/ut/python/dataset/test_datasets_voc.py @@ -36,8 +36,8 @@ def test_voc_detection(): count = [0, 0, 0, 0, 0, 0] for item in data1.create_dict_iterator(): assert item["image"].shape[0] == IMAGE_SHAPE[num] - for bbox in item["annotation"]: - count[int(bbox[6])] += 1 + for label in item["label"]: + count[label[0]] += 1 num += 1 assert num == 9 assert count == [3, 2, 1, 2, 4, 3] @@ -54,9 +54,9 @@ def test_voc_class_index(): num = 0 count = [0, 0, 0, 0, 0, 0] for item in data1.create_dict_iterator(): - for bbox in item["annotation"]: - assert (int(bbox[6]) == 0 or int(bbox[6]) == 1 or int(bbox[6]) == 5) - count[int(bbox[6])] += 1 + for label in item["label"]: + count[label[0]] += 1 + assert label[0] in (0, 1, 5) num += 1 assert num == 6 assert count == [3, 2, 0, 0, 0, 3] @@ -72,10 +72,9 @@ def test_voc_get_class_indexing(): num = 0 count = [0, 0, 0, 0, 0, 0] for item in data1.create_dict_iterator(): - for bbox in item["annotation"]: - assert (int(bbox[6]) == 0 or int(bbox[6]) == 1 or int(bbox[6]) == 2 or int(bbox[6]) == 3 - or int(bbox[6]) == 4 or int(bbox[6]) == 5) - count[int(bbox[6])] += 1 + for label in item["label"]: + count[label[0]] += 1 + assert label[0] in (0, 1, 2, 3, 4, 5) num += 1 assert num == 9 assert count == [3, 2, 1, 2, 4, 3] diff --git a/tests/ut/python/dataset/test_random_crop_and_resize_with_bbox.py b/tests/ut/python/dataset/test_random_crop_and_resize_with_bbox.py index 599acc95609..026808e9dee 100644 --- a/tests/ut/python/dataset/test_random_crop_and_resize_with_bbox.py +++ b/tests/ut/python/dataset/test_random_crop_and_resize_with_bbox.py @@ -48,9 +48,9 @@ def test_random_resized_crop_with_bbox_op_c(plot_vis=False): test_op = c_vision.RandomResizedCropWithBBox((256, 512), (0.5, 0.5), (0.5, 0.5)) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) filename = "random_resized_crop_with_bbox_01_c_result.npz" @@ -114,15 +114,15 @@ def test_random_resized_crop_with_bbox_op_edge_c(plot_vis=False): test_op = c_vision.RandomResizedCropWithBBox((256, 512), (0.5, 0.5), (0.5, 0.5)) # maps to convert data into valid edge case data - dataVoc1 = dataVoc1.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc1 = dataVoc1.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[lambda img, bboxes: (img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(bboxes.dtype))]) # Test Op added to list of Operations here - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[lambda img, bboxes: (img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(bboxes.dtype)), test_op]) unaugSamp, augSamp = [], [] @@ -149,9 +149,9 @@ def test_random_resized_crop_with_bbox_op_invalid_c(): test_op = c_vision.RandomResizedCropWithBBox((256, 512), (1, 0.5), (0.5, 0.5)) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) for _ in dataVoc2.create_dict_iterator(): @@ -175,9 +175,9 @@ def test_random_resized_crop_with_bbox_op_invalid2_c(): test_op = c_vision.RandomResizedCropWithBBox((256, 512), (1, 1), (1, 0.5)) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) for _ in dataVoc2.create_dict_iterator(): @@ -206,9 +206,9 @@ def test_random_resized_crop_with_bbox_op_bad_c(): if __name__ == "__main__": - test_random_resized_crop_with_bbox_op_c(plot_vis=True) - test_random_resized_crop_with_bbox_op_coco_c(plot_vis=True) - test_random_resized_crop_with_bbox_op_edge_c(plot_vis=True) + test_random_resized_crop_with_bbox_op_c(plot_vis=False) + test_random_resized_crop_with_bbox_op_coco_c(plot_vis=False) + test_random_resized_crop_with_bbox_op_edge_c(plot_vis=False) test_random_resized_crop_with_bbox_op_invalid_c() test_random_resized_crop_with_bbox_op_invalid2_c() test_random_resized_crop_with_bbox_op_bad_c() diff --git a/tests/ut/python/dataset/test_random_crop_with_bbox.py b/tests/ut/python/dataset/test_random_crop_with_bbox.py index 69fb0d63209..00e9e9d0770 100644 --- a/tests/ut/python/dataset/test_random_crop_with_bbox.py +++ b/tests/ut/python/dataset/test_random_crop_with_bbox.py @@ -46,10 +46,10 @@ def test_random_crop_with_bbox_op_c(plot_vis=False): test_op = c_vision.RandomCropWithBBox([512, 512], [200, 200, 200, 200]) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], - operations=[test_op]) # Add column for "annotation" + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], + operations=[test_op]) # Add column for "bbox" unaugSamp, augSamp = [], [] @@ -108,9 +108,9 @@ def test_random_crop_with_bbox_op2_c(plot_vis=False): test_op = c_vision.RandomCropWithBBox(512, [200, 200, 200, 200], fill_value=(255, 255, 255)) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) filename = "random_crop_with_bbox_01_c_result.npz" @@ -145,9 +145,9 @@ def test_random_crop_with_bbox_op3_c(plot_vis=False): test_op = c_vision.RandomCropWithBBox(512, [200, 200, 200, 200], padding_mode=mode.Border.EDGE) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) unaugSamp, augSamp = [], [] @@ -175,16 +175,16 @@ def test_random_crop_with_bbox_op_edge_c(plot_vis=False): test_op = c_vision.RandomCropWithBBox(512, [200, 200, 200, 200], padding_mode=mode.Border.EDGE) # maps to convert data into valid edge case data - dataVoc1 = dataVoc1.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc1 = dataVoc1.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[lambda img, bboxes: ( img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(bboxes.dtype))]) # Test Op added to list of Operations here - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[lambda img, bboxes: ( img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(bboxes.dtype)), test_op]) @@ -212,10 +212,10 @@ def test_random_crop_with_bbox_op_invalid_c(): test_op = c_vision.RandomCropWithBBox([512, 512, 375]) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], - operations=[test_op]) # Add column for "annotation" + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], + operations=[test_op]) # Add column for "bbox" for _ in dataVoc2.create_dict_iterator(): break diff --git a/tests/ut/python/dataset/test_random_horizontal_flip_with_bbox.py b/tests/ut/python/dataset/test_random_horizontal_flip_with_bbox.py index 4fd51a7a035..64c8de1c5e1 100644 --- a/tests/ut/python/dataset/test_random_horizontal_flip_with_bbox.py +++ b/tests/ut/python/dataset/test_random_horizontal_flip_with_bbox.py @@ -45,9 +45,9 @@ def test_random_horizontal_flip_with_bbox_op_c(plot_vis=False): test_op = c_vision.RandomHorizontalFlipWithBBox(1) - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) unaugSamp, augSamp = [], [] @@ -111,9 +111,9 @@ def test_random_horizontal_flip_with_bbox_valid_rand_c(plot_vis=False): test_op = c_vision.RandomHorizontalFlipWithBBox(0.6) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) filename = "random_horizontal_flip_with_bbox_01_c_result.npz" @@ -146,20 +146,20 @@ def test_random_horizontal_flip_with_bbox_valid_edge_c(plot_vis=False): test_op = c_vision.RandomHorizontalFlipWithBBox(1) # map to apply ops - # Add column for "annotation" - dataVoc1 = dataVoc1.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + # Add column for "bbox" + dataVoc1 = dataVoc1.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=lambda img, bbox: (img, np.array([[0, 0, img.shape[1], img.shape[0], 0, 0, 0]]).astype(np.float32))) - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=lambda img, bbox: (img, np.array([[0, 0, img.shape[1], img.shape[0], 0, 0, 0]]).astype(np.float32))) - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) unaugSamp, augSamp = [], [] @@ -184,10 +184,10 @@ def test_random_horizontal_flip_with_bbox_invalid_prob_c(): # Note: Valid range of prob should be [0.0, 1.0] test_op = c_vision.RandomHorizontalFlipWithBBox(1.5) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], - operations=[test_op]) # Add column for "annotation" + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], + operations=[test_op]) # Add column for "bbox" except ValueError as error: logger.info("Got an exception in DE: {}".format(str(error))) assert "Input prob is not within the required interval of (0.0 to 1.0)." in str(error) diff --git a/tests/ut/python/dataset/test_random_resize_with_bbox.py b/tests/ut/python/dataset/test_random_resize_with_bbox.py index 94f9d12427b..439a6dc89d7 100644 --- a/tests/ut/python/dataset/test_random_resize_with_bbox.py +++ b/tests/ut/python/dataset/test_random_resize_with_bbox.py @@ -48,9 +48,9 @@ def test_random_resize_with_bbox_op_voc_c(plot_vis=False): test_op = c_vision.RandomResizeWithBBox(100) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) filename = "random_resize_with_bbox_op_01_c_voc_result.npz" @@ -129,15 +129,15 @@ def test_random_resize_with_bbox_op_edge_c(plot_vis=False): test_op = c_vision.RandomResizeWithBBox(500) # maps to convert data into valid edge case data - dataVoc1 = dataVoc1.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc1 = dataVoc1.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[lambda img, bboxes: ( img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(bboxes.dtype))]) - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[lambda img, bboxes: ( img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(bboxes.dtype)), test_op]) diff --git a/tests/ut/python/dataset/test_random_vertical_flip_with_bbox.py b/tests/ut/python/dataset/test_random_vertical_flip_with_bbox.py index 490dc3e419b..1447c31c765 100644 --- a/tests/ut/python/dataset/test_random_vertical_flip_with_bbox.py +++ b/tests/ut/python/dataset/test_random_vertical_flip_with_bbox.py @@ -46,9 +46,9 @@ def test_random_vertical_flip_with_bbox_op_c(plot_vis=False): test_op = c_vision.RandomVerticalFlipWithBBox(1) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) unaugSamp, augSamp = [], [] @@ -111,9 +111,9 @@ def test_random_vertical_flip_with_bbox_op_rand_c(plot_vis=False): test_op = c_vision.RandomVerticalFlipWithBBox(0.8) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) filename = "random_vertical_flip_with_bbox_01_c_result.npz" @@ -148,15 +148,15 @@ def test_random_vertical_flip_with_bbox_op_edge_c(plot_vis=False): test_op = c_vision.RandomVerticalFlipWithBBox(1) # maps to convert data into valid edge case data - dataVoc1 = dataVoc1.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc1 = dataVoc1.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[lambda img, bboxes: (img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(bboxes.dtype))]) # Test Op added to list of Operations here - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[lambda img, bboxes: (img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(bboxes.dtype)), test_op]) unaugSamp, augSamp = [], [] @@ -181,9 +181,9 @@ def test_random_vertical_flip_with_bbox_op_invalid_c(): test_op = c_vision.RandomVerticalFlipWithBBox(2) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) for _ in dataVoc2.create_dict_iterator(): diff --git a/tests/ut/python/dataset/test_resize_with_bbox.py b/tests/ut/python/dataset/test_resize_with_bbox.py index 1dfe0cf987d..af10ed9449c 100644 --- a/tests/ut/python/dataset/test_resize_with_bbox.py +++ b/tests/ut/python/dataset/test_resize_with_bbox.py @@ -48,9 +48,9 @@ def test_resize_with_bbox_op_voc_c(plot_vis=False): test_op = c_vision.ResizeWithBBox(100) # map to apply ops - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[test_op]) filename = "resize_with_bbox_op_01_c_voc_result.npz" @@ -119,15 +119,15 @@ def test_resize_with_bbox_op_edge_c(plot_vis=False): test_op = c_vision.ResizeWithBBox(500) # maps to convert data into valid edge case data - dataVoc1 = dataVoc1.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc1 = dataVoc1.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[lambda img, bboxes: ( img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(bboxes.dtype))]) - dataVoc2 = dataVoc2.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], + dataVoc2 = dataVoc2.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], operations=[lambda img, bboxes: ( img, np.array([[0, 0, img.shape[1], img.shape[0]]]).astype(bboxes.dtype)), test_op]) diff --git a/tests/ut/python/dataset/util.py b/tests/ut/python/dataset/util.py index 649f638b496..911e4c4d2c3 100644 --- a/tests/ut/python/dataset/util.py +++ b/tests/ut/python/dataset/util.py @@ -252,13 +252,13 @@ def visualize_image(image_original, image_de, mse=None, image_lib=None): plt.show() -def visualize_with_bounding_boxes(orig, aug, annot_name="annotation", plot_rows=3): +def visualize_with_bounding_boxes(orig, aug, annot_name="bbox", plot_rows=3): """ - Take a list of un-augmented and augmented images with "annotation" bounding boxes + Take a list of un-augmented and augmented images with "bbox" bounding boxes Plot images to compare test correct BBox augment functionality :param orig: list of original images and bboxes (without aug) :param aug: list of augmented images and bboxes - :param annot_name: the dict key for bboxes in data, e.g "bbox" (COCO) / "annotation" (VOC) + :param annot_name: the dict key for bboxes in data, e.g "bbox" (COCO) / "bbox" (VOC) :param plot_rows: number of rows on plot (rows = samples on one plot) :return: None """ @@ -337,7 +337,7 @@ def check_bad_bbox(data, test_op, invalid_bbox_type, expected_error): :return: None """ - def add_bad_annotation(img, bboxes, invalid_bbox_type_): + def add_bad_bbox(img, bboxes, invalid_bbox_type_): """ Used to generate erroneous bounding box examples on given img. :param img: image where the bounding boxes are. @@ -366,15 +366,15 @@ def check_bad_bbox(data, test_op, invalid_bbox_type, expected_error): try: # map to use selected invalid bounding box type - data = data.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], - operations=lambda img, bboxes: add_bad_annotation(img, bboxes, invalid_bbox_type)) + data = data.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], + operations=lambda img, bboxes: add_bad_bbox(img, bboxes, invalid_bbox_type)) # map to apply ops - data = data.map(input_columns=["image", "annotation"], - output_columns=["image", "annotation"], - columns_order=["image", "annotation"], - operations=[test_op]) # Add column for "annotation" + data = data.map(input_columns=["image", "bbox"], + output_columns=["image", "bbox"], + columns_order=["image", "bbox"], + operations=[test_op]) # Add column for "bbox" for _, _ in enumerate(data.create_dict_iterator()): break except RuntimeError as error: