MCPcopy Create free account
hub / github.com/apple/coremltools / ModelPackageImpl

Method ModelPackageImpl

modelpackage/src/ModelPackage.cpp:192–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190#pragma mark ModelPackageImpl
191
192ModelPackageImpl::ModelPackageImpl(const std::filesystem::path& path, bool createIfNecessary, bool readOnly)
193: m_packagePath(path),
194 m_manifestPath(path / kModelPackageManifestFileName),
195 m_packageDataDirPath(path / kModelPackageDataDir),
196 m_manifest(nullptr),
197 m_readOnly(readOnly)
198{
199 if (std::filesystem::exists(m_packagePath)) {
200 if (std::filesystem::exists(m_manifestPath)) {
201 std::ifstream manifestStream(m_manifestPath, std::ios::binary);
202 m_manifest = std::make_unique<JsonMap>(manifestStream);
203 manifestStream.close();
204 } else {
205 throw std::runtime_error("A valid manifest does not exist at path: " + m_manifestPath.string());
206 }
207 }
208 // Create the package structure at specified path
209 else if (createIfNecessary) {
210 if (false == create_directory(m_packagePath)) {
211 throw std::runtime_error("Failed to create model package at path: " + m_packagePath.string());
212 }
213
214 if (false == create_directory(m_packageDataDirPath)) {
215 throw std::runtime_error("Failed to create data directory at path: " + m_packageDataDirPath.string());
216 }
217
218 m_manifest = std::make_unique<JsonMap>();
219 std::stringstream ss;
220 ss << kModelPackageFileFormatMajorVersion << "." << kModelPackageFileFormatMinorVersion << "." << kModelPackageFileFormatPatchVersion;
221 m_manifest->setString(kModelPackageFileFormatVersionKey, ss.str());
222 }
223 // Error out since package does not exist
224 else {
225 throw std::runtime_error("Failed to open model package at path: " + m_packagePath.string());
226 }
227
228 validate();
229}
230
231ModelPackageImpl::~ModelPackageImpl()
232{

Callers

nothing calls this directly

Calls 5

validateFunction · 0.85
closeMethod · 0.45
stringMethod · 0.45
setStringMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected