Skip to content

Instantly share code, notes, and snippets.

@ilyakava
Created September 8, 2017 13:36
Show Gist options
  • Save ilyakava/c3cf725a0c250155d18ebbfe438e0c3f to your computer and use it in GitHub Desktop.
Save ilyakava/c3cf725a0c250155d18ebbfe438e0c3f to your computer and use it in GitHub Desktop.
// http://cs.stanford.edu/people/karpathy/convnetjs//demo/classify2d.html
(function xor_data(){
data = [];
labels = [];
data.push([0 , 0 ]); labels.push(0);
data.push([1 , -1 ]); labels.push(0);
data.push([0 , -1 ]); labels.push(1);
data.push([1 , 0 ]); labels.push(1);
N = labels.length;
})()
// small network
layer_defs = [];
layer_defs.push({type:'input', out_sx:1, out_sy:1, out_depth:2});
layer_defs.push({type:'fc', num_neurons:2, activation: 'relu'});
layer_defs.push({type:'softmax', num_classes: 2});
net = new convnetjs.Net();
net.makeLayers(layer_defs);
trainer = new convnetjs.SGDTrainer(net, {learning_rate:0.05, momentum:0.1, batch_size:4, l2_decay:0.001});
// inspect, index 1
net.layers
// orig network
layer_defs = [];
layer_defs.push({type:'input', out_sx:1, out_sy:1, out_depth:2});
layer_defs.push({type:'fc', num_neurons:6, activation: 'tanh'});
layer_defs.push({type:'fc', num_neurons:2, activation: 'tanh'});
layer_defs.push({type:'softmax', num_classes:2});
net = new convnetjs.Net();
net.makeLayers(layer_defs);
trainer = new convnetjs.SGDTrainer(net, {learning_rate:0.01, momentum:0.1, batch_size:10, l2_decay:0.001});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment