<jupyter_start><jupyter_text>WeightWatcher   Basic Functionalityhttps://calculationconsulting.com<jupyter_code># Suppress the powerlaw package warnings
# "powerlaw.py:700: RuntimeWarning: divide by zero encountered in true_divide"
# "powerlaw.py:700: RuntimeWarning: invalid value encountered in true_divide"
import warnings
warnings.simplefilter(action='ignore', category=RuntimeWarning)
import numpy as np
import pandas as pd

import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>1. Quick start example  1.1 Import your model (Keras or PyTorch)<jupyter_code>import tensorflow 
from tensorflow.keras.models import load_model
from tensorflow.keras.applications import vgg16

kmodel = vgg16.VGG16
model = kmodel(weights='imagenet')<jupyter_output><empty_output><jupyter_text>1.2 Run WeightWatcher<jupyter_code>import weightwatcher as ww

watcher = ww.WeightWatcher(model=model)
details = watcher.analyze()
details
watcher.get_summary(details)<jupyter_output><empty_output><jupyter_text>2. Advanced examples  2.1 Filter by layer type (CONV1D, CONV2D, DENSE)In this example we are interested in the DENSE layers only<jupyter_code>from tensorflow.keras.applications import vgg16

kmodel = vgg16.VGG16
model = kmodel(weights='imagenet')

import weightwatcher as ww

watcher = ww.WeightWatcher(model=model)

details = watcher.analyze(layers=ww.LAYER_TYPE.DENSE)
details<jupyter_output><empty_output><jupyter_text>2.2 Filter by multiple layer typesIn this example we are interested in the CONV1D and DENSE layers.Filter the layers using a bitmask.<jupyter_code>import weightwatcher as ww

watcher = ww.WeightWatcher(model=model)

details = watcher.analyze(layers=[ww.LAYER_TYPE.CONV1D,ww.LAYER_TYPE.DENSE])
details<jupyter_output><empty_output><jupyter_text>2.3 Filter by layer Ids<jupyter_code>import weightwatcher as ww

watcher = ww.WeightWatcher(model=model)

details = watcher.analyze(layers=[20])
details<jupyter_output><empty_output><jupyter_text>2.4 Plots<jupyter_code>import weightwatcher as ww

watcher = ww.WeightWatcher(model=model)

details = watcher.analyze(plot=True)<jupyter_output><empty_output><jupyter_text>2.5 Debug and Custom Logging<jupyter_code>import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(ww.__name__)
logger.setLevel(logging.DEBUG)

import weightwatcher as ww

watcher = ww.WeightWatcher(model=model)

details = watcher.analyze()<jupyter_output><empty_output><jupyter_text>3. pyTorch Models<jupyter_code>import weightwatcher as ww
import torchvision.models as models

model = models.vgg16(pretrained=True)

watcher = ww.WeightWatcher(model=model)

details = watcher.analyze()
summary =  watcher.get_summary(details)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0898876404494382, 'fraction_numerical': 0.015585357013410656, 'mean_word_length': 8.169435215946844, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '349279', 'license': 'Apache-2.0', 'n_tokens_mistral': 971, 'n_tokens_neox': 952, 'n_words': 196, 'path': 'WeightWatcher.ipynb', 'repo_name': 'quantitative-technologies/WeightWatcher', 'size': '2759'}