[MXNet-1343][Fit API]Add CNN integration test for fit() API - #14405
Conversation
| set -ex | ||
| cd /work/mxnet/tests/nightly/estimator | ||
| export PYTHONPATH=/work/mxnet/python/ | ||
| python tests/nightly/estimator/test_estimator_cnn_gpu.py |
There was a problem hiding this comment.
Is the test_estimator_cnn_gpu.py file path correct? The current shell location is already inside /work/mxnet/tests/nightly/estimator directory.
| 'estimator: CNN CPU': { | ||
| node(NODE_LINUX_CPU) { | ||
| ws('workspace/estimator-test-cnn-cpu') { | ||
| utils.unpack_and_init('gpu', mx_lib) |
| trainers=trainer, | ||
| context=context) | ||
| # Call fit() to begin training | ||
| logging_handler = event_handler.LoggingHandler(est, model_name+'_log', model_name+'_log') |
There was a problem hiding this comment.
LoggingHandler Class constructor says def __init__(self, estimator, file_name=None, file_location=None, ):, is file_location name correct?(e.g.: alexnet_log/alexnet_log). I think you have to provide file_location as a directory path or you can leave it empty since code takes care of it. Thanks!
There was a problem hiding this comment.
Thanks for pointing it out. Removing logging handler from integration tests for now as its undergoing changes. It will be covered in unit tests.
| trainers=trainer, | ||
| context=context) | ||
| # Call fit() to begin training | ||
| logging_handler = event_handler.LoggingHandler(est, model_name+'_log', model_name+'_log') |
|
@mxnet-label-bot add [Gluon, pr-work-in-progress] |
roywei
left a comment
There was a problem hiding this comment.
Thank for your contribution, as these tests are not running in PR checks, let's test them before merging.
| dataset = gluon.data.dataset.ArrayDataset(mx.nd.random.uniform(shape=(batch_size, 1, 224, 224)), | ||
| mx.nd.zeros(batch_size)) | ||
| loss = gluon.loss.SoftmaxCrossEntropyLoss() | ||
| net.initialize(mx.init.MSRAPrelu(), ctx=context) |
There was a problem hiding this comment.
let's use a more common initializer
There was a problem hiding this comment.
Changed to Xavier initializer
|
|
||
| def bilinear_kernel(in_channels, out_channels, kernel_size): | ||
| ''' | ||
| Bilinear interpolation using transposed convolution |
There was a problem hiding this comment.
reference for this implementation?
There was a problem hiding this comment.
Added link to reference code
| from mxnet.gluon.model_zoo import vision | ||
|
|
||
| def load_data_mnist(batch_size, resize=None, num_workers=None, | ||
| root=os.path.join('~', '.mxnet', 'datasets', 'mnist')): |
There was a problem hiding this comment.
remove root, let's not keep the data under ~/.mxnet in nightly tests.
| context=context) | ||
| # Call fit() to begin training | ||
| est.fit(train_data=train_data, | ||
| val_data=train_data, |
There was a problem hiding this comment.
Can you please create another random validation data and pass it here instead of using same train_data for both train and validation. Thanks!
…nto fit-api-test
|
@mxnet-label-bot update [Gluon, Test, pr-awaiting-merge] |
| val_dataset = gluon.data.dataset.ArrayDataset(mx.nd.random.uniform(shape=(batch_size, 3, 320, 480)), | ||
| mx.nd.zeros(shape=(batch_size, 320, 480))) | ||
| loss = gluon.loss.SoftmaxCrossEntropyLoss(axis=1) | ||
| net[-1].initialize(init.Constant(bilinear_kernel(num_classes, num_classes, 64)), ctx=context) |
There was a problem hiding this comment.
why not get the net from directly from FCN method?, why split the logic?.
There was a problem hiding this comment.
Updated logic, please have a look again
| input_size = 224 | ||
| lr = 0.001 | ||
| # Set context | ||
| if mx.context.num_gpus() > 0: |
There was a problem hiding this comment.
The GPU test just runs 5 epochs on MNIST, I think 1 GPU is enough.
| from mxnet.gluon.estimator import estimator, event_handler | ||
| from mxnet.gluon.model_zoo import vision | ||
|
|
||
| def load_data_mnist(batch_size, resize=None, num_workers=None): |
There was a problem hiding this comment.
why do you have we need 2 different files?
There was a problem hiding this comment.
combined tests into 1 file
| Test estimator by doing one pass over each model with synthetic data | ||
| ''' | ||
| models = ['resnet18_v1', | ||
| 'alexnet', |
There was a problem hiding this comment.
i don't think we need alexnet here since the fit is not very different than resnet.
| set -ex | ||
| cd /work/mxnet/tests/nightly/estimator | ||
| export PYTHONPATH=/work/mxnet/python/ | ||
| python test_estimator_cnn.py --type gpu |
There was a problem hiding this comment.
what's the reason to run a python script instead of using nosetest and assert accuracy at the end?
There was a problem hiding this comment.
Since we are executing a single test here, running the python script suffices. We can shift to nosetests if we add more tests in the future.
| utils.docker_run('ubuntu_nightly_gpu', 'nightly_tutorial_test_ubuntu_python3_gpu', true, '1500m') | ||
| } | ||
| } | ||
| }, |
There was a problem hiding this comment.
IMO, This should be in nightly/Jenkinsfile and not the one for Binaries
There was a problem hiding this comment.
I think it should work in either Jenkins file, I placed it in binaries since it contained similar existing nightly tests. I will keep your suggestion in mind and update with a follow up PR in case there are any issues with the current setup.
| model_name = 'resnet18_v1' | ||
| batch_size = 128 | ||
| num_epochs = 5 | ||
| if mx.context.num_gpus() > 0: |
There was a problem hiding this comment.
You should not fallback to mx.cpu here since you want to test on gpu only in this test.
There was a problem hiding this comment.
I do not want the test to fail if GPU is not available, it should pass on either context.
There was a problem hiding this comment.
we want it to fail and know if there is an issue, could you please change it.
There was a problem hiding this comment.
deleted "Also use all the GPUs, so if we run this same code elsewhere we can make use of it without having to change this code."
There was a problem hiding this comment.
ignore the comment on using all GPUs, we can do it as required.
There was a problem hiding this comment.
Updated context to use GPU
| epochs=num_epochs, | ||
| batch_size=batch_size) | ||
|
|
||
| assert est.train_stats['train_'+acc.name][num_epochs-1] > 0.75 |
There was a problem hiding this comment.
After 5 epochs the training accuracy is ~85%. I have made it more strict by setting it to 80%. What do you think?
Description
Add nightly integration tests for fit() API using CNN models.
This PR depends on the parent PR for fit() API #14346
JIRA epic: https://issues.apache.org/jira/projects/MXNET/issues/MXNET-1333
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Comments