2018-05-26 10:25:24 +03:00
<!--
Copyright (c) Microsoft Corporation
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS* , WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
2018-08-16 07:03:38 +03:00
# Keras on OpenPAI
2018-05-26 10:25:24 +03:00
2018-08-16 07:03:38 +03:00
This guide introduces how to run [Keras ](http://keras.io/ ) job on OpenPAI.
2018-05-26 10:25:24 +03:00
The following contents show some basic Keras examples, other customized Keras code can be run similarly.
2018-08-16 07:03:38 +03:00
## Keras tensorflow backend MNIST digit recognition examples
2018-05-26 10:25:24 +03:00
2018-08-16 07:03:38 +03:00
To run Keras examples in OpenPAI, you need to prepare a job configuration file and submit it through webportal.
2018-05-26 10:25:24 +03:00
2018-08-16 07:03:38 +03:00
OpenPAI packaged the docker env required by the job for user to use. User could refer to [DOCKER.md ](./DOCKER.md ) to customize this example docker env. If user have built a customized image and pushed it to Docker Hub, replace our pre-built image `pai.example.keras.tensorflow` with your own.
2018-05-26 10:25:24 +03:00
Here're some configuration file examples:
### [mnist_tensorflow_backend](https://github.com/keras-team/keras/blob/master/examples/mnist_cnn.py)
```json
{
"jobName": "keras_tensorflow_backend_mnist",
2018-06-25 08:15:06 +03:00
"image": "openpai/pai.example.keras.tensorflow",
2018-05-26 10:25:24 +03:00
"taskRoles": [
{
"name": "mnist",
"taskNumber": 1,
"cpuNumber": 4,
"memoryMB": 8192,
"gpuNumber": 1,
"command": "python mnist_cnn.py"
}
]
}
```
2018-08-16 07:03:38 +03:00
## Keras cntk backend MNIST digit recognition examples
2018-05-26 10:25:24 +03:00
### [mnist_cntk_backend](https://github.com/keras-team/keras/blob/master/examples/mnist_cnn.py)
```json
{
2018-10-11 10:00:30 +03:00
"jobName": "keras_cntk_backend_mnist",
2018-06-25 08:15:06 +03:00
"image": "openpai/pai.example.keras.cntk",
2018-05-26 10:25:24 +03:00
"taskRoles": [
{
"name": "mnist",
"taskNumber": 1,
"cpuNumber": 4,
"memoryMB": 8192,
"gpuNumber": 1,
"command": "python mnist_cnn.py"
}
]
}
```
2018-07-25 11:45:25 +03:00
For more details on how to write a job configuration file, please refer to [job tutorial ](../../docs/job_tutorial.md#json-config-file-for-job-submission ).
2018-05-26 10:25:24 +03:00
2018-08-16 07:03:38 +03:00
### Note:
2018-05-26 10:25:24 +03:00
2018-11-05 08:54:36 +03:00
Since PAI runs Keras jobs in Docker, the training speed on PAI should be similar to speed on host.
2018-08-13 04:33:50 +03:00
2018-10-11 10:00:30 +03:00
We provide two stable docker images by adding the data to the images. If you want to use them, add `stable` tag to the image name: `openpai/pai.example.keras.cntk:stable` or `openpai/pai.example.keras.tensorflow:stable` .