Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'For input_type=tfjs_layers_model & output_format=keras, '
'the output path should be the path to an HDF5 file, '
'but received an existing directory (%s).' % h5_path)
# Verify that config_json_path points to a JSON file.
with open(config_json_path, 'rt') as f:
try:
json.load(f)
except (ValueError, IOError):
raise ValueError(
'For input_type=tfjs_layers_model & output_format=keras, '
'the input path is expected to contain valid JSON content, '
'but cannot read valid JSON content from %s.' % config_json_path)
with tf.Graph().as_default(), tf.compat.v1.Session():
model = keras_tfjs_loader.load_keras_model(config_json_path)
model.save(h5_path)
# TODO(cais): Assert output_dir_path doesn't exist or is the path to
# a directory (not a file).
# Verify that config_json_path points to a JSON file.
with open(config_json_path, 'rt') as f:
try:
json.load(f)
except (ValueError, IOError):
raise ValueError(
'For input_type=tfjs_layers_model, '
'the input path is expected to contain valid JSON content, '
'but cannot read valid JSON content from %s.' % config_json_path)
temp_h5_path = tempfile.mktemp(suffix='.h5')
model = keras_tfjs_loader.load_keras_model(config_json_path)
model.save(temp_h5_path)
dispatch_keras_h5_to_tfjs_graph_model_conversion(
temp_h5_path, output_dir_path,
quantization_dtype=quantization_dtype,
skip_op_check=skip_op_check,
strip_debug_ops=strip_debug_ops)
# Clean up temporary HDF5 file.
os.remove(temp_h5_path)
'For input_type=tfjs_layers_model & output_format=keras_saved_model, '
'the input path should be a model.json '
'file, but received a directory.')
# Verify that config_json_path points to a JSON file.
with open(config_json_path, 'rt') as f:
try:
json.load(f)
except (ValueError, IOError):
raise ValueError(
'For input_type=tfjs_layers_model & output_format=keras, '
'the input path is expected to contain valid JSON content, '
'but cannot read valid JSON content from %s.' % config_json_path)
with tf.Graph().as_default(), tf.compat.v1.Session():
model = keras_tfjs_loader.load_keras_model(config_json_path)
keras.experimental.export_saved_model(
model, keras_saved_model_path, serving_only=True)
'For input_type=tfjs_layers_model & output_format=keras, '
'the output path should be the path to an HDF5 file, '
'but received an existing directory (%s).' % h5_path)
# Verify that config_json_path points to a JSON file.
with open(config_json_path, 'rt') as f:
try:
json.load(f)
except (ValueError, IOError):
raise ValueError(
'For input_type=tfjs_layers_model & output_format=keras, '
'the input path is expected to contain valid JSON content, '
'but cannot read valid JSON content from %s.' % config_json_path)
with tf.Graph().as_default(), tf.compat.v1.Session():
model = keras_tfjs_loader.load_keras_model(config_json_path)
model.save(h5_path)
'For input_type=tfjs_layers_model & output_format=keras_saved_model, '
'the input path should be a model.json '
'file, but received a directory.')
# Verify that config_json_path points to a JSON file.
with open(config_json_path, 'rt') as f:
try:
json.load(f)
except (ValueError, IOError):
raise ValueError(
'For input_type=tfjs_layers_model & output_format=keras, '
'the input path is expected to contain valid JSON content, '
'but cannot read valid JSON content from %s.' % config_json_path)
with tf.Graph().as_default(), tf.compat.v1.Session():
model = keras_tfjs_loader.load_keras_model(config_json_path)
keras.experimental.export_saved_model(
model, keras_saved_model_path, serving_only=True)
# TODO(cais): Assert output_dir_path doesn't exist or is the path to
# a directory (not a file).
# Verify that config_json_path points to a JSON file.
with open(config_json_path, 'rt') as f:
try:
json.load(f)
except (ValueError, IOError):
raise ValueError(
'For input_type=tfjs_layers_model, '
'the input path is expected to contain valid JSON content, '
'but cannot read valid JSON content from %s.' % config_json_path)
temp_h5_path = tempfile.mktemp(suffix='.h5')
with tf.Graph().as_default(), tf.compat.v1.Session():
model = keras_tfjs_loader.load_keras_model(config_json_path)
model.save(temp_h5_path)
dispatch_tensorflowjs_to_keras_h5_conversion(config_json_path, temp_h5_path)
with tf.Graph().as_default(), tf.compat.v1.Session():
dispatch_keras_h5_to_tfjs_layers_model_conversion(
temp_h5_path, output_dir_path,
quantization_dtype=quantization_dtype,
weight_shard_size_bytes=weight_shard_size_bytes)
# TODO(cais): Support weight quantization.
# Clean up the temporary H5 file.
os.remove(temp_h5_path)