|
|
|
|
|
|
|
|
if keras: |
|
|
if keras: |
|
|
keras_model.save(f, save_format='tf') |
|
|
keras_model.save(f, save_format='tf') |
|
|
else: |
|
|
else: |
|
|
m = tf.function(lambda x: keras_model(x)) # full model |
|
|
|
|
|
spec = tf.TensorSpec(keras_model.inputs[0].shape, keras_model.inputs[0].dtype) |
|
|
spec = tf.TensorSpec(keras_model.inputs[0].shape, keras_model.inputs[0].dtype) |
|
|
|
|
|
m = tf.function(lambda x: keras_model(x)) # full model |
|
|
m = m.get_concrete_function(spec) |
|
|
m = m.get_concrete_function(spec) |
|
|
frozen_func = convert_variables_to_constants_v2(m) |
|
|
frozen_func = convert_variables_to_constants_v2(m) |
|
|
tfm = tf.Module() |
|
|
tfm = tf.Module() |
|
|
tfm.__call__ = tf.function(lambda x: frozen_func(x)[0], [spec]) |
|
|
|
|
|
|
|
|
tfm.__call__ = tf.function(lambda x: frozen_func(x)[:4] if tf_nms else frozen_func(x)[0], [spec]) |
|
|
tfm.__call__(im) |
|
|
tfm.__call__(im) |
|
|
tf.saved_model.save(tfm, |
|
|
tf.saved_model.save(tfm, |
|
|
f, |
|
|
f, |