Git Product home page Git Product logo

caffe2_bhtsne's Introduction

Caffe2 TSNE example

What's this?

Caffe2 is an open-source deep learning library that is designed to be modular in nature. For many deep learning libraries, especially those earlier ones such as Caffe, one either only sticks with only the operators provided by the framework, or has to do non-trivial modifications to the codebase in order to compile custom implementation into the library.

This repository gives an example on how you can develop your custom operators and functionalities independent from the main Caffe2 codebase, and "plug-in" these into Caffe2 by dynamically loading your operators. The benefits are that

  • You can maintain your own library at your own pace.
  • You have a better control over the codebase.
  • It becomes easier to share code instead of having to merge and constantly upstream changes from the main Caffe2 library.

How should I use this?

Imagine you are developing a new deep learning algorithm, and in your method you have some new layers / operators that existing frameworks do not cover. At the same time, you still want to take advantage of the existing framework functionalities. What you can do is to write them as standard Caffe2 operators, build your code as a shared library, and then load it either from C++ or Python.

We will demonstrate the mechanism using a popular software package, T-SNE, and show how one can create a Caffe2 operator that produces T-SNE embeddings from an input Tensor, living under the Caffe2 runtime.

Getting started

To build the library, install the most recent version of Caffe2. Then, follow the standard cmake installation protocol. Usually what people do with cmake is like mkdir build && cd build && cmake .. && make.

To run the ipython notebook, simply do ipython notebook in the root folder of this repository. If your Caffe2 install is not in the default python path, you might need to add PYTHONPATH=/path/to/your/caffe2/install before the ipython command. You will also need to download the MNIST dataset here.

caffe2_bhtsne's People

Contributors

yangqing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

caffe2_bhtsne's Issues

Compile error on Raspbian

Some error occurs while running the building script on Raspbian.

In file included from /home/huzi/caffe2/caffe2/contrib/gloo/allreduce_ops.cc:5:0:
/home/huzi/caffe2/third_party/gloo/gloo/allreduce_ring_chunked.h:38:68: note: mismatched types ‘std::initializer_list<Tp>’ and ‘long unsigned int’s
chunkSize
= std::max(minSize, (count_ + chunks_ - 1) / chunks_);
^
In file included from /usr/include/c++/4.9/algorithm:62:0,
from /home/huzi/caffe2/caffe2/contrib/gloo/allreduce_ops.h:3,
from /home/huzi/caffe2/caffe2/contrib/gloo/allreduce_ops.cc:1:
/usr/include/c++/4.9/bits/stl_algo.h:3454:5: note: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _$ompare)
max(initializer_list<_Tp> __l, Compare comp)
^
/usr/include/c++/4.9/bits/stl_algo.h:3454:5: note: template argument deduction/substitution failed:
In file included from /home/huzi/caffe2/caffe2/contrib/gloo/allreduce_ops.cc:5:0:
/home/huzi/caffe2/third_party/gloo/gloo/allreduce_ring_chunked.h:38:68: note: mismatched types ‘std::initializer_list<Tp>’ and ‘long unsigned int’
chunkSize
= std::max(minSize, (count
+ chunks
- 1) / chunks
);
^
caffe2/CMakeFiles/Caffe2_CPU.dir/build.make:65: recipe for target 'caffe2/CMakeFiles/Caffe2_CPU.dir/contrib/gloo/allreduce_ops.cc$o' failed

I suspect it to be a compiler relevant error but I've tried to upgrade to the latest version of compiling tools. Please check.

linking in compilation

In the Makefile - should CAFFE2_LINKFLAGS be used in the linking step?

I am trying to compile a custom operator for GPU, would it be possible to have an example of GPU compilation and use?

make: *** [libcaffe2_tsne.so] Error 1 - with Undefined symbols

  1. Follow the instruction to "make" after following adaptation to my environment.
  • Remove "" at CAFFE2_LINKFLAGS and Add $(CAFFE2_LINKFLAGS) to build SHARED_LIB

CAFFE2_LINKFLAGS = "-L$(CAFFE2_LIB) -lCaffe2_CPU -lglog -lgflags -lprotobuf"

$(SHARED_LIB): $(OBJECTS)
$(CXX) -shared -o $(SHARED_LIB) $(CAFFE2_LINKFLAGS) $(OBJECTS)

  1. But "make Error" with 5 Undefined symbols:
    $ make
    c++ -shared -o libcaffe2_tsne.so -L/usr/local/lib -lCaffe2_CPU -lglog -lgflags -lprotobuf src/tsne_op.o bhtsne/sptree.o bhtsne/tsne.o
    Undefined symbols for architecture x86_64:
    "caffe2::MessageLogger::MessageLogger(char const*, int, int)", referenced from:
    caffe2::Operatorcaffe2::CPUContext::Run(int) in tsne_op.o
    caffe2::Tensorcaffe2::CPUContext const& caffe2::OperatorBase::Input<caffe2::Tensorcaffe2::CPUContext >(int) in tsne_op.o
    caffe2::Tensorcaffe2::CPUContext* caffe2::Blob::GetMutable<caffe2::Tensorcaffe2::CPUContext >(bool*) in tsne_op.o
    "caffe2::MessageLogger::~MessageLogger()", referenced from:
    caffe2::Operatorcaffe2::CPUContext::Run(int) in tsne_op.o
    caffe2::Tensorcaffe2::CPUContext const& caffe2::OperatorBase::Input<caffe2::Tensorcaffe2::CPUContext >(int) in tsne_op.o
    caffe2::Tensorcaffe2::CPUContext* caffe2::Blob::GetMutable<caffe2::Tensorcaffe2::CPUContext >(bool*) in tsne_op.o
    "caffe2::FLAGS_caffe2_keep_on_shrink", referenced from:
    void caffe2::Tensorcaffe2::CPUContext::Resize<int, int>(int, int) in tsne_op.o
    "caffe2::FLAGS_caffe2_report_cpu_memory_usage", referenced from:
    caffe2::CPUContext::New(unsigned long) in tsne_op.o
    caffe2::CPUContext::Delete(void*) in tsne_op.o
    "caffe2::FLAGS_caffe2_max_keep_on_shrink_memory", referenced from:
    void caffe2::Tensorcaffe2::CPUContext::Resize<int, int>(int, int) in tsne_op.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [libcaffe2_tsne.so] Error 1

  2. Looks like they are already in the caffe2, Not sure why 5 Undefined symbols !
    What am I missing ?

./core/logging.cc:MessageLogger::MessageLogger(const char *file, int line, int severity)
./core/tensor.h:CAFFE2_DECLARE_bool(caffe2_keep_on_shrink);
./core/tensor.cc: CAFFE2_DEFINE_bool( caffe2_keep_on_shrink,...
./core/context.h:CAFFE2_DECLARE_bool(caffe2_report_cpu_memory_usage);
./core/context.cc: CAFFE2_DEFINE_bool(caffe2_report_cpu_memory_usage, ...
./core/tensor.h:CAFFE2_DECLARE_int64(caffe2_max_keep_on_shrink_memory);
./core/tensor.cc: CAFFE2_DEFINE_int64(caffe2_max_keep_on_shrink_memory,...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.