Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
model_json: a json dictionary (empty if unused) for model topology.
If `h5_path` points to a weights-only HDF5 file, this return value
will be `None`.
groups: an array of weight_groups as defined in tfjs weights_writer.
"""
if not os.path.exists(h5_path):
raise ValueError('Nonexistent path to HDF5 file: %s' % h5_path)
if os.path.isdir(h5_path):
raise ValueError(
'Expected path to point to an HDF5 file, but it points to a '
'directory: %s' % h5_path)
h5_file = h5py.File(h5_path)
if 'layer_names' in h5_file.attrs:
model_json = None
groups = conversion.h5_weights_to_tfjs_format(
h5_file, split_by_layer=split_weights_by_layer)
else:
model_json, groups = conversion.h5_merged_saved_model_to_tfjs_format(
h5_file, split_by_layer=split_weights_by_layer)
if output_dir:
if os.path.isfile(output_dir):
raise ValueError(
'Output path "%s" already exists as a file' % output_dir)
if not os.path.isdir(output_dir):
os.makedirs(output_dir)
conversion.write_artifacts(
model_json, groups, output_dir, quantization_dtype,
weight_shard_size_bytes=weight_shard_size_bytes)
return model_json, groups
model_json: a json dictionary (empty if unused) for model topology.
If `h5_path` points to a weights-only HDF5 file, this return value
will be `None`.
groups: an array of weight_groups as defined in tfjs weights_writer.
"""
if not os.path.exists(h5_path):
raise ValueError('Nonexistent path to HDF5 file: %s' % h5_path)
if os.path.isdir(h5_path):
raise ValueError(
'Expected path to point to an HDF5 file, but it points to a '
'directory: %s' % h5_path)
h5_file = h5py.File(h5_path)
if 'layer_names' in h5_file.attrs:
model_json = None
groups = conversion.h5_weights_to_tfjs_format(
h5_file, split_by_layer=split_weights_by_layer)
else:
model_json, groups = conversion.h5_merged_saved_model_to_tfjs_format(
h5_file, split_by_layer=split_weights_by_layer)
if output_dir:
if os.path.isfile(output_dir):
raise ValueError(
'Output path "%s" already exists as a file' % output_dir)
if not os.path.isdir(output_dir):
os.makedirs(output_dir)
conversion.write_artifacts(
model_json, groups, output_dir, quantization_dtype,
weight_shard_size_bytes=weight_shard_size_bytes)
return model_json, groups