Giter Club home page Giter Club logo

mycaffe's Introduction

Welcome to MyCaffe!

❤️ Sponsor to help us keep innovating for you!

MyCaffe is a complete C# re-write of the native C++ CAFFE[1] open source project.

MyCaffe allows Windows C# software developers to use and expand deep learning solutions in their native C# language. All layers except for a few, and nearly every unit test are now provided in C#. Windows programmers can now write their own custom layers in the C# language, yet still enjoy the benefit of an efficient deep learning architecture that supports multi-GPU training on up to 8 headless GPU's using NCCL 1.3.4 ('Nickel').

Now you can create custom layers for MyCaffe in native C# using the full extent of the Windows .NET Framework!

We have made a large effort to keep the MyCaffe C# code true to the original CAFFE[1] down to comment with the hope of making it even easier to extend the general CAFFE architecture for all. In addition, MyCaffe uses the same Proto Buffer file format for solver and model descriptions and model binary files allowing an easy exchange between the MyCaffe and C++ CAFFE platforms.

Most of the MyCaffe C# code is very similar to the C++ CAFFE code, for our goal is to extend the CAFFE platform to C# programmers, while maintaining compatibility with CAFFE's solver descriptions, model descriptions and binary weight format.

The C# based MyCaffe open-source project is independently maintained by SignalPop LLC and made available under the Apache 2.0 License.

Supported Development Environments:

* Visual Studio 2022 & CUDA 11.8.0 & cuDnn 8.8.0 (current test pass)
* Visual Studio 2022 & CUDA 12.2.2 & cuDnn 8.9.5

NOTE: Compute 5.3 and above required for CUDA 11.8.0/cuDNN 8.8.0 when using __half sized memory. NOTE: Only compute 5.2 and above are supported in CUDA 11.8.0/cuDNN 8.8.0 due to 5.1 and lower compute phase-out in CUDA 11.8.

For detailed notes on building MyCaffe, please see the INSTALL.md file.

IMPORTANT: The open-source MyCaffe project on GitHub is considered 'pre-release' and may have bugs. When you find bugs or other issues, please report them here - or better yet, get involved and propose a fix!

We have several new models supported by MyCaffe with the train_val and solution prototxt ready to go:

  • Domain-Adversarial Neural Networks (DANN) as described in [2] with support for source and target datasets.
  • ResNet-56 on the Cifar-10 dataset as described in [3].
  • Deep convolutional auto-encoder neural networks with pooling as described in [4].
  • Policy Gradient Reinforcement Learning networks as described in [5].
  • Recurrent Learning of Char-RNN as described in [8] and [9].
  • Neural Style Transfer as described in [10] and [11] using the VGG model described in [12]
  • Deep Q-Learning [14][15] with Noisy-Net [16] and Prioritized Replay Buffer [17]
  • Siamese Network [18][19]
  • Deep Metric Learning with Triplet Network [20][21]
  • Single-Shot Multi-Box (SSD) Object Detection [22][23]
  • Seq2Seq with Attention [24][25][26] (see MyCaffe-Samples at https://github.com/MyCaffe/MyCaffe-Samples/tree/master/Seq2Seq)
  • Transformer Models (ChatGPT and GPT) [24][27]
  • Temporal Fusion Transformer Models [28][29]

For more information on the MyCaffe implementation of Policy Gradient Reinforcement Learning, see MyCaffe: A Complete C# Re-Write of Caffe with Reinforcement Learning by D. Brown, 2018.

MyCaffe now supports the Arcade-Learning-Environment by [6] based on the Stella Atari-2600 emulator from [7], via the AleControl from SignalPop.
For more information, get the AleControl on Nuget, or visit the AleControl on Github.

License and Citation

MyCaffe is released under the [Apache License 2.0](https://github.com/MyCaffe/MyCaffe/blob/master/LICENSE).

Please cite MyCaffe in your publications and projects if MyCaffe helps you in your research or applications:


	@article 
	{
	  brown2018mycaffe,
	  Author = {Brown, David W.}
	  Journal = {arXiv preprint arXiv:1810.02272},
	  Title = {MyCaffe: A Complete C# Re-Write of Caffe with Reinforcement Learning}
	  Year = {2018}
	  Link = {https://arxiv.org/abs/1810.02272}
	}

Donate

To support this project, kindly send donations to:
ETH (Ethereum): 0xb0d26F749FC3aE8cadb29bA4E224CA4C9Af99e20

References

[1] [CAFFE: Convolutional Architecture for Fast Feature Embedding](https://arxiv.org/abs/1408.5093) by Yangqing Jai, Evan Shelhamer, Jeff Donahue, Sergey Karayev, Jonathan Long, Ross Girshick, Sergio Guadarrama, and Trevor Darrell, 2014.

[2] Domain-Adversarial Training of Neural Networks by Yaroslav Ganin, Evgeniya Ustinova, Hana Ajakan, Pascal Germain, Hugo Larochelle, François Laviolette, Mario Marchand, and Victor Lempitsky, 2015.

[3] ResNet 20/32/44/56/110 for CIFAR10 with caffe by Yihui He, 2016.

[4] A Deep Convolutional Auto-Encoder with Pooling - Unpooling Layers in Caffe by Volodymyr Turchenko, Eric Chalmers and Artur Luczac, 2017.

[5] Deep Reinforcement Learning: Pong from Pixels by Andrej Karpathy, 2015.

[6] The Arcade Learning Environment: An Evaluation Platform for General Agents by Marc G. Bellemare, Yavar Naddaf, Joel Veness and Michael Bowling, 2012-2013. Source code available on GitHub at mgbellemare/Arcade-Learning-Envrionment

[7] Stella - A multi-platform Atari 2600 VCS emulator by Bradford W. Mott, Stephen Anthony and The Stella Team, 1995-2018 Source code available on GitHub at stella-emu/stella

[8] The Unreasonable Effectiveness of Recurrent Neural Networks by Andrej Karpathy, 2015.

[9] adepierre/caffe-char-rnn Github by adepierre, 2017.

[10] A Neural Algorithm of Artistic Style Leon A. Gatys, Alexander S. Ecker, Matthias Bethge, 2015, arXiv:1508:06576

[11] ftokarev/caffe Github by ftokarev, 2017

[12] Very Deep Convolutional Networks for Large-Scale Image Recognition by K. Simonyan, A. Zisserman, arXiv:1409.1556

[14] GitHub: Google/dopamine licensed under the Apache 2.0 License;

[15] Dopamine: A Research Framework for Deep Reinforcement Learning by Pablo Samuel Castro, Subhodeep Moitra, Carles Gelada, Saurabh Kumar, Marc G. Bellemare, 2018, arXiv:1812.06110

[16] Noisy Networks for Exploration by Meire Fortunato, Mohammad Gheshlaghi Azar, Bilal Piot, Jacob Menick, Ian Osband, Alex Graves, Vlad Mnih, Remi Munos, Demis Hassabis, Olivier Pietquin, Charles Blundell, Shane Legg, 2018, arXiv:1706.10295

[17] Prioritized Experience Replay by Tom Schaul, John Quan, Ioannis Antonoglou, David Silver, 2016, arXiv:1511.05952

[18] Siamese Network Training with Caffe by Yangqing Jia and Evan Shelhamer, BAIR.

[19] Siamese Neural Network for One-shot Image Recognition by G. Koch, R. Zemel and R. Salakhutdinov, ICML 2015 Deep Learning Workshop, 2015.

[20] Deep metric learning using Triplet network by E. Hoffer and N. Ailon, 2014, 2018, arXiv:1412.6622.

[21] In Defense of the Triplet Loss for Person Re-Identification by A. Hermans, L. Beyer, and B. Leibe, 2017, arXiv:1703.07737v2.

[22] SSD: Single Shot MultiBox Detector by Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy, Scott Reed, Cheng-Yang Fu, Alexander C. Berg, 2016.

[23] GitHub: SSD: Single Shot MultiBox Detector, by weiliu89/caffe, 2016

[24] Attention Is All You Need by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin, 2017, arXiv:1706:03762

[25] GitHub: mashmawy/Seq2SeqLearn by Mohamed Ashmawy, 2017

[26] GitHub: HectorPulido/Chatbot-seq2seq-C- by Hector Pulido, 2018

[27] GitHub: devjwsong/transformer-translator-pytorch by Jaewoo (Kyle) Song, 2021, GitHub

[28] Temporal Fusion Transformers for Interpretable Multi-horizon Time Series Forecasting by Bryan Lim, Sercan O. Arik, Nicolas Loeff and Tomas Pfister, 2019, arXiv:1912.09363

[29] GitHub: PlaytikaOSS/tft-torch by Playtika Research, 2021, GitHub

For more information on the C++ CAFFE open-source project, please see the following link.

mycaffe's People

Contributors

zorodervoncodier 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  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  avatar  avatar  avatar  avatar

Watchers

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

mycaffe's Issues

Can I use it with monodevelop on linux?

Hi,

I am struggling finding caffe bindings for mono, however this project is even better. Unfortunately I am not speaking about windows. But as far as I concerned, visual studio projects can be compiled with monodevelop.

So can you clarify this?

Thanks

MyCaffeControl.Clone() Null Exception

Hi again,

I've been playing with ImageClassificationBarebones example. I would like to use the MyCaffeControl object I created, take the network that has been trained with the Solver, and Run() the model with a SimpleDatum created from one of the MNIST images.
Where I'm confused is by how I set the Phase of the Net to 'RUN'

I thought of copying or Cloning the MyCaffeControl or the Net itself. Cloning the MyCaffeControl currently returns a Null object error and there isn't an option for Cloning the Net(), only the NetParameters. The cloning the parameters means I have to copy the weights of the model to the CPU and back to GPU.

What seems to happen at the moment is when I call Clone on MyCaffeControl, internally it creates the internal objects correctly until it gets to caffe.Load().
One of the arguments of this function is a ProjectEx m_project which in my case is Null because I'm not using a database.

is there also a tidy way to share the Net() for Running?

All the best,

Yy

Two blobs created have the same data handle

I tried creating 2 Blobs and adding them together, just to understand how the system works.

But I find the gpu_data handle = 2 for both the Blob I created. The result is that the Input1's value is added to both sides of the operation. I think.

        public Blob<float> CuSca(float Input1)
        {
            var myDevice = new CudaDnn<float>(0, DEVINIT.CURAND);
            var myLog = new Log("");
            var inputArray = new float[1];
            inputArray[0] = Input1;
            var myData = new SimpleDatum(1, 1, 1, inputArray, 0, 1);
            return new Blob<float>(myDevice, myLog, myData, true, true, false);
        }

        public Blob<float> TheAdd(Blob<float> Input1, Blob<float> Input2)
        {
            Input1.Cuda.add(Input1.count(), Input1.gpu_data, Input2.gpu_data, Input1.gpu_data);
            return Input1;
        }

        public float[] myBlobAdditonTest(float input1, float input2)
        {
            var scalar1 = CuSca(input1);
            Console.WriteLine("Scalar 1 gpu_data = {0}", scalar1.gpu_data);
            var scalar2 = CuSca(input2);
            Console.WriteLine("Scalar 2 gpu_data = {0}", scalar2.gpu_data);
            var cudaRes = TheAdd(scalar1, scalar2).Clone();
            return cudaRes.Cuda.GetMemoryFloat(cudaRes.gpu_data);
        }

        public void MyTest()
        {
            var myResult = myBlobAdditonTest(1.0f, 0.5f)[0];
            Console.WriteLine(myResult.ToString());
        }

I've tried this while putting the same CudaDNN Device and log object in both Blobs, but this doesn't make a difference. I've also tried creating a new output Blob for the result, but this makes no difference either.

How should this be done?

Thanks in advanced,

Yy

How to use pre-trained models to generate images?

Hello:
I can download all pre-trained models from NVIDIA for Stylegan3, for example: stylegan3-t-ffhqu-1024x1024.pkl
Then I can use the following Python code to generate images:
(stylegan3) C:\stylegan3>python gen_images.py --outdir=out --trunc=0.7 --seeds=600-605 --C:\stylegan3\stylegan3-t-ffhqu-1024x1024.pkl
The code can be downloaded from this URL:
https://github.com/NVlabs/stylegan3
Please advise on how I can do the job using the repo?

Guidance needed for setting up MemoryDataLayer

Hi,

I've been trying to set data into the layer pipeline. I tried the MemoryDataLayer but it threw an exception - '[there] are not enough datum to add'. Digging further I realized this was because the datum list count / the batch_size were unequal to or less than '1'.

I could set the batch size from the layer itself, but other channels couldn't be updated, which I think I understand. This meant that AddDatumVector expected 1,0,0,0 input shape. Example below:

class MemDataTest
{
    public static MemoryDataLayer<float> createMemDatalayer(CudaDnn<float>cuda, Log log)
    {
        // Create the parameters for the MemoryData itself
        var myMemParam = new MemoryDataParameter();
        myMemParam.label_type = LayerParameterBase.LABEL_TYPE.ONLY_ONE;
        myMemParam.batch_size = 1;
        myMemParam.channels = 1;
        myMemParam.height = 1;
        myMemParam.width = 60; // <- the true size of the data

        // Create layer parameter
        var mylayerParam = new LayerParameter(LayerParameter.LayerType.MEMORYDATA);
        mylayerParam.memory_data_param = myMemParam;

        // Create MemoryLayer itself
        var ramDataLayer = new MemoryDataLayer<float>(cuda, log, mylayerParam);
        return ramDataLayer;
    }

    public static List<Datum> DataSetter(CudaDnn<float> cuda, Log log)
    {
        // Setup input data values as an array of floats
        var myRamData = new float[60];

        for (int i = 0; i < myRamData.Length; i++)
        {
            myRamData[i] = 10;
        }

        // Set a shape for the data
        var dShape = new BlobProto(new List<int> { 1, 1, 1, 60 });
        var dBlob = new Blob<float>(cuda, log, dShape, false);
        dBlob.mutable_cpu_data = myRamData;
        var myDatumVec = new List<Datum>();
        myDatumVec.Add(dBlob.ToDatum());

        return myDatumVec;
    }

    public static MemoryDataLayer<float> DataInserter(MemoryDataLayer<float> myInputLayer, List<Datum> DatumVec)
    {
        Console.WriteLine("My input layer has a batch size of (0) and a width of {1}", myInputLayer.batch_size, myInputLayer.width);
        // The parameters haven't been read.
        // I can change the intended batch size here and it will take effect.
        myInputLayer.batch_size = 1;
        Console.WriteLine("My input layer has a batch size of (0) and a width of {1}", myInputLayer.batch_size, myInputLayer.width);
        // But I can't set the width or the other dimensions this way.
        // myInputLayer.width = 1;
        // Let's set the batch to '0' again.
        myInputLayer.batch_size = 0;
        //and we will get the first error '[there] are not enough datum to add'
        myInputLayer.AddDatumVector(DatumVec); // you can comment out this line
        myInputLayer.batch_size = 1;
        myInputLayer.AddDatumVector(DatumVec);
        return myInputLayer;
    }

    public static void TheTest()
    {
        var myDevice = new CudaDnn<float>(0, DEVINIT.CURAND);
        var myLog = new Log("Test");

        var memlayer = createMemDatalayer(myDevice, myLog);
        var data = DataSetter(myDevice, myLog);
        memlayer = DataInserter(memlayer, data);

    }
}

}

My IDE is a little strange sometimes but do you see something similar? Could I work with BlobCollections in the meanwhile?

Yy

compatibility with keras's cudnn saved model?

Hi
I'm new to machine learning and so far, I'n training a cudnn lstm model using tensor flow 1.13.1, question is, can i load a saved model using your library into c# and predict the result or not? if yes, is there an example for this or can you please guide me on how to do it?
if no, is there any solution for this? i am aware of tensorsharp but it looks like the version they use is tensor 1.12 with cuda 9 (tensor 1.13 uses cuda 10)

thanks

compute 5.0

How come the set or sumsqdiff function doesn't work?
test on device:
GeForce GTX 750 Ti (2.14 GB - P2P off; compute 5.0)
up
CUDA 11.1.1, cuDNN 8.0.5

immagine

Generate XML Documentation

Your code is well documented, but the info isn't currently available in the Nuget. With the next release a generated XML file would be very much appreciated.

Thanks again

Yy

File not found - nccl64_134.10.0.dll

When building the app, this error was returned:

1> File not found - nccl64_134.10.0.dll
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(5165,5): error MSB3073: The command "%systemroot%\System32\xcopy /s /y "C:\MyCaffeRepo\MyCaffe_0_10_2_124\packages\HDF5DotNet.x64.1.8.9\NativeBinaries*.*" "C:\MyCaffeRepo\MyCaffe_0_10_2_124\MyCaffe.app\bin\Debug"
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(5165,5): error MSB3073: %systemroot%\System32\xcopy /y C:\Data\Binaries\SS_Projects_Debug\nccl64_134.10.0.dll "C:\MyCaffeRepo\MyCaffe_0_10_2_124\MyCaffe.app\bin\Debug"" exited with code 4.

As a work around I copied the nccl from the installed version of the MyCaffe App, created to corresponding folder and copied it in.

Then I noticed that the names were different (nccl64_134.10.0.dll, not nccl64_134.12.0.dll), the one in the app being later. So I changed the Mycaffe.App.proj file to rename the final output accordingly. I suspect your local drive or build server is setup a certain way to benefit from the hardcoded folder

Pre-Trained Model Examples Neural Style Transfer

To see how to load a pre-trained model for Neural Style Transfer, do the following:

1.) Run the MyCaffe Test Application (MyCaffe.app project)
2.) Select the 'Test | Special Tests | Start Neural Style Transfer' menu.
3.) Use the default selections in the 'Neural Style Settings' dialog.

This will download the pre-trained VGG19 model and start training on the two images. When done a dialog will appear showing the style transfer.

Missing 'CudaDnnDll.8.dll' from nuget

Running the project, I get this error for a file that hasn't been installed. Other versions of the CudaDnnDll are installed so I guess it just wasn't included in the Nuget?

Failed to load 'C:\Program Files\vvvv\vvvv_gamma_2019.1.0-0975-gbe94390fc5\CudaDnnDll.8.dll'! at MyCaffe.common.CudaDnn1..ctor(Int32 nDeviceID, DEVINIT flags, Nullable1 lSeed, String strPath, Boolean bResetFirst, Boolean bEnableMemoryTrace) at MyCaffe.MyCaffeControl1.LoadLite(Phase phase, String strSolver, String strModel, Byte[] rgWeights, Boolean bResetFirst, String strStage, Boolean bEnableMemTrace)
at Main.ExploringmyCaffe2Application.UpdateDEBUG(PatchTracer tracer) in C:\Users\Igor\Documents\TFProjects_In-House\VLMyCaffe\ExploringmyCaffe2.vl:line 185248`

image

image

c# Reinforcment Tutorial request

I have read sample examples project code, the RL sample was in python code ,
need one in c#.can we expect other RL algos like a3c ,gail , rainbow, PPO in the future?

Simplest FORWARD example?

I'm trying to use this to run some pre-trained models.
I don't need training/databases .etc.

In Opencv.dnn I can simply do:

Net net = dnn::readNetFromCaffe("bvlc_googlenet.prototxt", "bvlc_googlenet.caffemodel");
Mat inputBlob = blobFromImage(some_img_Mat, 1, Size(224, 224),
                              Scalar(104, 117, 123));
net.setInput(inputBlob);
Mat what_I_want = net.forward();

Now my code stuck here:

	static void caftet()
        {
       

            SettingsCaffe settings = new SettingsCaffe();
            settings.GpuIds = "0";  // use GPU 0.
            var mcaf = new MyCaffeControl<float>(settings, new Log("Test"), new CancelEvent());

            mcaf.m_net = new Net<float>() //???

//I made m_cuda & m_net public.

            
        }

How can I load .caffemodel file s ( they are protobuf binaries) into Net<T>?
I searched the code I guess it's probably:

IXPersist.LoadSolverState(...), .caffemodel file as byte[] rgState.

But how can I make it link with MyCaffeControl.m_net?

Also need some explanation on how to fill input blob & get output blob manually.

Where to find file MyCaffe.basecode.dll?

Hello:
I want to see if I can run the repo.
So, I downloaded the source code, unzipped it, and open the solution by Visual Studio 2022.
But I found that there are 12 items not loadable.
When I tried to build the solution, I got 26 errors, the first one is like this:
Error CS0006 Metadata file 'D:\GitHubRepos\MyCaffe-master\MyCaffe.basecode\bin\Debug\MyCaffe.basecode.dll' could not be found
As I can't find the missing file: MyCaffe.basecode.dll
Let me know how I can fix the issue.
By the way, if I have some pre-trained keras model (.h5) and some json format data structure of the model, can I simply load the pre-trained model and make some prediction? If yes, I will give more details.
But, how to make the solution working?
I am using Windows 10 version (21H2), I have both VS2022 and VS2019.
Please advise!
BuildMyCaffeNOK

Float[] to Double[] bottle neck

Hi,
using the Simple Datum I can setup my data relatively easily. Most of it comes as a float collection of some kind, but to change the simpledatum I need to use a double array. This means converting all of the elements of the array which seems like a bottle neck. Given that the system allows for floats and doubles as input, can the Cuda stage when the data is copied to GPU just copy a float if its the set datatype?

Promotion Alliance

Hello from SciSharp,

we are striving for creating a .NET based ML ecosystem and uniting library creators and would like to add your wonderful library MyCaffe to our portal. Would you agree to that? No strings attached.

How can I get Start Mycaffe?

I'm pleasure that MyCaffe is a good Framework for C#,But I don't konw how use it.Where is the document ,If some samples can be supplied,it will help Mycaffe's lovers.

Onnx

Hi,
Will it be possible to export ONNX models?

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.