Created
July 25, 2023 00:10
-
-
Save hrshovon/3e03d2d88190a2cdfeed8d8ea4ce50f4 to your computer and use it in GitHub Desktop.
Simple python snippet for downloading a VGG16 model and saving it as savedmodel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.environ["CUDA_VISIBLE_DEVICES"] = "" | |
import tensorflow as tf | |
import tensorflow.keras.backend as K | |
from pathlib import Path | |
#leaving this line in case someone needs it, just uncomment the line below and comment the next line | |
#model = tf.keras.models.load_model(model_path,compile=False) | |
model = tf.keras.applications.vgg16.VGG16(include_top = True, weights="imagenet", input_shape=(224,224,3)) | |
@tf.function | |
def serve(*args, **kwargs): | |
outputs = model(*args, **kwargs) | |
# Apply postprocessing steps, or add additional outputs. | |
... | |
return outputs | |
# arg_specs is `[tf.TensorSpec(...), ...]`. kwarg_specs, in this | |
# example, is an empty dict since functional models do not use keyword | |
# arguments. | |
arg_specs, kwarg_specs = model.save_spec() | |
#we create the output folder in case it does not exist | |
op_folder = "output_foler" | |
Path(op_folder).mkdir(parents=True, exist_ok = True) | |
savepath = f"{op_folder}/testmodel" | |
model.save(savepath, signatures={ | |
'serving_default': serve.get_concrete_function(*arg_specs, | |
**kwarg_specs) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment