Skip to content

02. Getting Started

Cédric edited this page Jul 7, 2018 · 3 revisions

Neural networks created by ConvNetSharp use objects called Volume as input and output.

Volume

A volume is a 4-dimensions matrix (It is often called tensor in other libraries).
A volume is defined by a type (float/double) and a shape.

Shape

The shape specifies the size of each volume's dimensions.
Shapes have this format: [Width, Height, Class, Batch Size]

e.g.
A volume used to store 10 640 x 480 color images would be: [640, 480, 3, 10]. The third dimension is 3 to store each RGB channels.

A volume used to store the classification (among 20 categories) of 1048 items would be: [1, 1, 20, 1048]

How to create a Volume

Single/double precision

Volume data can be float or double. Volumes are generic to handle different data types.

CPU/GPU

Volume data can be stored on the host memory or on the GPU.

BuilderInstance<T>.Volume singleton is used to access a volume builder. This singleton is used globaly to create new volumes. It is be default set to the CPU (allocated on host memory).

You can set it to the GPU version at the beginning of your program this way:

BuilderInstance<float>.Volume = new ConvNetSharp.Volume.GPU.Single.VolumeBuilder();
// Or
BuilderInstance<double>.Volume = new ConvNetSharp.Volume.GPU.Double.VolumeBuilder();

GPU volume will be first allocated on the host and then transferred to GPU memory when needed.

Volume creation

// CPU
var volume1 = BuilderInstance<double>.Volume.From(new[] { 1.0, 2.0, 3.0, 4.0 },
                                                  new Shape(2, 2, 1, 1))

// GPU
BuilderInstance<double>.Volume = new ConvNetSharp.Volume.GPU.Double.VolumeBuilder();
var volume2 = BuilderInstance<double>.Volume.From(new[] { 1.0, 2.0, 3.0, 4.0 },
                                                  new Shape(2, 2, 1, 1))
Clone this wiki locally