// // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information. // #pragma once #include #include "Config.h" #ifdef USE_ZIP #include #include #include #include "ConcStack.h" #endif namespace CNTK { using MultiMap = std::map>; class ByteReader { public: ByteReader() = default; virtual ~ByteReader() = default; virtual void Register(const MultiMap& sequences) = 0; virtual cv::Mat Read(size_t seqId, const std::string& path, bool grayscale) = 0; DISABLE_COPY_AND_MOVE(ByteReader); }; class FileByteReader : public ByteReader { public: FileByteReader(const std::string& expandDirectory) : m_expandDirectory(expandDirectory) {} void Register(const MultiMap&) override {} cv::Mat Read(size_t seqId, const std::string& path, bool grayscale) override; std::string m_expandDirectory; }; #ifdef USE_ZIP class ZipByteReader : public ByteReader { public: ZipByteReader(const std::string& zipPath); void Register(const std::map>& sequences) override; cv::Mat Read(size_t seqId, const std::string& path, bool grayscale) override; private: using ZipPtr = std::unique_ptr; ZipPtr OpenZip(); std::string m_zipPath; Microsoft::MSR::CNTK::conc_stack m_zips; std::unordered_map> m_seqIdToIndex; Microsoft::MSR::CNTK::conc_stack> m_workspace; }; #endif }