Example #1
0
#* specific language governing permissions and limitations
#* under the License.
#*
#*************************************************************/


import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
from singa.model import *
from examples.datasets import mnist

rbmid = 2
pvalues = {'batchsize' : 100, 'shape' : 784, 'std_value' : 255}
X_train, X_test, workspace = mnist.load_data(
            workspace = 'examples/rbm/rbm2',
            nb_rbm = rbmid,
            checkpoint_steps = 6000,
            **pvalues)

m = Energy('rbm'+str(rbmid), sys.argv)

out_dim = [1000, 500]
m.add(RBM(out_dim, w_std=0.1, b_wd=0))

sgd = SGD(lr=0.1, decay=0.0002, momentum=0.8)
topo = Cluster(workspace)
m.compile(optimizer=sgd, cluster=topo)
m.fit(X_train, alg='cd', nb_epoch=6000)
#result = m.evaluate(X_test, test_steps=100, test_freq=500)

Example #2
0
#*************************************************************/

import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from singa.model import *
from examples.datasets import mnist

# Sample parameter values for Mnist MLP example
pvalues = {
    'batchsize': 64,
    'shape': 784,
    'random_skip': 5000,
    'std_value': 127.5,
    'mean_value': 127.5
}
X_train, X_test, workspace = mnist.load_data(**pvalues)

m = Sequential('mlp', argv=sys.argv)
''' Weight and Bias are initialized by
    uniform distribution with scale=0.05 at default
'''
m.add(Dense(2500, init='uniform', activation='tanh'))
m.add(Dense(2000, init='uniform', activation='tanh'))
m.add(Dense(1500, init='uniform', activation='tanh'))
m.add(Dense(1000, init='uniform', activation='tanh'))
m.add(Dense(500, init='uniform', activation='tanh'))
m.add(Dense(10, init='uniform', activation='softmax'))

sgd = SGD(lr=0.001, lr_type='step')
topo = Cluster(workspace)
m.compile(loss='categorical_crossentropy', optimizer=sgd, cluster=topo)
Example #3
0
#* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#* KIND, either express or implied.  See the License for the
#* specific language governing permissions and limitations
#* under the License.
#*
#*************************************************************/

import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from singa.model import *
from examples.datasets import mnist

rbmid = 4
pvalues = {'batchsize': 100, 'shape': 784, 'std_value': 255}
X_train, X_test, workspace = mnist.load_data(workspace='examples/rbm/rbm' +
                                             str(rbmid),
                                             nb_rbm=rbmid,
                                             checkpoint_steps=6000,
                                             **pvalues)

m = Energy('rbm' + str(rbmid), sys.argv)

out_dim = [1000, 500, 250, 30]
m.add(RBM(out_dim, sampling='gaussian', w_std=0.1, b_wd=0))

sgd = SGD(lr=0.001, decay=0.0002, momentum=0.8)
topo = Cluster(workspace)
m.compile(optimizer=sgd, cluster=topo)
m.fit(X_train, alg='cd', nb_epoch=6000)
#result = m.evaluate(X_test, test_steps=100, test_freq=500)
Example #4
0
#* specific language governing permissions and limitations
#* under the License.
#*
#*************************************************************/

import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from singa.model import *
from examples.datasets import mnist

# Sample parameter values for Autoencoder example
rbmid = 4
pvalues = {'batchsize': 100, 'shape': 784, 'std_value': 255}
X_train, X_test, workspace = mnist.load_data(
    workspace='examples/rbm/autoencoder',
    nb_rbm=rbmid + 1,
    checkpoint_steps=6000,
    **pvalues)

m = Sequential('autoencoder', sys.argv)

hid_dim = [1000, 500, 250, 30]
m.add(Autoencoder(hid_dim, out_dim=784, activation='sigmoid',
                  param_share=True))

agd = AdaGrad(lr=0.01)
topo = Cluster(workspace)
m.compile(loss='mean_squared_error', optimizer=agd, cluster=topo)
m.fit(X_train, alg='bp', nb_epoch=12200, with_test=True)
result = m.evaluate(X_test, test_steps=100, test_freq=1000)
#* KIND, either express or implied.  See the License for the
#* specific language governing permissions and limitations
#* under the License.
#*
#*************************************************************/


import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__),'..'))
from singa.model import *
from examples.datasets import mnist

# Sample parameter values for Mnist MLP example
pvalues = {'batchsize' : 64, 'shape' : 784,
           'std_value' : 127.5, 'mean_value' : 127.5}
X_train, X_test, workspace = mnist.load_data(**pvalues)

m = Sequential('mlp', argv=sys.argv)

m.add(Dense(2500, init='uniform', activation='tanh'))
m.add(Dense(2000, init='uniform', activation='tanh'))
m.add(Dense(1500, init='uniform', activation='tanh'))
m.add(Dense(1000, init='uniform', activation='tanh'))
m.add(Dense(500,  init='uniform', activation='tanh'))
m.add(Dense(10, init='uniform', activation='softmax'))

sgd = SGD(lr=0.001, lr_type='step')
topo = Cluster(workspace)
m.compile(loss='categorical_crossentropy', optimizer=sgd, cluster=topo)

''' For doing test only, normally users sets checkpoint path