Add `trackable_asset` to `asset_info` and `resource_map`.
(trackable_asset, asset_info, resource_map)
| 502 | |
| 503 | |
| 504 | def _process_asset(trackable_asset, asset_info, resource_map): |
| 505 | """Add `trackable_asset` to `asset_info` and `resource_map`.""" |
| 506 | original_path_tensor = trackable_asset.asset_path |
| 507 | original_path = tensor_util.constant_value(original_path_tensor) |
| 508 | try: |
| 509 | original_path = str(original_path.astype(str)) |
| 510 | except AttributeError: |
| 511 | # Already a string rather than a numpy array |
| 512 | pass |
| 513 | path = builder_impl.get_asset_filename_to_add( |
| 514 | asset_filepath=original_path, |
| 515 | asset_filename_map=asset_info.asset_filename_map) |
| 516 | # TODO(andresp): Instead of mapping 1-1 between trackable asset |
| 517 | # and asset in the graph def consider deduping the assets that |
| 518 | # point to the same file. |
| 519 | asset_path_initializer = array_ops.placeholder( |
| 520 | shape=original_path_tensor.shape, |
| 521 | dtype=dtypes.string, |
| 522 | name="asset_path_initializer") |
| 523 | asset_variable = resource_variable_ops.ResourceVariable( |
| 524 | asset_path_initializer) |
| 525 | asset_info.asset_filename_map[path] = original_path |
| 526 | asset_def = meta_graph_pb2.AssetFileDef() |
| 527 | asset_def.filename = path |
| 528 | asset_def.tensor_info.name = asset_path_initializer.name |
| 529 | asset_info.asset_defs.append(asset_def) |
| 530 | asset_info.asset_initializers_by_resource[original_path_tensor] = ( |
| 531 | asset_variable.initializer) |
| 532 | asset_info.asset_index[trackable_asset] = len(asset_info.asset_defs) - 1 |
| 533 | resource_map[original_path_tensor] = asset_variable |
| 534 | |
| 535 | |
| 536 | def _fill_meta_graph_def(meta_graph_def, saveable_view, signature_functions): |
no test coverage detected