<commit_before>"""
unzip the following datafile
tar


ref:
1. https://stackoverflow.com/questions/40118062/how-to-read-weights-saved-in-tensorflow-checkpoint-file
2. https://www.tensorflow.org/s/results/?q=freezegraph&p=%2F

Loading meta only might not work.
If the checkpoint contains:
model.ckpt.meta
model.ckpt.index
model.ckpt.data-XXXX

model_name = model.ckpt

If the checkpoint only contains model.ckpt
model_name = model.ckpt


Checked on inceptionv3 and mobilenet
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
import sys
import math

import numpy as np
np.set_printoptions(precision=32)
from tensorflow.python import pywrap_tensorflow
from tensorflow.python.platform import app
from tensorflow.python.platform import flags
CHECK_ALL = True
# CHECK_ALL = True
weights_params = {}
bn_params = {}
# model_name = "../data/mobilenet_v1_1.0_224.ckpt"
model_name = "/local/scratch/yaz21/tmp/model.ckpt-255000"
reader = pywrap_tensorflow.NewCheckpointReader(model_name)
var_to_shape_map = reader.get_variable_to_shape_map()
TEST = False

for key in sorted(var_to_shape_map):
     if (key.endswith('/w') or key.endswith('/b')):
         print (key)<commit_msg>testing<commit_after>"""
unzip the following datafile
tar


ref:
1. https://stackoverflow.com/questions/40118062/how-to-read-weights-saved-in-tensorflow-checkpoint-file
2. https://www.tensorflow.org/s/results/?q=freezegraph&p=%2F

Loading meta only might not work.
If the checkpoint contains:
model.ckpt.meta
model.ckpt.index
model.ckpt.data-XXXX

model_name = model.ckpt

If the checkpoint only contains model.ckpt
model_name = model.ckpt


Checked on inceptionv3 and mobilenet
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
import sys
import math
import pickle

import numpy as np
np.set_printoptions(precision=32)
from tensorflow.python import pywrap_tensorflow
from tensorflow.python.platform import app
from tensorflow.python.platform import flags
CHECK_ALL = True
# CHECK_ALL = True
weights_params = {}
bn_params = {}
# model_name = "../data/mobilenet_v1_1.0_224.ckpt"
model_name = "/local/scratch/yaz21/tmp/model.ckpt-255000"
reader = pywrap_tensorflow.NewCheckpointReader(model_name)
var_to_shape_map = reader.get_variable_to_shape_map()
TEST = False
vars_to_store = {}

for key in sorted(var_to_shape_map):
     if (key.endswith('/w') or key.endswith('/b')):
         vars_to_store[key] = var_to_shape_map[key]
         print (key)
with open('vgg_var.pkl','wb') as f:
    f.dump(vars_to_store)
{'fraction_non_alphanumeric': 0.09958190801976435, 'fraction_numerical': 0.021284682630178638, 'mean_word_length': 5.163934426229508, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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}}
{'dir': 'git-commits-cleaned', 'id': '1306910', 'n_tokens_mistral': 933, 'n_tokens_neox': 883, 'n_words': 209}