from tensorflow import kerasfrom keras.models import load_modelmodel =load_model("example.h5")# Summarizationprint(model.summary())# Configurationprint(model.get_config())# List inputsprint(model.inputs)# List outputsprint(model.outputs)
Using PyTorch
If we don’t have torchinfo, we need to install it at first.
pipinstalltorchinfo
Here is the code for investigation.
import torchfrom torchinfo import summarymodel = torch.load("example.pt")model.eval()# it's not required for investigation only but required when infereningbatch_size =16print(summary(model=model, input_size=(batch_size, 3, 16, 16)))# Also simply show model's state dictprint(model.state_dict)
Scan Model
ModelScan
ModelScan is a machine learning model scanner to protect againt Model Serialization Attacks.
# -p: Path to the filemodelscan-pexample.h5modelscan-pexample.pt# Scan all models in Hugging Face Repositorymodelscan-hfowner/model-repository-name