ML Model Analysis

Last modified: 2023-08-22

Machine Learning

Model Investigation

Using Keras

from tensorflow import keras
from keras.models import load_model

model = load_model("example.h5")

# Summarization

# Configuration

# List inputs
# List outputs

Using PyTorch

If we don’t have torchinfo, we need to install it at first.

pip install torchinfo

Here is the code for investigation.

import torch
from torchinfo import summary

model = torch.load("")
model.eval() # it's not required for investigation only but required when inferening

batch_size = 16
print(summary(model=model, input_size=(batch_size, 3, 16, 16)))

# Also simply show model's state dict

Scan Model


ModelScan is a machine learning model scanner to protect againt Model Serialization Attacks.

# -p: Path to the file
modelscan -p example.h5
modelscan -p

# Scan all models in Hugging Face Repository
modelscan -hf owner/model-repository-name