Skip to content

mematrix/caffe-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Caffe-rs

GitHub License

Rust Rust - Nightly Rust - Stable Minimum

Toolchain Required

With no unstable feature enabled, this project needs a toolchain version >=1.51.0 to be built.

Build

cd path/to/caffe-rs
cargo build

Usage

Register custom layer

The library exports two macros:

  • register_layer_class! which is used to register the Layer class which impls the trait caffe_rs::layer::CaffeLayer<T> and has a public fn names new with a single caffe_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 the test:
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;

License

Caffe-rs is released under the BSD 2-Clause license that is the same as the Caffe project.

About

A rust version of the Caffe library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published