// // DataLoader.hpp // MNN // // Created by MNN on 2019/11/15. // Copyright © 2018, Alibaba Group Holding Limited // #ifndef DataLoader_hpp #define DataLoader_hpp #include #include #include #include "BlockingQueue.hpp" #include "DataLoaderConfig.hpp" #include "Example.hpp" namespace MNN { namespace Train { class BatchDataset; class Sampler; class BatchTransform; class MNN_PUBLIC DataLoader { public: DataLoader(std::shared_ptr dataset, std::shared_ptr sampler, std::shared_ptr config); /* When use Windows v141 toolset to compile class having vector of non-copyable element (std::thread, for example), copy constructor (or assignment operator) must be deleted explicity, otherwise compile will failed. */ DataLoader(const DataLoader&) = delete; DataLoader& operator = (const DataLoader&) = delete; virtual ~DataLoader() { join(); }; void prefetch(size_t nJobs); void workerThread(); void join(); std::vector next(); void reset(); void clean(); size_t iterNumber() const; size_t size() const; static DataLoader* makeDataLoader(std::shared_ptr dataset, const int batchSize, const bool stack = true, const bool shuffle = true, const int numWorkers = 0); static DataLoader* makeDataLoader(std::shared_ptr dataset, std::vector> transforms, const int batchSize, const bool shuffle = true, const int numWorkers = 0); private: struct Job { std::vector job; bool quit = false; }; std::shared_ptr mDataset; std::shared_ptr mSampler; std::shared_ptr mConfig; std::shared_ptr> mJobs; std::shared_ptr>> mDataQueue; std::vector mWorkers; }; } // namespace Train } // namespace MNN #endif // DataLoader_hpp