Git Product home page Git Product logo

deepbeliefsdk's Introduction

DeepBeliefSDK

The SDK for Jetpac's iOS, Android, Linux, and OS X Deep Belief image recognition framework.

This is a framework implementing the convolutional neural network architecture described by Alex Krizhevsky, Ilya Sutskever, and Geoffrey Hinton. The processing code has been highly optimized to run within the memory and processing constraints of modern mobile devices, and can analyze an image in under 300ms on an iPhone 5S. It's also easy to use together with OpenCV.

We're releasing this framework because we're excited by the power of this approach for general image recognition, especially when it can run locally on low-power devices. It gives your phone the ability to see, and I can't wait to see what applications that helps you build.

Getting started

Adding to an existing application

Documentation

Getting Started on iOS

You'll need the usual tools required for developing iOS applications - XCode 5, an OS X machine and a modern iOS device (it's been tested as far back as the original iPhone 4). Open up the SimpleExample/SimpleExample.xcodeproj, build and run.

You should see some warnings (the example is based on Apple sample code which has some anachronisms in it unfortunately), then once it's running a live camera stream should be visible on your phone. Move it to look closely at your keyboard, and some tags should start appearing in the top left of the screen. These should include things that look like keyboards, including calculators, remote controls, and even typewriters!

You should experiment with other objects like coffee cups, doors, televisions, and even dogs if you have any handy! The results will not be human quality, but the important part is that they're capturing meaningful attributes of the images. Understanding images with no context is extremely hard, and while this approach is a massive step forward compared to the previous state of the art, you'll still need to adapt it to the domain you're working in to get the best results in a real application.

Happily the framework includes the ability to retrain the network for custom objects that you care about. If you have logos you need to pick out, machine parts you need to spot, or just want to be able to distinguish between different kinds of scenes like offices, beaches, mountains or forests, you should look at the LearningExample sample code. It builds a custom layer on top of the basic neural network that responds to images you've trained it on, and allows you to embed the functionality in your own application easily.

There's also this full how-to guide on training and embedding your own custom object recognition code.

Adding to an existing iOS application

To use the library in your own application:

  1. Add the following frameworks to the Link Binary with Libraries in your XCode project's Build Phases:
  2. DeepBelief.framework
  3. Accelerate.framework
  4. libc++.dylib
  5. Add #import <DeepBelief/DeepBelief.h> to the top of the file you want to use the code in.

You should then be able to use code like this to classify a single image that you've included as a resource in your bundle. The code assumes it's called 'dog.jpg', but you should change it to match the name of your file.

  NSString* networkPath = [[NSBundle mainBundle] pathForResource:@"jetpac" ofType:@"ntwk"];
  if (networkPath == NULL) {
    fprintf(stderr, "Couldn't find the neural network parameters file - did you add it as a resource to your application?\n");
    assert(false);
  }
  network = jpcnn_create_network([networkPath UTF8String]);
  assert(network != NULL);

  NSString* imagePath = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"jpg"];
  void* inputImage = jpcnn_create_image_buffer_from_file([imagePath UTF8String]);

  float* predictions;
  int predictionsLength;
  char** predictionsLabels;
  int predictionsLabelsLength;
  jpcnn_classify_image(network, inputImage, 0, 0, &predictions, &predictionsLength, &predictionsLabels, &predictionsLabelsLength);

  jpcnn_destroy_image_buffer(inputImage);

  for (int index = 0; index < predictionsLength; index += 1) {
    const float predictionValue = predictions[index];
    char* label = predictionsLabels[index % predictionsLabelsLength];
    NSString* predictionLine = [NSString stringWithFormat: @"%s - %0.2f\n", label, predictionValue];
    NSLog(@"%@", predictionLine);
  }
  
  jpcnn_destroy_network(network);

Getting Started on Android

I've been using Google's ADT toolchain. To get started import the AndroidExample into their custom version of Eclipse, build and run it. Hopefully you should see a similar result to the iPhone app, with live video and tags displayed. You'll need to hold the phone in landscape orientation, look for the tag text and use that as your guide.

The Android implementation uses NEON SIMD instructions, so it may not work on older phones, and will definitely not work on non-ARM devices. As a benchmark for expected performance, classification takes around 650ms on a Samsung Galaxy S5.

Adding to an existing Android application

Under the hood the Android implementation uses a native C++ library that's linked to Java applications using JNA. That means the process of including the code is a bit more complex than on iOS. If you look at the AndroidExample sample code, you'll see a 'libs' folder. This contains a deepbelief.jar file that has the Java interface to the underlying native code, and then inside the armeabi there's jnidispatch.so which is part of JNA and handles the mechanics of calling native functions, and libjpcnn.so which implements the actual object recognition algorithm. You'll need to replicate this folder structure and copy the files to your own application's source tree.

Once you've done that, you should be able to import the Java interface to the library:

import com.jetpac.deepbelief.DeepBelief.JPCNNLibrary;

This class contains a list of Java functions that correspond to exactly to the C interface functions. The class code is available in the AndroidLibrary folder, and you should be able to rebuild it yourself by running ant, but here are the definitions using JNA types:

Pointer jpcnn_create_network(String filename);
void jpcnn_destroy_network(Pointer networkHandle);
Pointer jpcnn_create_image_buffer_from_file(String filename);
void jpcnn_destroy_image_buffer(Pointer imageHandle);
Pointer jpcnn_create_image_buffer_from_uint8_data(byte[] pixelData, int width, int height, int channels, int rowBytes, int reverseOrder, int doRotate);
void jpcnn_classify_image(Pointer networkHandle, Pointer inputHandle, int doMultiSample, int layerOffset, PointerByReference outPredictionsValues, IntByReference outPredictionsLength, PointerByReference outPredictionsNames, IntByReference outPredictionsNamesLength);
void jpcnn_print_network(Pointer networkHandle);

Pointer jpcnn_create_trainer();
void jpcnn_destroy_trainer(Pointer trainerHandle);
void jpcnn_train(Pointer trainerHandle, float expectedLabel, float[] predictions, int predictionsLength);
Pointer jpcnn_create_predictor_from_trainer(Pointer trainerHandle);
void jpcnn_destroy_predictor(Pointer predictorHandle);
int jpcnn_save_predictor(String filename, Pointer predictorHandle);
Pointer jpcnn_load_predictor(String filename);
float jpcnn_predict(Pointer predictorHandle, Pointer predictions, int predictionsLength);

There are a few quirks to using the interface that the example code demonstrates how to work around. jpcnn_create_network() requires a standard filename path, but to distribute the network with an application it needs to be an asset, and because that may be compressed and part of an archive, there's no way to get a path to it. To fix that, initDeepBelief() copys the file to the application's data directory:

AssetManager am = ctx.getAssets();
String baseFileName = "jetpac.ntwk";
String dataDir = ctx.getFilesDir().getAbsolutePath();
String networkFile = dataDir + "/" + baseFileName;
copyAsset(am, baseFileName, networkFile);
networkHandle = JPCNNLibrary.INSTANCE.jpcnn_create_network(networkFile);

This has some overhead obviously, so one optimization might be to check for the existence of the file and only copy it over if it doesn't already exist.

jpcnn_create_image_buffer_from_uint8_data() needs a plain byte array, and the classifyBitmap() function shows how you can extract what you need from a normal Bitmap object:

final int width = bitmap.getWidth();
final int height = bitmap.getHeight();
final int pixelCount = (width * height);
final int bytesPerPixel = 4;
final int byteCount = (pixelCount * bytesPerPixel);
ByteBuffer buffer = ByteBuffer.allocate(byteCount);
bitmap.copyPixelsToBuffer(buffer);
byte[] pixels = buffer.array();
Pointer imageHandle = JPCNNLibrary.INSTANCE.jpcnn_create_image_buffer_from_uint8_data(pixels, width, height, 4, (4 * width), 0, 0);

Native objects are not garbage-collected, so you'll have to remember to explicitly call jpcnn_destroy_image_buffer() and other calls on objects you've created through the library if you want to avoid memory leaks.

The rest of classifyBitmap() also demonstrates how to pull out the results as Java-accessible arrays from the JNA types.

Getting Started on Linux

I've been using Ubuntu 12.04 and 14.04 on x86-64 platforms, but the library ships as a simple .so with minimal dependencies, so hopefully it should work on most distros.

As long as you have git and the build-essentials packages installed, you should be able to build an example by running the following commands in a terminal:

git clone https://github.com/jetpacapp/DeepBeliefSDK.git
cd DeepBeliefSDK/LinuxLibrary
sudo ./install.sh
cd ../examples/SimpleLinux/
make
./deepbelief 

If the example program ran successfully, the output should look like this:

0.016994	wool
0.016418	cardigan
0.010924	kimono
0.010713	miniskirt
0.014307	crayfish
0.015663	brassiere
0.014216	harp
0.017052	sandal
0.024082	holster
0.013580	velvet
0.057286	bonnet
0.018848	stole
0.028298	maillot
0.010915	gown
0.073035	wig
0.012413	hand blower
0.031052	stage
0.027875	umbrella
0.012592	sarong

It's analyzing the default Lena image, and giving low probabilities of a wig and a bonnet, which isn't too crazy. You can pass in a command-line argument to analyze your own images, and the results are tab separated text, so you can pipe the results into other programs for further processing.

Adding to an existing Linux application

To use the library in your own application, first make sure you've run the install.sh script in AndroidLibrary/ to install the libjpcnn.so in /usr/lib, and libjpcnn.h in /usr/include, as described in Getting Started on Linux.

Then you should be able to access all the API functions by including the libjpcnn.h header, eg:

#include <libjpcnn.h>

Here's how you would run a basic classification of a single image, from the SimpleLinux example:

  networkHandle = jpcnn_create_network(NETWORK_FILE_NAME);
  imageHandle = jpcnn_create_image_buffer_from_file(imageFileName);

  jpcnn_classify_image(networkHandle, imageHandle, 0, 0, &predictions, &predictionsLength, &predictionsLabels, &predictionsLabelsLength);

  for (index = 0; index < predictionsLength; index += 1) {
    float predictionValue;
    char* label;
    predictionValue = predictions[index];
    if (predictionValue < 0.01f) {
      continue;
    }
    label = predictionsLabels[index];
    fprintf(stdout, "%f\t%s\n", predictionValue, label);
  }

Getting Started on OS X

Load the examples/OSXExample/MyRecorder.xcodeproj XCode project, build, and run. On any machine with a webcam, you should see a window appear showing live video. Move the webcam until it has a clear view of an object like a wine bottle, glass, mug, or a computer keyboard, and you should start to see overlaid labels and percentages.

Adding to an existing OS X application

The DeepBelief.framework you'll need is in the OSXLibrary folder. Since installing frameworks in a shared location can be a pain, and Apple recommends keeping applications as self-contained as possible, it's designed to be bundled inside your app folder. The OS X Example sample code uses this approach, and is a good starting point for understanding the process. It has a symbolic link back to the framework, but you'll probably want to copy the library into your own source tree. Apple's documentation on bundling private frameworks is the best documentation for the whole process, but here's the summary of what you'll need to do:

  • Copy DeepBelief.framework into your source tree
  • Drag it into the Frameworks folder of your project in the XCode navigator.
  • Add it to the "Link Binary with Libraries" build phase in the project settings.
  • Add a new "Copy Files Build Phase" to the project build phases.
  • Add the framework as a new file in that build phase, with the destination as "Frameworks".

Once you've done that, you should be able to build your app, and then "Show package contents" on the built product should show DeepBelief.framework inside the Contents/Frameworks folder.

At that point, just add #import <DeepBelief/DeepBelief.h> and all of the code you need should be identical to the snippets shown in the iOS guide.

Using with OpenCV

It's pretty straightforward to use DeepBelief together with OpenCV, you just need to convert the images over. There's sample code showing the whole process, but the heart of it is this image format conversion:

  const cv::Size size = image.size();
  const int width = size.width;
  const int height = size.height;
  const int pixelCount = (width * height);
  const int bytesPerPixel = 3;
  const int byteCount = (pixelCount * bytesPerPixel);

  // OpenCV images are BGR, we need RGB, so do a conversion to a temporary image
  cv::Mat rgbImage;
  cv::cvtColor(image, rgbImage, CV_BGR2RGB);
  uint8_t* rgbPixels = (uint8_t*)rgbImage.data;

  imageHandle = jpcnn_create_image_buffer_from_uint8_data(rgbPixels, width, height, 3, (3 * width), 0, 0);

Once you've done that, you can run the image classification and prediction as normal on the image handle. The sample code has some other convenience classes too, to help make using the library in C++ a bit easier. If you're using the Java interface, the same sort of call sequence works to handle the conversion, though you'll need byte[] arrays and you'll have to call image.get(0, 0, pixels) to actually get the raw image data you need.

Getting Started on a Raspberry Pi 1

The library is available as a Raspbian .so library in the RaspberryPiLibrary folder. Using it is very similar to ordinary Linux, and you can follow most of the same instructions, substituting the install.sh in the Pi folder. The biggest difference is that the Pi library uses the GPU to handle a lot of the calculations, so you need to run the example program as a super user, e.g. sudo ./deepbelief. This optimization allows an image to be recognized on a stock Pi in around five seconds, and in three seconds with a boosted GPU clock rate.

Getting Started on a Raspberry Pi 2

There's no pre-built library for the Pi 2, and the GPU version that's fastest on the Pi 1 doesn't work, so you can't just re-use the older library. The good news is that the CPU has improved so much, you can get better performance using the optimized Eigen open-source library, and compiling it from source. Here are the instructions:

mkdir ~/projects

cd ~/projects

Clone this repository into ~/projects/DeepBeliefSDK

sudo apt-get install -y mercurial

hg clone https://bitbucket.org/eigen/eigen

ln -s ~/projects/eigen ~/projects/DeepBeliefSDK/eigen

cd ~/projects/DeepBeliefSDK/source

make clean

sudo apt-get install gcc-4.8 g++-4.8

sudo rm -rf /usr/bin/gcc

sudo rm -rf /usr/bin/g++

sudo ln -s /usr/bin/gcc-4.8 /usr/bin/gcc

sudo ln -s /usr/bin/g++-4.8 /usr/bin/g++

make GEMM=eigen TARGET=pi2

./jpcnn -i data/dog.jpg -n ../networks/jetpac.ntwk -t -m s -d

You should see the classification results, with a time of around 3.8 seconds on a stock Pi 2. If you then overclock it with raspi-config, you can increase that to 3.2s.

Getting Started on a Beaglebone Black

Like the Pi 2, there’s no pre-built library for the Beaglebone Black, but you can build it yourself using the ARM-optimized Eigen open-source library. You will need to use the latest development version of Eigen to make sure NEON is enabled on the default gcc v4.6 compiler though, see this patch.

Here are the instructions:

mkdir ~/projects

cd ~/projects

Clone this repository into ~/projects/DeepBeliefSDK

sudo apt-get install -y mercurial

hg clone https://bitbucket.org/eigen/eigen

ln -s ~/projects/eigen ~/projects/DeepBeliefSDK/eigen

cd ~/projects/DeepBeliefSDK/source

make clean

make GEMM=eigen TARGET=beagle

./jpcnn -i data/dog.jpg -n ../networks/jetpac.ntwk -t -m s -d

Getting Started with Javascript

The Javascript version of the library includes complete source, and a browser demo page. The interface is similar to the C version, but uses native Javascript image objects, camelCase function names, and classes. You'll need to include the jpcnn.js file, and then load the networks/jetpac_untransposed.ntwk file (which is a slightly-modified version of the standard Jetpac network). Then you should be able to call Network.classifyImage(), with an option to accelerate the calculations using WebGL if you're in a browser that supports it. On my 2012 MacBook Pro in Chrome, the WebGL version takes around 600ms, whereas the naive CPU path takes 5 seconds.

Building from Source

If you’re on a platform that isn’t covered here, you can compile your own version of the library from the code and Makefile inside the source directory. It’s designed to have no dependencies by default, using plain, portable C++, and it’s possible to get it running on almost any device that has a compiler and the standard C libraries. Here are the minimal instructions:

mkdir ~/projects

cd ~/projects

git clone https://github.com/jetpacapp/DeepBeliefSDK.git

cd ~/projects/DeepBeliefSDK/source

make clean

make

./jpcnn -i data/dog.jpg -n ../networks/jetpac.ntwk -t -m s -d

There are two arguments you can pass into the make file to control compilation. PLATFORM (used as make PLATFORM=foo) controls settings for specific devices, for example enabling particular cpus in gcc. The GEMM argument decides which implementation of the matrix multiplication that takes the bulk of the execution time to use, so you can swap in something like Eigen or Intel’s MKL on supported platforms.

Examples

All of the sample code projects are included in the 'examples' folder in this git repository.

SimpleiOS

This is a self-contained iOS application that shows you how to load the neural network parameters, and process live video to estimate the probability that one of the 1,000 pre-defined Imagenet objects are present. The code is largely based on the SquareCam Apple sample application, which is fairly old and contains some ugly code. If you look for jpcnn_* calls in SquareCamViewController.m you should be able to follow the sequence of first loading the network, applying it to video frames as they arrive, and destroying the objects once you're all done.

LearningExample

This application allows you to apply the image recognition code to custom objects you care about. It demonstrates how to capture positive and negative examples, feed them into a trainer to create a prediction model, and then apply that prediction model to the live camera feed. It can be a bit messy thanks to all the live video feed code, but if you look for jpcnn_* you'll be able to spot the main flow. Once a prediction model has been fully trained, the parameters are written to the XCode console so they can be used as pre-trained predictors.

SavedModelExample

This shows how you can use a custom prediction model that you've built using the LearningExample sample code. I've included the simple 'wine_bottle_predictor.txt' that I quickly trained on a bottle of wine, you should be able to run it yourself and see the results of that model's prediction on your own images.

AndroidExample

A basic Android application that applies the classification algorithm to live video from the phone's camera. The first thing it does after initialization is analyze the standard image-processing image of Lena, you should see log output from that first. After that it continuously analyzes incoming camera frames, both displaying the found labels on screen and printing them to the console.

SimpleLinux

This is a small command line tool that shows how you can load a network file and classify an image using the default Imagenet categories. If you run it with no arguments, it looks for lena.png and analyzes that, otherwise it tries to load the file name in the first argument as its input image.

The network file name is hardcoded to "jetpac.ntwk" in the current folder. In a real application you'll want to set that yourself, either hard-coding it to a known absolute location for the file, or passing it in dynamically as an argument or environment variable.

The output of the tool is tab-separated lines, with the probability first followed by the imagenet label, so you can sort and process it easily through pipes on the command line.

OSXExample

This project is based on Apple's MyRecorder sample code, which is both quite old and fairly gnarly thanks to its use of QTKit! The complexity is mostly in the way it accesses the webcam, and converts the supplied image down to a simple array of RGB bytes to feed into the neural network code. If you search for 'jpcnn' in the code, you'll see the calls to the library nestled amongst all the plumbing for the interface and the video, they should be fairly straightforward.

The main steps are loading the 'jetpac.ntwk' neural network, that's included as a resource in the app, then extracting an image from the video, classifying it, and displaying the found labels in the UI. When you build and run the project, you should see a window appear with the webcam view in it, and any found labels overlaid on top. You'll also see some performance stats being output to the console - on my mid-2012 Macbook Pro it takes around 60ms to do the calculations.

SimpleOpenCV

This is a basic Linux command-line tool that shows how OpenCV and the DeepBelief framework can work together. The main() function uses C++ classes defined in deepbeliefopencv.h to load a network, then it creates an OpenCV image from either lena.png or another file supplied on the command line. A wrapper class for the library's image handle object is then used to convert the OpenCV image into one the DeepBelief framework can analyze. The classification is run on that image, and the found labels are printed out.

If you're doing a lot of work with OpenCV, the most crucial part for you is probably the conversion of the image objects between the two systems. That's defined in deepbeliefopencv.cpp in the Image::Image(const cv::Mat& image) constructor, and the section on using OpenCV covers what's going on in the actual code.

Networks

There are currently three pre-built models available in the networks folder. jetpac.ntwk is the in-house model used here at Jetpac, and it's licensed under the same BSD conditions as the rest of the project. It has a few oddities, like only 999 labels (a file truncation problem I discovered too late during training) but has served us well and is a good place to start.

The excellent libccv project also made a couple of networks available under a Creative Commons Attribution 4.0 International License. I've converted them over into a binary format, and they're in the networks folder as ccv2010.ntwk and ccv2012.ntwk. You should be able to substitute these in anywhere you'd use jetpac.ntwk. The 2012 file has very similar labels to our original, and the 2010 is an older architecture. You may notice slightly slower performance, the arrangement of the layers is a bit different (in technical terms the local-response normalization happens before the max-pooling in these models, which is more expensive since there's more data to normalize), but the accuracy of the 2012 model especially is good. One common technique in the academic world is to take multiple models and merge their votes for higher accuracy, so one application of the multiple models might be improved accuracy.

API Reference

Because we reuse the same code across a lot of different platforms, we use a plain-old C interface to our library. All of the handles to different objects are opaque pointers, and you have to explictly call the *_destroy_* function on any handles that have been returned from *_create_* calls if you want to avoid memory leaks. Input images are created from raw arrays of 8-bit RGB data, you can see how to build those from iOS types by searching for jpcnn_create_image_buffer() in the sample code.

The API is broken up into two sections. The first gives you access to one of the pre-trained neural networks you'll find in the networks folder. These have been trained on 1,000 Imagenet categories, and the output will give you a decent general idea of what's in an image.

The second section lets you replace the highest layer of the neural network with your own classification step. This means you can use it to recognize the objects you care about more accurately.

Pre-trained calls

Custom training calls

jpcnn_create_network

void* jpcnn_create_network(const char* filename)

This takes the filename of the network parameter file as an input, and builds a neural network stack based on that definition. Right now the only available file is the 1,000 category jetpac.ntwk, built here at Jetpac based on the approach used by Krizhevsky to win the Imagenet 2012 competition.

You'll need to make sure you include this 60MB file in the 'Copy Files' build phase of your application, and then call something like this to get the actual path:

NSString* networkPath = [[NSBundle mainBundle] pathForResource:@"jetpac" ofType:@"ntwk"];
network = jpcnn_create_network([networkPath UTF8String]);

jpcnn_destroy_network

void jpcnn_destroy_network(void* networkHandle)

Once you're finished with the neural network, call this to destroy it and free up the memory it used.

jpcnn_create_image_buffer_from_file

void* jpcnn_create_image_buffer_from_file(const char* filename)

Takes a filename (see above for how to get one from your bundle) and creates an image object that you can run the classification process on. It can load PNGS and JPEGS.

jpcnn_create_image_buffer_from_uint8_data

void* jpcnn_create_image_buffer_from_uint8_data(unsigned char* pixelData, int width, int height, int channels, int rowBytes, int reverseOrder, int doRotate)

If you already have data in memory, you can use this function to copy it into an image object that you can then classify. It's useful if you're doing video capture, as the sample code does.

jpcnn_destroy_image_buffer

void jpcnn_destroy_image_buffer(void* imageHandle)

Once you're done classifying an image, call this to free up the memory it used.

jpcnn_classify_image

void jpcnn_classify_image(void* networkHandle, void* inputHandle, unsigned int flags, int layerOffset, float** outPredictionsValues, int* outPredictionsLength, char*** outPredictionsNames, int* outPredictionsNamesLength)

This is how you actually get tags for an image. It takes in a neural network and an image, and returns an array of floats. Each float is a predicted value for an imagenet label, between 0 and 1, where higher numbers are more confident predictions.

The three outputs are:

  • outPredictionsValues is a pointer to the array of predictions.
  • outPredictionsLength holds the length of the predictions array.
  • outPredictionsNames is an array of C strings representing imagenet labels, each corresponding to the prediction value at the same index in outPredictionsValues.
  • outPredictionsNamesLength is the number of name strings in the label array. In the simple case this is the same as the number of predictions, but in different modes this can get more complicated! See below for details.

In the simple case you can leave the flags and layerOffset arguments as zero, and you'll get an array of prediction values out. Pick the highest (possibly with a threshold like 0.1 to avoid shaky ones), and you can use that as a simple tag for the image.

There are several optional arguments you can use to improve your results though.

layerOffset

The final output of the neural network represents the high-level categories that it's been trained on, but often you'll want to work with other types of objects. The good news is that it's possible to take the results from layers that are just before the final one, and use those as inputs to simple statistical algorithms to recognize entirely new kinds of things. This paper on Decaf does a good job of describing the approach, but the short version is that those high-level layers can be seen as adjectives that help the output layer make its final choice between categories, and those same adjectives turn out to be useful for choosing between a lot of other categories it hasn't been trained on too. For example, there might be some signals that correlate with 'spottiness' and 'furriness', which would be useful for picking out leopards, even if they were originally learned from pictures of dalmatians.

The layerOffset argument lets you control which layer you're sampling, as a negative offset from the start of the network. Try setting it to -2, and you should get an array of 4096 floats in outPredictionsValues, though since these are no longer representing Imagenet labels the names array will no longer be valid. You can then feed those values into a training system like libSVM to help you distinguish between the kinds of objects you care about.

flags

The image recognition algorithm always crops the input image to the biggest square that fits within its bounds, resamples that area to 256x256 pixels and then takes a slightly smaller 224x224 sample square from somewhere within that main square. The flags argument controls how that 224-pixel sample square is positioned within the larger one. If it's left as zero, then it's centered with a 16 pixel margin at all edges. The sample code uses JPCNN_RANDOM_SAMPLE to jitter the origin of the 224 square randomly within the bounds each call, since this, combined with smoothing of the results over time, helps ensure that the identification of tags is robust to slight position changes. The JPCNN_MULTISAMPLE flag takes ten different sample positions within the image and runs them all through the classification pipeline simultaneously. This is a costly operation, so it doesn't tend to be practical on low-processing-power platforms like the iPhone.

jpcnn_print_network

void jpcnn_print_network(void* networkHandle)

This is a debug logging call that prints information about a loaded neural network.

jpcnn_create_trainer

void* jpcnn_create_trainer()

Returns a handle to a trainer object that you can feed training examples into to build your own custom prediction model.

jpcnn_destroy_trainer

void jpcnn_destroy_trainer(void* trainerHandle)

Disposes of the memory used by the trainer object and destroys it.

jpcnn_train

void jpcnn_train(void* trainerHandle, float expectedLabel, float* predictions, int predictionsLength)

To create your own custom prediction model, you need to train it using 'positive' examples of images containing the object you care about, and 'negative' examples of images that don't. Once you've created a trainer object, you can call this with the neural network results for each positive or negative image, and with an expectedLabel of '0.0' for negatives and '1.0' for positives. Picking the exact number of each you'll need is more of an art than a science, since it depends on how easy your object is to recognize and how cluttered your environment is, but I've had decent results with as few as a hundred of each. You can use the output of any layer of the neural network, but I've found using the penultimate one works well. I discuss how to do this above in the layerOffset section. To see how this works in practice, try out the LearningExample sample code for yourself.

jpcnn_create_predictor_from_trainer

void* jpcnn_create_predictor_from_trainer(void* trainerHandle)

Once you've passed in all your positive and negative examples to jpcnn_train, you can call this to build a predictor model from them all. Under the hood, it's using libSVM to create a support vector machine model based on the examples.

jpcnn_destroy_predictor

void jpcnn_destroy_predictor(void* predictorHandle)

Deallocates any memory used by the predictor model, call this once you're finished with it.

jpcnn_load_predictor

void* jpcnn_load_predictor(const char* filename)

Loads a predictor you've already created from a libSVM-format text file. Since you can't save files on iOS devices, the only way to create this file in the first place is to call jpcnn_print_predictor once you've created a predictor, and then copy and paste the results from the developer console into a file, and then add it to your app's resources. The SavedModelExample sample code shows how to use this call.

jpcnn_print_predictor

void jpcnn_print_predictor(void* predictorHandle)

Outputs the parameters that define a custom predictor to stderr (and hence the developer console in XCode). You'll need to copy and paste this into your own text file to subsequently reload the predictor.

jpcnn_predict

float jpcnn_predict(void* predictorHandle, float* predictions, int predictionsLength)

Given the output from a pre-trained neural network, and a custom prediction model, returns a value estimating the probability that the image contains the object it has been trained against.

FAQ

Is this available for platforms other than iOS, Android, OS X, and Linux x86-64?

Not right now. I hope to make it available on other devices like the Raspberry Pi in the future. I recommend checking out Caffe, OverFeat and libCCV if you're on the desktop too, they're great packages.

Is the source available?

Not at the moment. The compiled library and the neural network parameter set are freely reusable in your own apps under the BSD license though.

Can I train my own networks?

There aren't any standard formats for sharing large neural networks unfortunately, so there's no easy way to import other CNNs into the app. The custom training should help you apply the included pre-trained network to your own problems to a large extent though.

More Information

Join the Deep Belief Developers email list to find out more about the practical details of implementing deep learning.

License

The binary framework and jetpac.ntwk network parameter file are under the BSD three-clause license, included in this folder as LICENSE. All source code is under that BSD license unless otherwise noted.

The ccv2010.ntwk and ccv2012.ntwk network models were converted from files created as part of the LibCCV project and are licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.

Credits

Big thanks go to:

Pete Warden

deepbeliefsdk's People

Contributors

alessiop86 avatar arielelkin avatar cbowns avatar cfandy avatar jetpaccomputer avatar misko avatar petewarden avatar waylonflinn 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  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  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  avatar  avatar  avatar  avatar

deepbeliefsdk's Issues

Android crashes on JPCNNLibrary.INSTANCE.jpcnn_classify_image

Hi everybody,

I get crashes when I try run the android example. When it hits Line 167.
I read in the previous issues that this was patch so I'm not sure if it's because of the device I'm using (API 19 on a Samsung Galaxy S3).

Any ideas? Thank you very much.

Run classification command no respone

I make this with gemm qpu-asm complete and run
./jpcnn -i data/dog.jpg -n ../networks/jetpac.ntwk -t -m s -d
After that, my Raspberry Pi 2 have no respone, it crash and no result. Please help me solve this problem.
Thanks

Python wrapper?

Hi all,

Is anybody aware of a Python wrapper for the DeepBeliefSDK?

Daniel

[iOS]Lexical or Preprocessor issue 'DeepBelief/DeepBelief.h' not found

Hi, I know this question may seem strange or silly but I googled and tried to solve it in many ways but still couldn't get through.

I followed the ReadMe file and tried to use Xcode to build and run the SimpleExample project, but the Lexical or Preprocessor issue 'DeepBelief/DeepBelief.h' not found error keeps appearing. I tried it on another Mac and had the same problem.
My Xcode is Version 6.1.1

I would really appreciate it if someone could help me with this problem, I really look forward to running this app and see how it performs. Thank you.

Runtime error

Hi,

I'm not particularly familiar with the OS X toolkit so I am probably being an idiot about this.

I was able to get the code to compile ( I added the framework and everything ).

However, I can't get it to run. It fails with this error that I really couldn't make much sense of.

dyld: Library not loaded: @executable_path/../Frameworks/DeepBelief.framework/Versions/A/DeepBelief
  Referenced from: /Users/shriphani/Library/Developer/Xcode/DerivedData/MyRecorder-cfgnjbjyaacnmdanghxubskwpbsu/Build/Products/Debug/MyRecorder.app/Contents/MacOS/MyRecorder
  Reason: image not found
(lldb) 

Any help would be appreciated :)

Shared library for Linux

Would be great to have the shared library for Linux (Ubuntu) platform. Is it on your list or iOS&Android only for now?

[iOS] jpcnn couldn't open assets-library

I am trying to get image from Assets using following code -

 NSString* networkPath = [[NSBundle mainBundle] pathForResource:@"jetpac" ofType:@"ntwk"];
    if (networkPath == NULL) {
    fprintf(stderr, "Couldn't find the neural network parameters file - did you add it as a resource to your application?\n");
    assert(false);
}
network = jpcnn_create_network([networkPath UTF8String]);
assert(network != NULL);
ALAsset *result = self.assets[0];
NSString *imagePath; // = [[NSBundle mainBundle] pathForResource:@"slrCamera" ofType:@"png"];
imagePath = [result.defaultRepresentation.url absoluteString];

ALAssetsLibrary *lib = [ALAssetsLibrary new];
NSURL *url = result.defaultRepresentation.url;
[lib assetForURL:url resultBlock:^(ALAsset *asset) {

  NSString *finalImagePath = [asset.defaultRepresentation.url absoluteString];

    void* inputImage = jpcnn_create_image_buffer_from_file([finalImagePath UTF8String]);
    float* predictions;
    int predictionsLength;
    char** predictionsLabels;
    int predictionsLabelsLength;
    jpcnn_classify_image(network, inputImage, 0, 0, &predictions, &predictionsLength, &predictionsLabels, &predictionsLabelsLength);
    jpcnn_destroy_image_buffer(inputImage);
    for (int index = 0; index < predictionsLength; index += 1) {
        const float predictionValue = predictions[index];
        char* label = predictionsLabels[index % predictionsLabelsLength];
        NSString* predictionLine = [NSString stringWithFormat: @"%s - %0.2f\n", label, predictionValue];
        NSLog(@"predictionLine \n %@", predictionLine);
    }
    jpcnn_destroy_network(network);
} failureBlock:^(NSError *error) {
    NSLog(@"error = %@", error);
}];

But it crashes with following error -

jpcnn couldn't open 'assets-library://asset/asset.JPG?id=CC74B475-2402-4494-8777-67E7659AB7BE&ext=JPG'

Questions about image matching

Hi,
We have a requirement the user can take a picture of shirt or shoes from the mobile and application will show the relevant matching images from our image list. If the user searches front view of a shirt the application should show similar shirt even if its side view is available in the image list.

So, the basic requirement is, for an image, the relevant images need to fetch from the image list. How can I achieve this with DeepBeliefSDK?

in my understanding, the .ntwk file is the collection of information about the images list. How can I make the .ntwk file for my images?

If I want to check the logos(nike, adidas or puma) also what modifications I have to do?

Is there any sample code available for this purpose?

Thanks,
Saneesh

Android version

This would probably be best in a separate repo, but for understanding demand add your +1 here.

Can not build android using Accelerate gemm

How would i get the library for this on android?

Without this lib, we were able to still get it to compile; however, the speed is many mulitples slower than 650ms on a Samsung Galaxy s5

RomoExample fails to build on non-Pete machines

The framework search paths for RomoExample includes:

//:configuration = Debug
FRAMEWORK_SEARCH_PATHS = $(inherited) $(DEVELOPER_FRAMEWORKS_DIR) /Users/petewarden/projects/DeepBeliefSDK /Users/petewarden/projects/RomoSDK_v1.0C/frameworks

//:configuration = Release
FRAMEWORK_SEARCH_PATHS = $(inherited) $(DEVELOPER_FRAMEWORKS_DIR) /Users/petewarden/projects/DeepBeliefSDK /Users/petewarden/projects/RomoSDK_v1.0C/frameworks

//:completeSettings = some
FRAMEWORK_SEARCH_PATHS

But RomoSDK isn't part of the DeepBeliefSDK, so it fails to build. This is probably worth noting in a README for RomoExample.


The raw build log:

    cd /Users/cbowns/Development/DeepBeliefSDK/examples/RomoExample
    export LANG=en_US.US-ASCII
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch i386 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fmodules -fmodules-cache-path=/Users/cbowns/Library/Developer/Xcode/DerivedData/ModuleCache -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -fexceptions -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch -mios-simulator-version-min=7.0 -iquote /Users/cbowns/Library/Developer/Xcode/DerivedData/RomoExample-dnmxhznrcpgonyhgnipvijjytqkl/Build/Intermediates/RomoExample.build/Debug-iphonesimulator/RomoExample.build/RomoExample-generated-files.hmap -I/Users/cbowns/Library/Developer/Xcode/DerivedData/RomoExample-dnmxhznrcpgonyhgnipvijjytqkl/Build/Intermediates/RomoExample.build/Debug-iphonesimulator/RomoExample.build/RomoExample-own-target-headers.hmap -I/Users/cbowns/Library/Developer/Xcode/DerivedData/RomoExample-dnmxhznrcpgonyhgnipvijjytqkl/Build/Intermediates/RomoExample.build/Debug-iphonesimulator/RomoExample.build/RomoExample-all-target-headers.hmap -iquote /Users/cbowns/Library/Developer/Xcode/DerivedData/RomoExample-dnmxhznrcpgonyhgnipvijjytqkl/Build/Intermediates/RomoExample.build/Debug-iphonesimulator/RomoExample.build/RomoExample-project-headers.hmap -I/Users/cbowns/Library/Developer/Xcode/DerivedData/RomoExample-dnmxhznrcpgonyhgnipvijjytqkl/Build/Products/Debug-iphonesimulator/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/cbowns/Library/Developer/Xcode/DerivedData/RomoExample-dnmxhznrcpgonyhgnipvijjytqkl/Build/Intermediates/RomoExample.build/Debug-iphonesimulator/RomoExample.build/DerivedSources/i386 -I/Users/cbowns/Library/Developer/Xcode/DerivedData/RomoExample-dnmxhznrcpgonyhgnipvijjytqkl/Build/Intermediates/RomoExample.build/Debug-iphonesimulator/RomoExample.build/DerivedSources -F/Users/cbowns/Library/Developer/Xcode/DerivedData/RomoExample-dnmxhznrcpgonyhgnipvijjytqkl/Build/Products/Debug-iphonesimulator -F/Applications/Xcode.app/Contents/Developer/Library/Frameworks -F/Users/petewarden/projects/DeepBeliefSDK -F/Users/petewarden/projects/RomoSDK_v1.0C/frameworks -MMD -MT dependencies -MF /Users/cbowns/Library/Developer/Xcode/DerivedData/RomoExample-dnmxhznrcpgonyhgnipvijjytqkl/Build/Intermediates/RomoExample.build/Debug-iphonesimulator/RomoExample.build/Objects-normal/i386/SquareCamViewController.d --serialize-diagnostics /Users/cbowns/Library/Developer/Xcode/DerivedData/RomoExample-dnmxhznrcpgonyhgnipvijjytqkl/Build/Intermediates/RomoExample.build/Debug-iphonesimulator/RomoExample.build/Objects-normal/i386/SquareCamViewController.dia -c /Users/cbowns/Development/DeepBeliefSDK/examples/RomoExample/SquareCamViewController.m -o /Users/cbowns/Library/Developer/Xcode/DerivedData/RomoExample-dnmxhznrcpgonyhgnipvijjytqkl/Build/Intermediates/RomoExample.build/Debug-iphonesimulator/RomoExample.build/Objects-normal/i386/SquareCamViewController.o

In file included from /Users/cbowns/Development/DeepBeliefSDK/examples/RomoExample/SquareCamViewController.m:48:
/Users/cbowns/Development/DeepBeliefSDK/examples/RomoExample/SquareCamViewController.h:50:9: fatal error: 'RMCore/RMCore.h' file not found
# import <RMCore/RMCore.h>

^

1 error generated.

[Android] crash when deepbelief functions are called from background thread

issue is gone after removing -fopenmp.

It seems that issue is caused by an openmp bug on Android.
details and workaround can be found in
http://recursify.com/blog/2013/08/09/openmp-on-android-tls-workaround

This is the log.
ZhengZhihengs-iMac:source zhengzhiheng$ adb logcat | grep 23864
I/DEBUG (23864): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG (23864): Build fingerprint: 'samsung/jgedlteue/jgedlte:4.4.4/KTU84P.S001/140602:user/release-keys'
I/DEBUG (23864): Revision: '11'
I/DEBUG (23864): pid: 6108, tid: 6441, name: Thread-2423 >>> com.buuna.bourbonbeats <<<
I/DEBUG (23864): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000008
I/DEBUG (23864): r0 00000000 r1 78cb3dd0 r2 00000040 r3 00000018
I/DEBUG (23864): r4 78cb2bd0 r5 78cb2b18 r6 78cb2ab0 r7 0000016b
I/DEBUG (23864): r8 00000000 r9 00000040 sl 75b0bb08 fp 000002d6
I/DEBUG (23864): ip 78ce1f9c sp 78cb2a48 lr 78cda168 pc 78cda168 cpsr 88070010
I/DEBUG (23864): d0 0000000000000000 d1 0000000000000000
I/DEBUG (23864): d2 0000000000000000 d3 0000000000000000
I/DEBUG (23864): d4 4306494041769400 d5 418c3880435c6940
I/DEBUG (23864): d6 000000d54306db10 d7 46f6d60000000000
I/DEBUG (23864): d8 bec96d473750324e d9 0000000000000000
I/DEBUG (23864): d10 0000000000000000 d11 0000000000000000
I/DEBUG (23864): d12 0000000000000000 d13 0000000000000000
I/DEBUG (23864): d14 0000000000000000 d15 0000000000000000
I/DEBUG (23864): d16 0000000000000000 d17 c1d4e170423912e8
I/DEBUG (23864): d18 41b8ef20c20558a4 d19 41f6c0fcc1e9ec10
I/DEBUG (23864): d20 c1f2f10041699af8 d21 42a50dcb42577d0a
I/DEBUG (23864): d22 42b97bffc290f7c1 d23 c24a4d14421ee5c2
I/DEBUG (23864): d24 43167895bbae2364 d25 00c000bf00bd00be
I/DEBUG (23864): d26 0000000000000000 d27 0000000000000000
I/DEBUG (23864): d28 009e009d009c009b d29 00a0009f009d009e
I/DEBUG (23864): d30 00c000c000c000c0 d31 3ff1c37937e08000
I/DEBUG (23864): scr 60000012
I/DEBUG (23864):
I/DEBUG (23864): backtrace:
I/DEBUG (23864): #00 pc 00026168 /data/app-lib/com.buuna.bourbonbeats-2/libjpcnn.so (omp_get_num_threads+8)
I/DEBUG (23864):
I/DEBUG (23864): stack:
I/DEBUG (23864): 78cb2a08 00000000
I/DEBUG (23864): 78cb2a0c 00000000
I/DEBUG (23864): 78cb2a10 00000000
I/DEBUG (23864): 78cb2a14 00000000
I/DEBUG (23864): 78cb2a18 00000000
I/DEBUG (23864): 78cb2a1c 78cb2ac4 [stack:6441]
I/DEBUG (23864): 78cb2a20 78cb2abc [stack:6441]
I/DEBUG (23864): 78cb2a24 78cb2ab0 [stack:6441]
I/DEBUG (23864): 78cb2a28 00100000
I/DEBUG (23864): 78cb2a2c 00002000
I/DEBUG (23864): 78cb2a30 00000000
I/DEBUG (23864): 78cb2a34 78cb2ab0 [stack:6441]
I/DEBUG (23864): 78cb2a38 00000000
I/DEBUG (23864): 78cb2a3c 78cc2831 /data/app-lib/com.buuna.bourbonbeats-2/libjpcnn.so
I/DEBUG (23864): 78cb2a40 0000016b
I/DEBUG (23864): 78cb2a44 78cb2bc0 [stack:6441]
I/DEBUG (23864): #00 78cb2a48 00000bd1
I/DEBUG (23864): 78cb2a4c 78cc398b /data/app-lib/com.buuna.bourbonbeats-2/libjpcnn.so
I/DEBUG (23864): 78cb2a50 00000000
I/DEBUG (23864): 78cb2a54 00000000
I/DEBUG (23864): 78cb2a58 00000040
I/DEBUG (23864): 78cb2a5c 00000001
I/DEBUG (23864): 78cb2a60 00000bd1
I/DEBUG (23864): 78cb2a64 00000001
I/DEBUG (23864): 78cb2a68 80e32214
I/DEBUG (23864): 78cb2a6c 75af5008
I/DEBUG (23864): 78cb2a70 0000016b
I/DEBUG (23864): 78cb2a74 00000040
I/DEBUG (23864): 78cb2a78 78cb3220 [stack:6441]
I/DEBUG (23864): 78cb2a7c 78cb2a6c [stack:6441]
I/DEBUG (23864): 78cb2a80 78cb2bd0 [stack:6441]
I/DEBUG (23864): 78cb2a84 78cb2b18 [stack:6441]
I/DEBUG (23864):
I/DEBUG (23864): memory near r1:
I/DEBUG (23864): 78cb3db0 415bf0f5 401011b4 76fa2330 807248f8
I/DEBUG (23864): 78cb3dc0 78cb3dd0 0000000b 00000078 4010134c
I/DEBUG (23864): 78cb3dd0 78cb3dd0 807248f8 00000016 00000000
I/DEBUG (23864): 78cb3de0 00000000 26c52576 00000000 00000000
I/DEBUG (23864): 78cb3df0 00000000 00000000 00000000 00000000
I/DEBUG (23864): 78cb3e00 00000000 00000000 00000000 76fa2330
I/DEBUG (23864): 78cb3e10 00000000 00000000 00000000 00000000
I/DEBUG (23864): 78cb3e20 00000000 00000000 00000000 00000000
I/DEBUG (23864): 78cb3e30 80e2ecd8 80724b40 00000000 00000000
I/DEBUG (23864): 78cb3e40 00000000 00000000 80e2d400 00000000
I/DEBUG (23864): 78cb3e50 00000000 00000000 00000000 00000000
I/DEBUG (23864): 78cb3e60 00000000 00000000 00000000 00000000
I/DEBUG (23864): 78cb3e70 00000000 00000000 00000000 00000000
I/DEBUG (23864): 78cb3e80 00000000 00000000 00000000 00000000
I/DEBUG (23864): 78cb3e90 00000000 00000000 00000000 00000000
I/DEBUG (23864): 78cb3ea0 00000000 00000000 00000000 00000000
I/DEBUG (23864):
I/DEBUG (23864): memory near r4:
I/DEBUG (23864): 78cb2bb0 00017000 40103865 ffffffff 00000000
I/DEBUG (23864): 78cb2bc0 75af5008 0000016b 00000040 40104eab
I/DEBUG (23864): 78cb2bd0 773c2008 0000016b 00000bd1 00016b00
I/DEBUG (23864): 78cb2be0 00000000 00000000 00000000 80d97008
I/DEBUG (23864): 78cb2bf0 00000060 00000020 0000016b 0000016b
I/DEBUG (23864): 78cb2c00 772a6108 78cc3d45 00000bd1 0000016b
I/DEBUG (23864): 78cb2c10 3f800000 75af5008 0000016b 773c2008
I/DEBUG (23864): 78cb2c20 0000016b 00000000 772a6008 00000060
I/DEBUG (23864): 78cb2c30 773c2000 000005ac 80d97008 80d97008
I/DEBUG (23864): 78cb2c40 00000010 75af5008 00000066 00000070
I/DEBUG (23864): 78cb2c50 0000006f 00000bd1 3f800000 773c2008
I/DEBUG (23864): 78cb2c60 0000016b 00000000 00000060 00005ac0
I/DEBUG (23864): 78cb2c70 0000b580 ffffffe0 00000060 000002d6
I/DEBUG (23864): 78cb2c80 0000016a 76f1f008 01000000 40800000
I/DEBUG (23864): 78cb2c90 00000037 80e2d518 00000060 76fdde38
I/DEBUG (23864): 78cb2ca0 76dc3b20 00000090 0000000b 00000a80
I/DEBUG (23864):
I/DEBUG (23864): memory near r5:
I/DEBUG (23864): 78cb2af8 773c2008 75af5008 00000070 78cc3bd7
I/DEBUG (23864): 78cb2b08 0000016b 00000040 000003f6 000003f7
I/DEBUG (23864): 78cb2b18 772a6008 00000040 00000bd1 00000060
I/DEBUG (23864): 78cb2b28 00000001 000007f8 000007f9 00000ff4
I/DEBUG (23864): 78cb2b38 00000ff5 00000ff6 00000ff7 00003fe0
I/DEBUG (23864): 78cb2b48 00007fc2 00007fc3 0000ff88 0000ff89
I/DEBUG (23864): 78cb2b58 0000ff8a 0000ff8b 0000ff8c 0000ff8d
I/DEBUG (23864): 78cb2b68 0000ff8e 0000ff8f 0000ff90 0000ff91
I/DEBUG (23864): 78cb2b78 0000ff92 0000ff93 0000ff94 0000ff95
I/DEBUG (23864): 78cb2b88 00000000 ffffffff 76f1f000 40106cdf
I/DEBUG (23864): 78cb2b98 76f1f000 76f1f000 76f1f000 4012191f
I/DEBUG (23864): 78cb2ba8 40133f4a 00017000 00017000 40103865
I/DEBUG (23864): 78cb2bb8 ffffffff 00000000 75af5008 0000016b
I/DEBUG (23864): 78cb2bc8 00000040 40104eab 773c2008 0000016b
I/DEBUG (23864): 78cb2bd8 00000bd1 00016b00 00000000 00000000
I/DEBUG (23864): 78cb2be8 00000000 80d97008 00000060 00000020
I/DEBUG (23864):
I/DEBUG (23864): memory near r6:
I/DEBUG (23864): 78cb2a90 00000001 80e336f4 40142384 78cb2aa4
I/DEBUG (23864): 78cb2aa0 00000000 00000000 00000001 00000004
I/DEBUG (23864): 78cb2ab0 00000000 00000000 00000000 00000040
I/DEBUG (23864): 78cb2ac0 00000bd1 00000080 00002000 0005e880
I/DEBUG (23864): 78cb2ad0 00000400 0000003b 00000078 78cb2b18
I/DEBUG (23864): 78cb2ae0 773c1904 772a6008 00000060 78cc3b2b
I/DEBUG (23864): 78cb2af0 00000000 0000016b 773c2008 75af5008
I/DEBUG (23864): 78cb2b00 00000070 78cc3bd7 0000016b 00000040
I/DEBUG (23864): 78cb2b10 000003f6 000003f7 772a6008 00000040
I/DEBUG (23864): 78cb2b20 00000bd1 00000060 00000001 000007f8
I/DEBUG (23864): 78cb2b30 000007f9 00000ff4 00000ff5 00000ff6
I/DEBUG (23864): 78cb2b40 00000ff7 00003fe0 00007fc2 00007fc3
I/DEBUG (23864): 78cb2b50 0000ff88 0000ff89 0000ff8a 0000ff8b
I/DEBUG (23864): 78cb2b60 0000ff8c 0000ff8d 0000ff8e 0000ff8f
I/DEBUG (23864): 78cb2b70 0000ff90 0000ff91 0000ff92 0000ff93
I/DEBUG (23864): 78cb2b80 0000ff94 0000ff95 00000000 ffffffff
I/DEBUG (23864):
I/DEBUG (23864): memory near sl:
I/DEBUG (23864): 75b0bae8 3d12aa90 3c9dec70 3ba20840 3c0510a0
I/DEBUG (23864): 75b0baf8 bbb3f280 3c72db40 3bf69cc0 baaee600
I/DEBUG (23864): 75b0bb08 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bb18 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bb28 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bb38 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bb48 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bb58 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bb68 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bb78 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bb88 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bb98 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bba8 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bbb8 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bbc8 00000000 00000000 00000000 00000000
I/DEBUG (23864): 75b0bbd8 00000000 00000000 00000000 00000000
I/DEBUG (23864):
I/DEBUG (23864): memory near ip:
I/DEBUG (23864): 78ce1f7c 4012196d 40114af8 40106c9d 4010722b
I/DEBUG (23864): 78ce1f8c 401030d1 4011587c 00000000 00000000
I/DEBUG (23864): 78ce1f9c 40101940 4011ccd1 4011cbc5 4011f3e5
I/DEBUG (23864): 78ce1fac 40108489 4011f0ad 4011f38d 4011f1d5
I/DEBUG (23864): 78ce1fbc 40106ce9 40106d11 40106d59 40107455
I/DEBUG (23864): 78ce1fcc 4011be99 4011cc47 40102d98 40101960
I/DEBUG (23864): 78ce1fdc 40106d69 40101258 40106d03 401016f4
I/DEBUG (23864): 78ce1fec 401017f0 401142f8 401143cc 4012e20b
I/DEBUG (23864): 78ce1ffc 40115f8c 00000000 78cdec84 78cbe4a9
I/DEBUG (23864): 78ce200c 78cded70 78cbe615 78cded84 78cbe795
I/DEBUG (23864): 78ce201c 78cded98 78cbea75 78cdef00 78cbf431
I/DEBUG (23864): 78ce202c 78cdefc0 78cbf769 78cdefcc 78cbf949
I/DEBUG (23864): 78ce203c 78cdefd4 78cc0581 78cdeb84 78cbefb5
I/DEBUG (23864): 78ce204c ffffffff 0000013d 78cc509d 3ee8ba2e
I/DEBUG (23864): 78ce205c 3f800000 400ccccd 3f800000 58585858
I/DEBUG (23864): 78ce206c 75686320 6e206b6e 6b20746f 6e776f6e
I/DEBUG (23864):
I/DEBUG (23864): memory near sp:
I/DEBUG (23864): 78cb2a28 00100000 00002000 00000000 78cb2ab0
I/DEBUG (23864): 78cb2a38 00000000 78cc2831 0000016b 78cb2bc0
I/DEBUG (23864): 78cb2a48 00000bd1 78cc398b 00000000 00000000
I/DEBUG (23864): 78cb2a58 00000040 00000001 00000bd1 00000001
I/DEBUG (23864): 78cb2a68 80e32214 75af5008 0000016b 00000040
I/DEBUG (23864): 78cb2a78 78cb3220 78cb2a6c 78cb2bd0 78cb2b18
I/DEBUG (23864): 78cb2a88 3f800000 78cb2ab0 00000001 80e336f4
I/DEBUG (23864): 78cb2a98 40142384 78cb2aa4 00000000 00000000
I/DEBUG (23864): 78cb2aa8 00000001 00000004 00000000 00000000
I/DEBUG (23864): 78cb2ab8 00000000 00000040 00000bd1 00000080
I/DEBUG (23864): 78cb2ac8 00002000 0005e880 00000400 0000003b
I/DEBUG (23864): 78cb2ad8 00000078 78cb2b18 773c1904 772a6008
I/DEBUG (23864): 78cb2ae8 00000060 78cc3b2b 00000000 0000016b
I/DEBUG (23864): 78cb2af8 773c2008 75af5008 00000070 78cc3bd7
I/DEBUG (23864): 78cb2b08 0000016b 00000040 000003f6 000003f7
I/DEBUG (23864): 78cb2b18 772a6008 00000040 00000bd1 00000060
I/DEBUG (23864):
I/DEBUG (23864): code around pc:
I/DEBUG (23864): 78cda148 e08f0000 eb0007f0 e8bd4008 ea000200
I/DEBUG (23864): 78cda158 00007f80 00008138 e92d4008 ebffff99
I/DEBUG (23864): 78cda168 e5903008 e3530000 15930000 03a00001
I/DEBUG (23864): 78cda178 e8bd8008 e92d4008 ebffff92 e5900014
I/DEBUG (23864): 78cda188 e8bd8008 e92d4008 ebffff8e e590001c
I/DEBUG (23864): 78cda198 e2900000 13a00001 e8bd8008 e92d4008
I/DEBUG (23864): 78cda1a8 ebffff88 e5900018 e8bd8008 e92d4010
I/DEBUG (23864): 78cda1b8 e1a04000 ebffff83 e3540000 b3e00000
I/DEBUG (23864): 78cda1c8 b8bd8010 e5903018 e1540003 92800008
I/DEBUG (23864): 78cda1d8 90644003 9a000003 ea000006 e5900000
I/DEBUG (23864): 78cda1e8 e2444001 e2800008 e3540000 cafffffa
I/DEBUG (23864): 78cda1f8 e590000c e8bd8010 e3e00000 e8bd8010
I/DEBUG (23864): 78cda208 e92d4010 e1a04000 ebffff6e e3540000
I/DEBUG (23864): 78cda218 ba00000f e5903018 e1540003 92800008
I/DEBUG (23864): 78cda228 90644003 9a000003 ea000009 e5900000
I/DEBUG (23864): 78cda238 e2444001 e2800008 e3540000 cafffffa
I/DEBUG (23864): !@dumpstate -k -t -z -d -o /data/log/dumpstate_app_native -m 6108

Android app crash when call jpcnn_predict

I just slightly modify the AndroidExample to load the predictor after init the network
and when I call predictionsValue = JPCNNLibrary.INSTANCE.jpcnn_predict(myPredictor, predictionsValuesPointer, predictionsNamesLength);

the app just crashed and there was a error message in the logcat log "07-17 12:05:08.367 29209-29209/com.example.cam A/libc﹕ Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 29209 (com.example.cam)"

I am not sure if it is a bug of DeepBelief android library or I did not use the library correctly?

Thanks,

Jason

Compiled and tested RPI 2 jpcnn Had problem with previous /usr/lib/libjpcnn.so and include

I have successfully compiled and run the new RPI 2 jpcnn but had a slight problem. As previously noted in issue 36, I had a problem with the original RPI code on a B2. Successfully Compiled jpcnn on RPI B2 using your B2 instructions but my B2 locked up when running the test and needed to be hard booted. After looking at the problem I determined that my previous RPI B+ install,sh had copied /usr/lib/libjpcnn;so and /usr/include/libjpcnn.h. I replaced these from new source files and all works fine now. I am looking forward to doing some testing with my robot. Since the GPU is not required for jpcnn then it should be easier to use camera in parallel. I have used multiprocessor on my robot opencv program and am hoping to put jpcnn in another thread to do object recognition.
Thanks for your excellent work. Greatly Appreciated
Claude ...

I created a new install.sh in ~/projects/DeepBeliefSDK/source per below

!/bin/sh

echo "Installing libjpcnn library files"
cp libjpcnn.so /usr/lib/
cp src/include/libjpcnn.h /usr/include/
echo "Done"

Then ran
sudo ./install.sh.

FYI I also Updated to the latest 4.0 kernel
http://news.softpedia.com/news/raspberry-pi-s-default-firmware-updated-to-linux-kernel-4-0-485088.shtml
updated firmware using commands
sudo apt-get update
sudo apt-get upgrade
sudo rpi-update
sudo reboot

sudo apt-get update
sudo apt-get upgrade

RPI B2 is overclocked per /boot/config.txt entries below.

arm_freq=1000
sdram_freq=500
core_freq=500
over_voltage=2
gpu_mem=128

Here is the output from the test that took 4637 milliseconds

pi@dawn-robot ~/projects/DeepBeliefSDK/source $ ./jpcnn -i data/dog.jpg -n ../networks/jetpac.ntwk -t -m s -d


JPCNN Network with 28 layers
Node ConvNode - conv1 - _kernelWidth=11, _kernelCount=96, _marginSize=0, _sampleStride=4, _kernels->_dims=(96, 363), _bias->_dims=(96, 1)
Node ReluNode - conv1_neuron.1 -
Node ReluNode - conv1_neuron -
Node PoolNode - pool1 - _patchWidth=3, _stride=2, _mode=max
Node NormalizeNode - rnorm1 - _windowSize=5, _k=1.000000, _alpha=0.000020, _beta=0.750000
Node GConvNode - conv2 - _kernelsCount = 256, _subnodes = Node ConvNode - conv2 - _kernelWidth=5, _kernelCount=128, _marginSize=2, _sampleStride=1, _kernels->_dims=(128, 1200), _bias->_dims=(128, 1) Node ConvNode - conv2 - _kernelWidth=5, _kernelCount=128, _marginSize=2, _sampleStride=1, _kernels->_dims=(128, 1200), _bias->_dims=(128, 1)
Node ReluNode - conv2_neuron.1 -
Node ReluNode - conv2_neuron -
Node PoolNode - pool2 - _patchWidth=3, _stride=2, _mode=max
Node NormalizeNode - rnorm2 - _windowSize=5, _k=1.000000, _alpha=0.000020, _beta=0.750000
Node ConvNode - conv3 - _kernelWidth=3, _kernelCount=384, _marginSize=1, _sampleStride=1, _kernels->_dims=(384, 2304), _bias->_dims=(384, 1)
Node ReluNode - conv3_neuron.1 -
Node ReluNode - conv3_neuron -
Node GConvNode - conv4 - _kernelsCount = 384, _subnodes = Node ConvNode - conv4 - _kernelWidth=3, _kernelCount=192, _marginSize=1, _sampleStride=1, _kernels->_dims=(192, 1728), _bias->_dims=(192, 1) Node ConvNode - conv4 - _kernelWidth=3, _kernelCount=192, _marginSize=1, _sampleStride=1, _kernels->_dims=(192, 1728), _bias->_dims=(192, 1)
Node ReluNode - conv4_neuron.1 -
Node ReluNode - conv4_neuron -
Node GConvNode - conv5 - _kernelsCount = 256, _subnodes = Node ConvNode - conv5 - _kernelWidth=3, _kernelCount=128, _marginSize=1, _sampleStride=1, _kernels->_dims=(128, 1728), _bias->_dims=(128, 1) Node ConvNode - conv5 - _kernelWidth=3, _kernelCount=128, _marginSize=1, _sampleStride=1, _kernels->_dims=(128, 1728), _bias->_dims=(128, 1)
Node ReluNode - conv5_neuron.1 -
Node ReluNode - conv5_neuron -
Node PoolNode - pool5 - _patchWidth=3, _stride=2, _mode=max
Node NeuronNode - fc6 - _outputsCount=4096, _useBias=1, _weights->_dims=(4096, 9216)
Node ReluNode - fc6_neuron.1 -
Node ReluNode - fc6_neuron -
Node NeuronNode - fc7 - _outputsCount=4096, _useBias=1, _weights->_dims=(4096, 4096)
Node ReluNode - fc7_neuron.1 -
Node ReluNode - fc7_neuron -
Node NeuronNode - fc8 - _outputsCount=999, _useBias=1, _weights->_dims=(999, 4096)
Node MaxNode - probs -


0.015300 soccer ball
0.020866 standard poodle
0.169138 boxer
0.038989 corgi
0.213237 Staffordshire bullterrier
0.024005 greyhound
0.012390 English setter
0.013972 miniature poodle
0.016022 tennis ball
0.025065 dalmatian
0.394529 golden retriever
Classification took 4637 milliseconds

How to generate bindings on Android?

Specifically, there is the libjnidispatch.so and also the deepbelief.jar files. i believe these are effectively the bindings for the JCPNN api.

I was able to generate the libjpcnn.so using ndk-make. but having a hard time figuring out how to use JNA to generate these other files.

Build a custom network / Recognize multiple self-learned images

Is it possible to build a custom network and/or recognize multiple self-learned images simultaneously? If yes, any pointers?

After having studied the available functions in the API it seems to me it's only possible to load a preexisting network. The LearningExample also runs jpcnn_classify_image with a different layerOffset, but doesn't save the prediction values in the newValues array. Why is this done? Do we need to run jpcnn_classify_image and jpcnn_predict for the custom learned object, or is the first part just redundancy?

But my real problem is how I can create a predictor with multiple object, or add objects to the model. From studying the available methods it seems to me this isn't possible, I hope I'm wrong. Any help would be greatly appreciated.

Unable to compile example on a Kubuntu 12.04

Hi
I am trying to run the examples on a Kubuntu 12.04 i686 machine, but get the following error:

sudo ./install.sh
libjpcnn installed

cd ./develop/DeepBeliefSDK/$
make
gcc -o deepbelief ./main.c -L/usr/lib -ljpcnn
/usr/bin/ld: skipping incompatible /usr/lib/libjpcnn.so when searching for -ljpcnn
/usr/bin/ld: skipping incompatible /usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/libjpcnn.so when searching for -ljpcnn
/usr/bin/ld: skipping incompatible /usr/lib/../lib/libjpcnn.so when searching for -ljpcnn
/usr/bin/ld: skipping incompatible /usr/lib/gcc/i686-linux-gnu/4.6/../../../libjpcnn.so when searching for -ljpcnn
/usr/bin/ld: skipping incompatible /usr/lib/libjpcnn.so when searching for -ljpcnn
/usr/bin/ld: cannot find -ljpcnn
collect2: ld returned 1 exit status
make: *** [deepbelief] Error 1

Machine:

uname -a
Linux p4-duo 3.2.0-64-generic-pae #97-Ubuntu SMP Wed Jun 4 22:22:15 UTC 2014 i686 i686 i386 GNU/Linux

cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.4 LTS"

Any sugestions?

Thank you.

Errors on Android.mk

Hi, I was trying to recompile the sources file on Windows 7 but I ran into a few errors.

First the command:
LIBSRCS:=$(shell find src/lib -name '*.cpp')

doesn't work on windows 7 so I used the following to locate all the files:
LIBSRCS:=$(shell find src/lib -name '*.cpp')

And the following directories doesn't exist on my computer so I changed to match my path.
../eigen
/Users/petewarden/android_ndk/sources/cxx-stl/gnu-libstdc++/4.6/include
/Users/petewarden/android_ndk/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include

But I'm also getting compiler errors such as:
qpu_gemm.cpp: error: 'class Buffer' has no member named _gpuMemoryBase

'DeepBelief/DeepBelief.h' file not found in Xcode 7

In Xcode 7 adding the DeepBelief framework won't work at all for me anymore. Removing and re-adding, framework search path, nothing will work. On Xcode 6 I had to remove and re-add the framework every time I opened a project, now it can never find the header file. Any suggestions?

problem with test output

Hi,

I just tried your SDK. After downloading it, I extracted and enter $HOME/src in order to compile it:
sudo make TARGET=pi GEMM=piqpu

Then I copied the two files jpcnn and libjpcnn.so into the directory $HOME/LinuxLibrary. Then run sudo ./install.sh. Fine!

Now I compiled the example with Linux and run it to test the lena image. The output is somehow strange, since everything is zero except that the class Euopean hoopoe. I tried several other images and get the same result.

A snippet of the output:

790 0.000000 maze
791 0.000000 pajama
792 0.000000 purse
793 0.000000 parachute
794 0.000000 matchstick
795 0.000000 puffer
796 0.000000 swimming trunks
797 0.000000 volcano
798 0.000000 ptarmigan
799 0.000000 armadillo
800 0.000000 cuirass
801 0.000000 frying pan
802 0.000000 scale
803 0.000000 leatherback turtle
804 0.000000 chainlink fence
805 0.000000 tile roof
806 0.000000 pretzel
807 0.000000 burrito
808 0.515223 Euopean hoopoe
809 0.000000 cassette
810 0.000000 maraca
811 0.000000 rule
812 0.000000 jersey
813 0.000000 sunscreen
814 0.000000 espresso
815 0.000000 vase
816 0.000000 gorilla
817 0.000000 spider monkey

Do you have any idea?

libjpcnn Jetson

please let me know whether you will be able to support Jetson,
and any information armv7 192 cores CUDA 6.0 etc....

cd ../LinuxLibrary/
$ sudo ./install.sh
libjpcnn installed
$ cd ../examples/SimpleLinux/
$ make
gcc -o deepbelief ./main.c -L/usr/lib -ljpcnn
/usr/lib/libjpcnn.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
make: *** [deepbelief] Error 1

$ cd RaspberryPiLibrary/
$ sudo ./install.sh
libjpcnn installed
$ cd ../examples/SimpleLinux/
gcc -o deepbelief ./main.c -L/usr/lib -ljpcnn
$ ./deepbelief
Can't open device file: /var/lib/jpcnn/char_dev

can opengl acceleration path work

Hi Pete,
Is the opengl acceleration path in libjpcnn workable? I tried it and failed on following error message with jetpack.ntwk and dog.jpg. Can the issue be fixed?
Calling gl_gemm_fixed()
m=96, n=3000, inputK=363
Compiling 16-bit shader
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 24, 1), bDims=(3000, 24, 1)
aDims=(96, 3, 1), bDims=(3000, 3, 1)
Assertion failed: (virtualWidth % elementsPerPixel) == 0, file c:\deepbeliefsdk-gh-pages\sour
ce\src\lib\opengl\glgemm.cpp, line 1005
The HW is HSW integrated gfx.
Thanks!
-Andy

iOS examples without SquareCam code

I would find it extremely helpful if the code examples involved none of this outdated and bulky SquareCam code, but just a simple & clean AVCaptureSession setup. Maybe the examples could be changed sometimes in the future. For now, I would be very grateful if someone could share the files and or code of such a setup with me.

Why no function other than jpcnn_print_predictor for extracting trainer data?

I know that on iOS that it is not possible to write text files directly, but why not just have a return as a data-blob or string that can be stored and loaded programmatically?

Unless I'm mistaken, when working on the Mac, fprintf / stderr doesn't always route to the system console anymore, which makes the jpcnn_print_predictor demonstrated in the learning example unreliable.

AndroidExample crashes on Android 4.2 4.3

I found the crash dump in the log. It seem crash occurs when it frees the matrix in the function cblas_sgemm_fixed.

I set libc.debug.malloc to 10 and it reported rear guard mismatch for 20bytes.

E/libc ( 5319): +++ REAR GUARD MISMATCH [0, 7)
E/libc ( 5319): +++ REAR GUARD MISMATCH [8, 11)
E/libc ( 5319): +++ REAR GUARD MISMATCH [12, 20)
E/libc ( 5319): +++ ALLOCATION 0x4dfff0c8 SIZE 92928 HAS A CORRUPTED REAR GUARD
E/libc ( 5319): +++ ALLOCATION 0x4dfff0c8 SIZE 92928 ALLOCATED HERE:
E/libc ( 5319): *** *** *** *** *** *** *** *** *** *** *** *** *** *** ** ***
E/libc ( 5319): #00 pc 0000d7e0 /system/lib/libc_malloc_debug_leak.so (chk_malloc+0x17)
E/libc ( 5319): #1 pc 0000dcc6 /system/lib/libc.so (malloc+0x9)
E/libc ( 5319): #2 pc 4e224cce libjpcnn.so (cblas_sgemm_fixed(int, int, int, int, int, int, float, void_, float, float, int, int, float_, int, float, float
, int)+0x5d)

It seems some codes in cblas_sgemm_fixed function corrupt the allocated memory.
The AndroidExample does not crash on Android 4.1 and 4.4 but I can still see Rear guard mismatch msg, so it means that the memory is still corrupted, but it is lucky that the app does not crash.

The following is the crash dump.

12-31 13:09:57.465 3701-3701/? A/libc﹕ @@@ ABORTING: LIBC: ARGUMENT IS INVALID HEAP ADDRESS IN dlfree addr=0x5121e000
12-31 13:09:57.465 3701-3701/? A/libc﹕ Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 3701 (com.example.cam)
12-31 13:09:57.530 1850-1850/? I/DEBUG﹕ *** *** *** *** *** *** *** *** *** *** *** *** *** *** ** ***
12-31 13:09:57.530 1850-1850/? I/DEBUG﹕ Build fingerprint: 'samsung/GT-I9100/GT-I9100:4.0.3/IML74K/XXLPQ:user/release-keys'
12-31 13:09:57.530 1850-1850/? I/DEBUG﹕ Revision: '10'
12-31 13:09:57.530 1850-1850/? I/DEBUG﹕ pid: 3701, tid: 3701, name: com.example.cam >>> com.example.cam <<<
12-31 13:09:57.530 1850-1850/? I/DEBUG﹕ signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
12-31 13:09:57.900 1850-1850/? I/DEBUG﹕ r0 00000055 r1 bed42618 r2 00000003 r3 deadbaad
12-31 13:09:57.900 1850-1850/? I/DEBUG﹕ r4 40092228 r5 5121e000 r6 bed42640 r7 4008585a
12-31 13:09:57.900 1850-1850/? I/DEBUG﹕ r8 5121e008 r9 4f585588 sl 00000020 fp 51229588
12-31 13:09:57.900 1850-1850/? I/DEBUG﹕ ip 00000000 sp bed42640 lr 40071c69 pc 4005600c cpsr 00010030
12-31 13:09:57.900 1850-1850/? I/DEBUG﹕ d0 c1790e403eaf0c38 d1 41e4dcdfc1b49f9e
12-31 13:09:57.900 1850-1850/? I/DEBUG﹕ d2 0000000000000000 d3 0000000000000000
12-31 13:09:57.900 1850-1850/? I/DEBUG﹕ d4 bd22a1283c5bada0 d5 3ab6f0003c033c40
12-31 13:09:57.900 1850-1850/? I/DEBUG﹕ d6 8000000000000000 d7 3f80000000000000
12-31 13:09:57.900 1850-1850/? I/DEBUG﹕ d8 bec96d47bec96d47 d9 bec96d47bec96d47
12-31 13:09:57.900 1850-1850/? I/DEBUG﹕ d10 3750324e3750324e d11 3750324e3750324e
12-31 13:09:57.900 1850-1850/? I/DEBUG﹕ d12 0000000000000000 d13 0000000000000000
12-31 13:09:57.905 1850-1850/? I/DEBUG﹕ d14 0000000000000000 d15 0000000000000000
12-31 13:09:57.905 1850-1850/? I/DEBUG﹕ d16 42253b40c209c66b d17 c367fa72c2e77db0
12-31 13:09:57.910 1850-1850/? I/DEBUG﹕ d18 0000000000000000 d19 0000000000000000
12-31 13:09:57.910 1850-1850/? I/DEBUG﹕ d20 0000000000000000 d21 0000000000000000
12-31 13:09:57.910 1850-1850/? I/DEBUG﹕ d22 419033abc203c170 d23 c10d9a20c198f3cc
12-31 13:09:57.910 1850-1850/? I/DEBUG﹕ d24 3d88e5243d10bc18 d25 bda932d03d97ea44
12-31 13:09:57.910 1850-1850/? I/DEBUG﹕ d26 3f8000003f800000 d27 3f8000003f800000
12-31 13:09:57.910 1850-1850/? I/DEBUG﹕ d28 4051a513c03de1bc d29 41694fcd40c6fd80
12-31 13:09:57.910 1850-1850/? I/DEBUG﹕ d30 c1790e403eaf0c38 d31 41e4dcdfc1b49f9e
12-31 13:09:57.910 1850-1850/? I/DEBUG﹕ scr 60000010
12-31 13:09:57.925 1850-1850/? I/DEBUG﹕ backtrace:
12-31 13:09:57.925 1850-1850/? I/DEBUG﹕ #00 pc 0000f00c /system/lib/libc.so
12-31 13:09:57.925 1850-1850/? I/DEBUG﹕ #1 pc 00011db3 /system/lib/libc.so (dlfree+1458)
12-31 13:09:57.925 1850-1850/? I/DEBUG﹕ #2 pc 0000cf73 /system/lib/libc.so (free+10)
12-31 13:09:57.925 1850-1850/? I/DEBUG﹕ #3 pc 0000fe5b /data/app-lib/com.example.cam-1/libjpcnn.so (cblas_sgemm_fixed(int, int, int, int, int, int, float, void_, float, float, int, int, float_, int, float, float_, int)+490)
12-31 13:09:57.925 1850-1850/? I/DEBUG﹕ #4 pc 0000d61b /data/app-lib/com.example.cam-1/libjpcnn.so (matrix_correlate(Buffer_, Buffer
, int, int, int, bool)+1514)

iOS - read only file system?

"Since you can't save files on iOS devices, the only way to create this file in the first place is to call jpcnn_print_predictor once you've created a predictor, and then copy and paste the results from the developer console into a file, and then add it to your app's resources."

Is this a hold over in the docs since I notice jpcnn_save_predictor in libjpcnn.h?

jpcnn_print_predictor buggy?

I'm changing the learning example so that the predictor output can be saved as a file inside the app's documents directory instead of being output to the console. This already works, however I've run into issues due to what I believe is a bug in the mentioned method. After jpcnn_print_predictor(predictor) is called, no further fprintf or NSLog calls deliver anything to the console, leading me to believe that the jpcnn_print_predictor method must somehow not 'close' properly.

So, even in your own example, "------------- end of SVM File output - copy lines above ------------\n" is never printed.

OpenCV version

not possible without source of course but add your +1 if you think its a good idea.

just balck screen on android

I run android example and i found the below errors:

@@@ ABORTING: LIBC: ARGUMENT IS INVALID HEAP ADDRESS IN dlfree addr=0x65b6e000
Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 6374 (com.example.cam)

Rebuild with bitcode enabled

Hey Pete,

I know your busy, and support for DeepBelief is low/non-priority

But could we get the next build with bitcode enabled? It would give DeepBelief longer legs, once apple starts making bit code mandatory.

Here's the error, and the current fix is as easy as changing the Enable Bitcode setting in Build Settings from YES to NO.

Current error message reads
'''
'/Frameworks/DeepBelief.framework(libjpcnn.o)' does not contain bitcode. You must rebuild it with bicode enabled (XCode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64
clang: error: linker command failed with exit code 1
'''

Pretty sure there's no way I can rebuild the package on my side, is there?

Lucky to have folks like you on the planet.

training image processing

The paper describes your initial image processing approach as:

- we down-sampled the images to a fixed resolution of 256x256. 
Given a rectangular image, we first rescaled the image such that the 
shorter side was of length 256, and then cropped out the 
central 256x256 patch from the resulting image.

Have you considered using a graphcut (such as gimp's resynthesize) to reduce the image instead of cropping the internal region. I.e. graphcut original to a square - then scale.
http://www.logarithmic.net/pfh/resynthesizer

On most random imagery this approach might give improved results.
Of course I have no data as to the relative squareness of the original images and how much image information was "lost" to cropping.

Raspberry Pi 2 : Error makefile 107 buffer.o

I make on Raspberry Pi 2. But it have error:

Makefile:107: recipe for target 'src/lib/graph/buffer.o' failed
make: *** [src/lib/graph/buffer.o] Error 1

Please help me solve this problem. Thanks

WebGl misprediction in demo

On the demo page http://jetpacapp.github.io/DeepBeliefSDK/ , having WebGL enabled runs, but always predicts slightly changing activations of around 52% for 'European Hoopoe' and 48% 'Hacksaw'. No other activation is ever predicted. Disabling WebGL solves the problem.

Chrome Browser 37.0.2062.120 on Linux using an Intel HD3000 GPU.

Trainer (?)

Hello all,

I have been using the DeepBeliefSDK for a couple projects and I must say its very impressive. Recently have created a way to create and store multiple trainers inside an ios app. Decided to go a bit further and began to implement a method to load in captured photos from the phones library.

The only issue I am having is when it comes to plugging that image chosen into a custom trainer object. I have tried manipulating the pixelBuffer to have the image overlay the video output but that doesn't seem to work well.

  • User chooses image from their photo library which gets saved in a manner that the app can reach it.
  • Upon selecting an image the imagePath synthesizes the path and holds on to it.

Now that I have the path to the image, how do I put that image into a format that I can feed it to the jpcnn_train void to use only that one image for the positive predictions? I have tried many different ways with the following two lines during the positive predictons.

trainer = jpcnn_create_trainer( ?here? ) ;
jpcnn_train(?here?, predictions, predictionsLength);

Any help is greatly appreciated!
Thanks.

SimpleLinux example

I am having trouble getting the SimpleLinux example to print the prediction labels on the PI. I see on the README it says after compiling and running it should print these labels. But I don't think the labels are printed int he code committed to the repository, and when I try to add this it crashes my PI GPU and I have to reboot to be able to run again. With the current version in the repository it only prints the prediction index. Any ideas? :) Thank you!

Caffe into DeepBeliefSDK??

Is there any interest in having a script that converts/imports pre-trained models from Caffe into DeepBeliefSDK? Cheers.

Framework not working on Xcode 6.2 / iOS 8.2?

Anyone else having issues running the framework on the newest software? I've been away from working on it for a while, so I may be overseeing something.

I get the following error on all my projects:
Thread 5: EXC_BAD_ACCESS (code=1, address=0x9)
at DeepBCustom`jpcnn_classify_image at libjpcnn.cpp:108:

Raspberry PI B 2 locks up

I have successfully installed and run the SDK on one of my RPI B+ with no problems. Memory set to 128.
Tried the same install procedure several times on a new RPI B 2 quadcore. The machine consistently locks up when trying to run the example/SimpleLinux sudo ./deepbelief test. RPI then needs a hard reboot to get working again. Not sure if this is an issue with RPI B 2 but would like to see if anyone else has a similar problem.
Thanks

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.