Reputation: 387
I train different models with tensor object detection (TFOD) API and I would like to know how many parameters are trained for a given model.
I run faster RCNN, SSD, RFCN and also with different image resolution, I would like to have a way to know how many parameters are trained. Is there a way to do that?
I have tried answers found here How to count total number of trainable parameters in a tensorflow model? with no luck.
Here is the code I added line 103 of model_main.py
:
print("Training {} parameters".format(np.sum([np.prod(v.get_shape().as_list()) for v in tf.trainable_variables()]))
I think the problem is that I do not access the tf.Session() the TFOD is running, hence my code always return 0.0 parameters (although training strats just fine and train, hopefully, millions of parameters), and I don't know how to solve that issue.
Upvotes: 4
Views: 1821
Reputation: 1912
When using the export_inference_graph.py, the script also analyzes your model, and counts parameters and FLOPS (if possible). If looks like this:
_TFProfRoot (--/# total params)
FeatureExtractor (--/# params)
...
WeightSharedConvolutionalBoxPredictor (--/# params)
...
Upvotes: 1
Reputation: 4071
TFOD API used tf.estimator.Estimator
to train and evaluate. The Estimator
object provided function to get all the variables, Estimator.get_variable_names()
(reference).
You can add this line print(estimator.get_variable_names())
after estimator.train_and_evaluate()
(here).
You will see all variable names printed after the training is completed. To see the results faster, you can train for just 1 step.
Upvotes: 0