| 27 | namespace data { |
| 28 | |
| 29 | COCODataReader::COCODataReader(user_op::KernelInitContext* ctx) : DataReader<COCOImage>(ctx) { |
| 30 | batch_size_ = ctx->TensorDesc4ArgNameAndIndex("image", 0)->shape().elem_cnt(); |
| 31 | if (auto* pool = TensorBufferPool::TryGet()) { pool->IncreasePoolSizeByBase(batch_size_); } |
| 32 | |
| 33 | std::shared_ptr<const COCOMeta> meta(new COCOMeta( |
| 34 | ctx->Attr<int64_t>("session_id"), ctx->Attr<std::string>("annotation_file"), |
| 35 | ctx->Attr<std::string>("image_dir"), ctx->Attr<bool>("remove_images_without_annotations"))); |
| 36 | std::unique_ptr<RandomAccessDataset<COCOImage>> coco_dataset_ptr(new COCODataset(ctx, meta)); |
| 37 | |
| 38 | size_t world_size = 1; |
| 39 | int64_t rank = 0; |
| 40 | CHECK_JUST(InitDataSourceDistributedInfo(ctx, world_size, rank)); |
| 41 | loader_.reset(new DistributedTrainingDataset<COCOImage>( |
| 42 | world_size, rank, ctx->Attr<bool>("stride_partition"), ctx->Attr<bool>("shuffle_after_epoch"), |
| 43 | ctx->Attr<int64_t>("random_seed"), std::move(coco_dataset_ptr))); |
| 44 | |
| 45 | if (ctx->Attr<bool>("group_by_ratio")) { |
| 46 | auto GetGroupId = [](const COCOImage& sample) { |
| 47 | return static_cast<int64_t>(sample.height / sample.width); |
| 48 | }; |
| 49 | loader_.reset(new GroupBatchDataset<COCOImage>(batch_size_, GetGroupId, std::move(loader_))); |
| 50 | } else { |
| 51 | loader_.reset(new BatchDataset<COCOImage>(batch_size_, std::move(loader_))); |
| 52 | } |
| 53 | |
| 54 | parser_.reset(new COCOParser(meta)); |
| 55 | StartLoadThread(); |
| 56 | } |
| 57 | |
| 58 | COCODataReader::~COCODataReader() { |
| 59 | if (auto* pool = TensorBufferPool::TryGet()) { pool->DecreasePoolSizeByBase(batch_size_); } |
nothing calls this directly
no test coverage detected