Apollo 11.0
自动驾驶开放平台
apollo::perception::inference::BatchStream类 参考

#include <batch_stream.h>

apollo::perception::inference::BatchStream 的协作图:

Public 成员函数

 BatchStream (int batchSize, int maxBatches, std::string data_path)
 
 BatchStream ()
 
void reset (int firstBatch)
 
bool next ()
 
void skip (int skipCount)
 
float * getBatch ()
 
int getBatchesRead () const
 
int getBatchSize () const
 
nvinfer1::DimsNCHW getDims () const
 

详细描述

在文件 batch_stream.h 第 36 行定义.

构造及析构函数说明

◆ BatchStream() [1/2]

apollo::perception::inference::BatchStream::BatchStream ( int  batchSize,
int  maxBatches,
std::string  data_path 
)

在文件 batch_stream.cc 第 35 行定义.

36 : mBatchSize(batchSize), mMaxBatches(maxBatches), mPath(dataPath) {
37 FILE *file = fopen((mPath + "Batch0").c_str(), "rb");
38 if (file != nullptr) {
39 int d[4];
40 int fs = static_cast<int>(fread(d, sizeof(int), 4, file));
41 CHECK_EQ(fs, 4);
42 mDims = nvinfer1::DimsNCHW{d[0], d[1], d[2], d[3]};
43 fclose(file);
44 mImageSize = mDims.c() * mDims.h() * mDims.w();
45 mBatch.resize(mBatchSize * mImageSize, 0);
46 mFileBatch.resize(mDims.n() * mImageSize, 0);
47 reset(0);
48 }
49}
int32_t & h()
Definition rt_legacy.h:46
int32_t & n()
Definition rt_legacy.h:30
int32_t & c()
Definition rt_legacy.h:38
int32_t & w()
Definition rt_legacy.h:54

◆ BatchStream() [2/2]

apollo::perception::inference::BatchStream::BatchStream ( )

在文件 batch_stream.cc 第 51 行定义.

51: mPath("") {}

成员函数说明

◆ getBatch()

float * apollo::perception::inference::BatchStream::getBatch ( )
inline

在文件 batch_stream.h 第 50 行定义.

50{ return &mBatch[0]; }

◆ getBatchesRead()

int apollo::perception::inference::BatchStream::getBatchesRead ( ) const
inline

在文件 batch_stream.h 第 51 行定义.

51{ return mBatchCount; }

◆ getBatchSize()

int apollo::perception::inference::BatchStream::getBatchSize ( ) const
inline

在文件 batch_stream.h 第 52 行定义.

52{ return mBatchSize; }

◆ getDims()

nvinfer1::DimsNCHW apollo::perception::inference::BatchStream::getDims ( ) const
inline

在文件 batch_stream.h 第 53 行定义.

53{ return mDims; }

◆ next()

bool apollo::perception::inference::BatchStream::next ( )

在文件 batch_stream.cc 第 62 行定义.

62 {
63 if (mBatchCount == mMaxBatches) {
64 return false;
65 }
66
67 for (int csize = 1, batchPos = 0; batchPos < mBatchSize;
68 batchPos += csize, mFileBatchPos += csize) {
69 CHECK_GT(mFileBatchPos, 0);
70 CHECK_LE(mFileBatchPos, mDims.n());
71 // mMaxBatches > number of batches in the files
72 if (mFileBatchPos == mDims.n() && !update()) {
73 return false;
74 }
75
76 // copy the smaller of: elements left to fulfill the request,
77 // or elements left in the file buffer.
78 csize = std::min(mBatchSize - batchPos, mDims.n() - mFileBatchPos);
79 std::copy_n(getFileBatch() + mFileBatchPos * mImageSize, csize * mImageSize,
80 getBatch() + batchPos * mImageSize);
81 }
82 mBatchCount++;
83 return true;
84}

◆ reset()

void apollo::perception::inference::BatchStream::reset ( int  firstBatch)

在文件 batch_stream.cc 第 53 行定义.

53 {
54 if (mPath != "") {
55 mBatchCount = 0;
56 mFileCount = 0;
57 mFileBatchPos = mDims.n();
58 skip(firstBatch);
59 }
60}

◆ skip()

void apollo::perception::inference::BatchStream::skip ( int  skipCount)

在文件 batch_stream.cc 第 86 行定义.

86 {
87 if (mBatchSize >= mDims.n() && mBatchSize % mDims.n() == 0 &&
88 mFileBatchPos == mDims.n()) {
89 mFileCount += skipCount * mBatchSize / mDims.n();
90 return;
91 }
92
93 int x = mBatchCount;
94 for (int i = 0; i < skipCount; ++i) {
95 next();
96 }
97 mBatchCount = x;
98}

该类的文档由以下文件生成: