Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

ML-Agents/ How can I check the parameter size (or number) of my model?

Discussion in 'ML-Agents' started by Chika-S, Jul 25, 2023.

  1. Chika-S

    Chika-S

    Joined:
    Apr 18, 2022
    Posts:
    2
    Hello.
    Please help me.
    ML-Agents/ How can I check the parameter size (or number) of my model?
    Also, is there a relationship between the file size of a model file (onnx file) and the number of parameters?
     
  2. kokimitsunami

    kokimitsunami

    Joined:
    Sep 2, 2021
    Posts:
    25
    Hi @Chika-S

    I quickly made a python script to check the parameter size of an NN model. I hope this helps.

    Code (Boo):
    1. import onnx
    2. from onnx import numpy_helper
    3.  
    4. model_path = "./yourmodel.onnx"
    5.  
    6. def count_parameters(onnx_model_path):
    7.     model = onnx.load(onnx_model_path)
    8.     total_parameters = 0
    9.     for initializer in model.graph.initializer:
    10.         total_parameters += numpy_helper.to_array(initializer).size
    11.     return total_parameters
    12.  
    13. num_params = count_parameters(model_path)
    14. print("num_of_params: ", num_params)
    15.  
    And yes, there is generally a relationship between the file size of a model and the number of parameters, because the parameters are stored in the file. The relationship might not be linear due to the model's precision, compression etc, though.
     
  3. Chika-S

    Chika-S

    Joined:
    Apr 18, 2022
    Posts:
    2
    Hello. @kokimitsunami
    thank you very much so kindly!!
    I will definitely try it.
    Thank you.