Get started with convnetjs CDN

MIT licensed

ConvNetJS: Lightweight web library for real-time image classification via convolutional neural networks.

Tags:
  • machine
  • learning
  • AI
  • convnet
  • neural
  • network
  • networks
  • convolutional
  • deep

Stable version

Copied!

How to start using convnetjs CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with convnetjs CDN - cdnhub.io</title>
  <script src="https://cdn.cdnhub.io/convnetjs/0.3.0/convnet-min.js"></script>
</head>
<body>
  <script>
    // Define the input shape and number of output classes
    const inputShape = [28, 28, 1];
    const numClasses = 10;

    // Load the MNIST dataset
    const net = new NeuralNetwork();
    net.addInput('input', inputShape);

    net.addLayer('conv1', new ConvLayer({
      input: 'input',
      output: 32,
      kernelSize: 3,
      padding: 'same',
      activation: 'relu'
    }));

    net.addLayer('pool1', new MaxPoolingLayer({ input: 'conv1.output', poolSize: [2, 2] }));

    net.addLayer('conv2', new ConvLayer({
      input: 'pool1.output',
      output: 64,
      kernelSize: 3,
      padding: 'same',
      activation: 'relu'
    }));

    net.addLayer('pool2', new MaxPoolingLayer({ input: 'conv2.output', poolSize: [2, 2] }));

    net.addLayer('flatten', new FlattenLayer({ input: 'pool2.output' }));

    net.addLayer('fc1', new FullyConnectedLayer({
      input: 'flatten.output',
      output: 128,
      activation: 'relu'
    }));

    net.addLayer('output', new SoftmaxLayer({ input: 'fc1.output', numClasses }));

    net.addOutput('output');

    net.loadWeights('https://cdn.cdnhub.io/convnetjs/examples/mnist/mnist_model_data.json');

    // Preprocess the input image and predict the output class
    const inputImage = new Tensor(inputShape, 'float32');
    inputImage.set(0.1); // Set all pixels to 0.1 for simplicity

    net.predict(inputImage).then(output => {
      const predictedClass = output.argMax();
      console.log(`Predicted class: ${predictedClass}`);
    });
  </script>
</body>
</html>
Copied!
Copied!

All versions