This repository contains code to train and score a Spatial Transformer Network on IBM Watson Machine Learning. This model is part of the IBM Code Model Asset Exchange.
A Spatial Transformer Network allows the spatial manipulation of data within the network.
It can be inserted into existing convolutional architectures, giving neural networks the ability to actively spatially transform feature maps, conditional on the feature map itself, without any extra training supervision or modification to the optimisation process[1].
| Domain | Application | Industry | Framework | Training Data | Input Data Format |
|---|---|---|---|---|---|
| Vision | Computer Vision | General | TensorFlow | Cluttered MNIST Sample | Images |
[1] Jaderberg, Max, et al. "Spatial Transformer Networks" arXiv preprint arXiv:1506.02025 (2015)
| Component | License | Link |
|---|---|---|
| This repository | Apache 2.0 | LICENSE |
| Model Code (3rd party) | Apache 2.0 | TensorFlow Models |
| Data | MIT | Cluttered MNIST |
transformer(U, theta, out_size)
U : float
The output of a convolutional net should have the
shape [num_batch, height, width, num_channels].
theta: float
The output of the
localisation network should be [num_batch, 6].
out_size: tuple of two ints
The size of the output of the network
To initialize the network to the identity transform init theta to :
identity = np.array([[1., 0., 0.],
[0., 1., 0.]])
identity = identity.flatten()
theta = tf.Variable(initial_value=identity)- This experiment requires a provisioned instance of IBM Watson Machine Learning service. If you don't have an instance yet, go to Watson Machine Learning in the IBM Cloud Catalog to create one.
- Create an IBM Cloud Object Storage account if you don't have one (https://www.ibm.com/cloud/storage)
- Create credentials for either reading and writing or just reading
- From the bluemix console page (https://console.bluemix.net/dashboard/apps/), choose
Cloud Object Storage - On the left side, click the
service credentials - Click on the
new credentialsbutton to create new credentials - In the
Add New Credentialspopup, use this parameter{"HMAC":true}in theAdd Inline Configuration... - When you create the credentials, copy the
access_key_idandsecret_access_keyvalues. - Make a note of the endpoint url
- On the left side of the window, click on
Endpoint - Copy the relevant public or private endpoint. [I choose the us-geo private endpoint].
- On the left side of the window, click on
- From the bluemix console page (https://console.bluemix.net/dashboard/apps/), choose
- In addition setup your AWS S3 command line which can be used to create buckets and/or add files to COS.
- Export
AWS_ACCESS_KEY_IDwith your COSaccess_key_idandAWS_SECRET_ACCESS_KEYwith your COSsecret_access_key
- Install IBM Cloud CLI
- Login using
bx loginorbx login --ssoif within IBM
- Login using
- Install ML CLI Plugin
- After install, check if there is any plugins that need update
bx plugin update
- Make sure to setup the various environment variables correctly:
ML_INSTANCE,ML_USERNAME,ML_PASSWORD,ML_ENV
- After install, check if there is any plugins that need update
The train.sh utility script will deploy the experiment to WML and start the training as a training-run
train.sh
After the train is started, it should print the training-id that is going to be necessary for steps below
Starting to train ...
OK
Model-ID is 'training-GCtN_YRig'
- To list the training runs -
bx ml list training-runs - To monitor a specific training run -
bx ml show training-runs <training-id> - To monitor the output (stdout) from the training run -
bx ml monitor training-runs <training-id>- This will print the first couple of lines, and may time out.
Save the model, when the training run has successfully completed and deploy it for scoring.
bx ml store training-runs <training-id>- This should give you back a model-id
bx ml deploy <model-id> 'spatial-training-deployment'- This should give you a deployment-id
- Update
modelIdanddeploymentIdonscoring-payload.json - Score the model with
bx ml score scoring-payload.json
bx ml score scoring-payload.json
Fetching scoring results for the deployment '14f98de1-bc60-4ece-b9f2-3e0c1528c778' ...
{"values": [1]}
OK
Score request successful
If you want to train this model using Fabric for Deep Learning (FFDL), You can simply clone the FfDL repository and follow the instructions over here to convert your training-runs.yml into FfDL's specification.
