With no unstable feature enabled, this project needs a toolchain version >=1.51.0
to be built.
cd path/to/caffe-rs
cargo build
The library exports two macros:
register_layer_class!
which is used to register the Layer class which impls the traitcaffe_rs::layer::CaffeLayer<T>
and has a public fn namesnew
with a singlecaffe_rs::proto::caffe::LayerParameter
param.
use caffe_rs::proto::caffe::LayerParameter;
use caffe_rs::blob::BlobType;
use caffe_rs::layer::CaffeLayer;
use std::marker::PhantomData;
struct TestLayer<T: BlobType> {
phantom: PhantomData<T>,
}
impl<T: BlobType> CaffeLayer for TestLayer<T> {
type DataType = T;
// Impl the necessary functions.
}
impl<T: BlobType> TestLayer<T> {
pub fn new(_param: &LayerParameter) -> Self {
TestLayer {
phantom: PhantomData
}
}
}
// Note: the name does not contains the trailing 'Layer'.
register_layer_class!(Test);
register_layer_creator!
which is used to register the custom layer creator function. The creator signature is defined as likes thetest
:
use caffe_rs::proto::caffe::LayerParameter;
use caffe_rs::layer::SharedLayer;
use caffe_rs::blob::BlobType;
fn test<T: BlobType>(p: &LayerParameter) -> Rc<RefCell<Layer<T>>> {
unimplemented!();
}
// register `TestLayer` with a creator.
register_layer_creator!(Test, test);
And important: you need import the dependency crate paste
to use the register macros.
On your Cargo.toml
:
[dependencies]
paste = "1"
and import the macro on your crate root (src/lib.rs
or src/main.rs
):
#[macro_use] extern crate paste;
Caffe-rs is released under the BSD 2-Clause license that is the same as the Caffe project.