Open taojianggit opened 3 years ago
I use the following code to calculate the parameters of the tf official model file, (params=8370479, model='http://download.tensorflow.org/models/object_detection/ssdlite_mobiledet_cpu_320x320_coco_2020_05_19.tar.gz').
from functools import reduce
from operator import mul
import numpy as np
from tensorflow.python import pywrap_tensorflow
def get_num_params(ckpt_path):
reader = pywrap_tensorflow.NewCheckpointReader(ckpt_path)
var_to_shape_map = reader.get_variable_to_shape_map()
total_parameters = 0
for key in var_to_shape_map:
shape = np.shape(reader.get_tensor(key))
params = reduce(mul, shape, 1)
print('key: %s, shape: %s, params: %s' % (key, shape, params))
total_parameters += params
print(total_parameters)
return total_parameters
get_num_params('ssdlite_mobiledet_cpu_320x320_coco_2020_05_19/model.ckpt-400000')
# 8370479
The official model file size also exceeds 10MB.
If you want to get a smaller deployment model, you can consider setting quantize to True when converting to TFLite model file.
python converter_tflite.py --quantize=True ......
`---------------------------------------------------------------- Layer (type) Output Shape Param #
Total params: 11,690,672 Trainable params: 11,690,672 Non-trainable params: 0
Input size (MB): 2.23 Forward/backward pass size (MB): 527.29 Params size (MB): 44.60 Estimated Total Size (MB): 574.11
The original paper says the params in all the platforms are less than 10M.