| CARVIEW |
Select Language
HTTP/2 200
date: Mon, 29 Dec 2025 18:05:21 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"e5b74f8784167f43ca067f74f383bb08"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com github.githubassets.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com marketplace-screenshots.githubusercontent.com/ copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com github.githubassets.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=a3HnErjiOaXVypWqSVB9rRDOSfSPTZGcwPzwBrSjOdlvDuALn2nMHU%2FwvsfZkzryDkLl0f6H%2FTECP9Y%2FZ%2FyEmMZ%2Fzd8sJc8ZNYJhXk0JZM3Ha5wBS6CFicJ3NSLpiCDnEDQ2wx1Iia8ifi%2BjzUpf0WBdt%2FA98aQClAEzd4RXSGkfK%2BkytcfmN%2FfsG65CTn3ShotI99ENDpyx1LHNQZ021HCeyHI4SbxEMzaN3ZBi42pgB1mFe1eGoSa3CMJ1Gs4eIdNBhg2ZsNerSI%2Bheo7rKA%3D%3D--mUnDNkv2wYp5kWxG--AaydSNeJEzJwTkOMhDdw7Q%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.394909962.1767031520; Path=/; Domain=github.com; Expires=Tue, 29 Dec 2026 18:05:20 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Tue, 29 Dec 2026 18:05:20 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: AFD2:382597:66260CB:7A4529B:6952C2E0
Development · BVLC/caffe Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Development
Domenic Curro edited this page Feb 9, 2016
·
24 revisions
- Add a class declaration for your layer to
include/caffe/layers/your_layer.hpp.- Include an inline implementation of
typeoverriding the methodvirtual inline const char* type() const { return "YourLayerName"; }replacingYourLayerNamewith your layer's name. - Implement the
{*}Blobs()methods to specify blob number requirements; see /caffe/include/caffe/layers.hpp to enforce strict top and bottom Blob counts using the inline{*}Blobs()methods. - Omit the
*_gpudeclarations if you'll only be implementing CPU code.
- Include an inline implementation of
- Implement your layer in
src/caffe/layers/your_layer.cpp.- (optional)
LayerSetUpfor one-time initialization: reading parameters, fixed-size allocations, etc. -
Reshapefor computing the sizes of top blobs, allocating buffers, and any other work that depends on the shapes of bottom blobs -
Forward_cpufor the function your layer computes -
Backward_cpufor its gradient (Optional -- a layer can be forward-only)
- (optional)
- (Optional) Implement the GPU versions
Forward_gpuandBackward_gpuinlayers/your_layer.cu. - If needed, declare parameters in
proto/caffe.proto, using (and then incrementing) the "next available layer-specific ID" declared in a comment abovemessage LayerParameter - Instantiate and register your layer in your cpp file with the macro provided in
layer_factory.hpp. Assuming that you have a new layerMyAwesomeLayer, you can achieve it with the following command:
INSTANTIATE_CLASS(MyAwesomeLayer);
REGISTER_LAYER_CLASS(MyAwesome);
- Note that you should put the registration code in your own cpp file, so your implementation of a layer is self-contained.
- Optionally, you can also register a Creator if your layer has multiple engines. For an example on how to define a creator function and register it, see
GetConvolutionLayerincaffe/layer_factory.cpp. - Write tests in
test/test_your_layer.cpp. Usetest/test_gradient_check_util.hppto check that your Forward and Backward implementations are in numerical agreement.
If you want to write a layer that you will only ever include in a test net, you do not have to code the backward pass. For example, you might want a layer that measures performance metrics at test time that haven't already been implemented.
Doing this is very simple. You can write an inline implementation of Backward_cpu (or Backward_gpu) together with the definition of your layer in include/caffe/your_layer.hpp that looks like:
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {
NOT_IMPLEMENTED;
}
The NOT_IMPLEMENTED macro (defined in common.hpp) throws an error log saying "Not implemented yet". For examples, look at the accuracy layer (accuracy_layer.hpp) and threshold layer (threshold_layer.hpp) definitions.
Clone this wiki locally
You can’t perform that action at this time.