mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-06 01:34:22 +00:00
Update README
This commit is contained in:
69
README.md
69
README.md
@@ -15,7 +15,7 @@ Convolutional Neural Network inference library running on CUDA.
|
|||||||
- [x] Sigmoid activation
|
- [x] Sigmoid activation
|
||||||
- [x] ReLU activation
|
- [x] ReLU activation
|
||||||
- [x] Softmax activation
|
- [x] Softmax activation
|
||||||
- [ ] Load weights from file
|
- [x] Load weights from file
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -39,3 +39,70 @@ make
|
|||||||
make test_main
|
make test_main
|
||||||
./test/test_main
|
./test/test_main
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Create Layers and Model
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
CUDANet::Model *model =
|
||||||
|
new CUDANet::Model(inputSize, inputChannels, outputSize);
|
||||||
|
|
||||||
|
// Conv2d
|
||||||
|
CUDANet::Layers::Conv2d *conv2d = new CUDANet::Layers::Conv2d(
|
||||||
|
inputSize, inputChannels, kernelSize, stride, numFilters,
|
||||||
|
CUDANet::Layers::Padding::VALID,
|
||||||
|
CUDANet::Layers::ActivationType::NONE
|
||||||
|
);
|
||||||
|
|
||||||
|
if (setWeights) {
|
||||||
|
conv2d->setWeights(getConv1Weights().data());
|
||||||
|
}
|
||||||
|
model->addLayer("conv1", conv2d);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sequential and Functional API
|
||||||
|
|
||||||
|
Run prediction by passing the input through the layers in the order they have been added.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
std::vector<float> input = {...};
|
||||||
|
model->predict(input.data());
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to use more complex forward pass, using `Concat` or `Add` layers, you can subclass the model class and override the default `predict` function
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
class MyModel : public CUDANet::Model {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
float* MyModel::predict(const float* input) {
|
||||||
|
float* d_input = inputLayer->forward(input);
|
||||||
|
|
||||||
|
d_conv1 = getLayer("conv1")->forward(d_input);
|
||||||
|
d_conv2 = getLayer("conv2")->forward(d_input);
|
||||||
|
|
||||||
|
d_output = concatLayer->forward(d_conv1, d_conv2);
|
||||||
|
|
||||||
|
return outputLayer->forward(d_input);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Load Pre-trained Weights
|
||||||
|
|
||||||
|
CUDANet uses format similar to safetensors to load weights and biases.
|
||||||
|
|
||||||
|
```
|
||||||
|
[int64 header size, header, tensor values]
|
||||||
|
```
|
||||||
|
|
||||||
|
where `header` is a csv format
|
||||||
|
|
||||||
|
```
|
||||||
|
<tensor_name>,<tensor_size>,<tensor_offset>
|
||||||
|
```
|
||||||
|
|
||||||
|
To load weights call `load_weights` function on Model object.
|
||||||
|
|
||||||
|
To export weights from pytorch you can use `tools/export_model_weights.py` script
|
||||||
Reference in New Issue
Block a user