Layers are subclasses of abstract class Layer, with implementing functions forward(), backward(), save(), and load().
Gradient stepping(parameter update) and working out downstream gradient are all implemented in backward().
Loader and Loss are all using polymorphism.
Look at main.cpp to get informed how to instantialize a model and train it.
Features are passed in vector<vector<DataType>>.
I've defined the DataType as float in public.h. You can change it to double if you like.
The outside vector is the batch, and the inner is the feature vector.
Features of different layer are in different shape. To get to passing through layer, they are all set to a 1-d vector as return value(batch_size * viewed_length).
The parameters will be saved after every training epoch.
A model's save call will sequencely call every layer's save.
Same to load, which must be called after the whole model is instantialized.
各层是抽象类Layer的子类,实现了forward()、backward()、save()和load()函数。
梯度下降(参数更新)和下游梯度计算均在backward()中实现。
数据加载器和损失函数均使用多态实现。
查看main.cpp以了解如何实例化模型并进行训练。
特征以vector<vector<DataType>>的形式传递。
我在public.h中将DataType定义为float。如果愿意,你可以将其改为double。
外层向量表示批次,内层向量表示特征。
不同层的特征具有不同的形状。为了能使特征在各层间传递,它们在返回时都被设置为一维向量(批次大小 * 展平后长度)。
每个训练周期结束后都会保存参数。
调用模型的save会依次调用每一层的save。
load也是如此。注意load必须在整个模型实例化之后调用。