-
Notifications
You must be signed in to change notification settings - Fork 109
02. Getting Started
Neural networks created by ConvNetSharp use objects called Volume as input and output.
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.
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]
Volume data can be float or double. Volumes are generic to handle different data types.
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.
// 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))