Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Added script to test caffe converted models layer by layer #6680

Merged
merged 8 commits into from
Jun 22, 2017

Conversation

arikpoz
Copy link
Contributor

@arikpoz arikpoz commented Jun 13, 2017

I've added a script which compares layer by layer both the weights and the outputs of a caffe model and its converted mxnet model.

The script by default runs on the known test models mentioned in test_converter.py, namely: bvlc_googlenet, vgg-16 and resnet-50.
In addition the script offers functions for comparing any model by supplying the parameters of the caffe model.

The script goes over the layers of the network DAG, in BFS order, and compares the layer's parameters, usually weights and bias, but others as well.

In addition the script takes an image as input and run inference using both caffe and mxnet models, and compare the blob outputs of each layer, taking into consideration inplace layers.

For each weight blob and output blob the script log to screen the mean and max of the absolute difference between the blobs.

Attached output generated when running the script using default parameters: compare_layers_output.txt

Since the script runs caffe inference, it depends on caffe being installed. The dependency is implicit, so the user of the script can resolve it by installing his favorite caffe version and setting the proper environment variables. All the script requires is that 'import caffe' will work.

@arikpoz
Copy link
Contributor Author

arikpoz commented Jun 13, 2017

Note that this PR addresses the 'pair test with caffe' in future roadmap of #5247

@mli
Copy link
Contributor

mli commented Jun 13, 2017

Can you please add a CI test on https://github.com/dmlc/mxnet/blob/master/Jenkinsfile#L335

@arikpoz
Copy link
Contributor Author

arikpoz commented Jun 13, 2017

I'm not sure how to go about that..
Is running the tool enough? should I add assertion to make sure the per layer difference is low?
Also, the tool depends on caffe being setup properly (such that 'import caffe' works), can this be an issue for integration tests?

@mli
Copy link
Contributor

mli commented Jun 13, 2017 via email

@arikpoz
Copy link
Contributor Author

arikpoz commented Jun 13, 2017

Currently test_converter.py downloads the models and dataset and check the models performance,
while compare_layers.py downloads the models and a test image and check the models weights and outputs.

Do you think the test_converter.py script should cover both checks? in which case I need to merge them to a single file.

Or should I leave compare_layers.py as a standalone script, add the relevant assertions, possibly rename it to test_compare_layers.py, and add it to the list of CI tests?

@mli
Copy link
Contributor

mli commented Jun 13, 2017 via email

arikpoz added 3 commits June 14, 2017 00:14
…er-by-layer comparison test for known models. Compare login remains in standalone compare_layers script.
@arikpoz arikpoz force-pushed the add_layer_comparison branch from 96c6684 to 5292f65 Compare June 13, 2017 21:15
@arikpoz
Copy link
Contributor Author

arikpoz commented Jun 13, 2017

I've refactored test_converter.py script to run both performance test and layer-by-layer comparison test for known models. The layer comparison login remains in a standalone compare_layers.py script, to avoid clouding the test_converter script, and to allow users to run the layer by layer comparison on their private models.

I've added assertion of mean difference allowed (1e-4) and max difference allowed (1e-2), based on actual numbers I got when running on CPU. Unfortunately, I can't run the test on GPU, so I hope it passes the integration test, and if not, we might need to update the threshold for the GPU. Hopefully, there won't be any significant difference..

@arikpoz arikpoz force-pushed the add_layer_comparison branch from cec3383 to 8ee4543 Compare June 14, 2017 12:28
@arikpoz arikpoz force-pushed the add_layer_comparison branch from 8ee4543 to ec44591 Compare June 14, 2017 13:18
@arikpoz
Copy link
Contributor Author

arikpoz commented Jun 14, 2017

Finally, continuous-integration/jenkins/pr-head passed with the new test.
I'm not familiar with the problem of continuous-integration/travis-ci/pr, if someone can check it out it would be great..

@arikpoz
Copy link
Contributor Author

arikpoz commented Jun 15, 2017

ready to merge

@arikpoz
Copy link
Contributor Author

arikpoz commented Jun 15, 2017

@mli can you check?

@arikpoz
Copy link
Contributor Author

arikpoz commented Jun 21, 2017

errors doesn't seem to be related

@mli mli merged commit 0ba8809 into apache:master Jun 22, 2017
@arikpoz arikpoz deleted the add_layer_comparison branch June 29, 2017 05:13
Guneet-Dhillon pushed a commit to Guneet-Dhillon/mxnet that referenced this pull request Sep 13, 2017
* added script for comparing layer by layer the converter results, weights and outputs

* added to contributors list

* Refactored test_converter script to run both performance test and layer-by-layer comparison test for known models. Compare login remains in standalone compare_layers script.

* fix cv2, and accuracy assertion failed on vgg, increased threshold
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants