| 318 | } |
| 319 | |
| 320 | Status GetAssetFileDefs(const MetaGraphDef& meta_graph_def, |
| 321 | std::vector<AssetFileDef>* asset_file_defs) { |
| 322 | // With SavedModel v2, we write asset file def into metagraph instead of |
| 323 | // collection, so read from metagraph first. |
| 324 | if (meta_graph_def.asset_file_def_size() > 0) { |
| 325 | for (const auto& asset : meta_graph_def.asset_file_def()) { |
| 326 | asset_file_defs->push_back(asset); |
| 327 | } |
| 328 | return Status::OK(); |
| 329 | } |
| 330 | // Fall back to read from collection to be backward compatible with v1. |
| 331 | const auto& collection_def_map = meta_graph_def.collection_def(); |
| 332 | const auto assets_it = collection_def_map.find(kSavedModelAssetsKey); |
| 333 | if (assets_it == collection_def_map.end()) { |
| 334 | return Status::OK(); |
| 335 | } |
| 336 | const auto& any_assets = assets_it->second.any_list().value(); |
| 337 | for (const auto& any_asset : any_assets) { |
| 338 | AssetFileDef asset_file_def; |
| 339 | TF_RETURN_IF_ERROR( |
| 340 | ParseAny(any_asset, &asset_file_def, "tensorflow.AssetFileDef")); |
| 341 | asset_file_defs->push_back(asset_file_def); |
| 342 | } |
| 343 | return Status::OK(); |
| 344 | } |
| 345 | |
| 346 | Status LoadSavedModelInternal(const SessionOptions& session_options, |
| 347 | const RunOptions& run_options, |