MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / COCODataReader

Method COCODataReader

oneflow/user/data/coco_data_reader.cpp:29–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27namespace data {
28
29COCODataReader::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
58COCODataReader::~COCODataReader() {
59 if (auto* pool = TensorBufferPool::TryGet()) { pool->DecreasePoolSizeByBase(batch_size_); }

Callers

nothing calls this directly

Calls 6

elem_cntMethod · 0.45
shapeMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected