# HG changeset patch # User boulanni # Date 1275456889 14400 # Node ID 269c39f55134fe9b78c8b556b6443a2460f27ec1 # Parent 84f42fe05594a0016d14484d8b09ce972980bd42 Added demo source files diff -r 84f42fe05594 -r 269c39f55134 demo/Test1.mxml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/Test1.mxml Wed Jun 02 01:34:49 2010 -0400 @@ -0,0 +1,327 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + imdraw.width || y<0 || y>imdraw.height) { + stop_drawing(e) + return + }*/ + can2.graphics.lineTo(x, y); + changeDrawing() + changeImage() + e.updateAfterEvent(); + } + + private function changeDrawing():void{ + var bitmapDataObject2:BitmapData = new BitmapData(32, 32, false, 0x00000000); + var rect:Rectangle = new Rectangle(0, 0, 32, 32); + var m:Matrix = new Matrix() + m.scale(32/imdraw.width, 32/imdraw.height) + bitmapDataObject2.draw(can2,m,null,null,null,true); + var myBitmap:Bitmap = new Bitmap(bitmapDataObject2); + imdraw.source = myBitmap; + } + + private var ready:Boolean = false; + private var cache:Number; + public function RandNormal(sigma:Number):Number { + ready = !ready; + if (!ready) return cache * sigma; + var x:Number = Math.sqrt(-2 * Math.log(Math.random())), y:Number = Math.random() + cache = x * Math.cos(2*Math.PI*y); + return x * Math.sin(2*Math.PI*y) * sigma; + } + + private function changeImage():void{ + + var bitmapDataObject2:BitmapData = new BitmapData(32, 32, false, 0x00000000); + + var can3:Sprite = new Sprite() + var x:Number, y:Number, l:int, t:Number, w:int, c:uint, n:uint + n = int(0.999 + 3*rat.value) + for(var j:uint=0; j + + + + + + + + + + + + + + Shallow MLP 500 h.u. /NIST + Deep SDA 3x1000 h.u. /P07 + + + + + + + + + + + + + + diff -r 84f42fe05594 -r 269c39f55134 demo/default.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/default.php Wed Jun 02 01:34:49 2010 -0400 @@ -0,0 +1,48 @@ + +Demo + + +

Deep Self-Taught Learning for Handwritten Character Recognition

+ +

+This demo allows you to compare two neural network detectors of handwritten characters: +

+Both classifiers are trained on P07, a distribution that combines multiple datasets and stochastic transformations. +

+ +

+The demo provides real-time detection of characters as you draw (left panel) and apply transforms (middle panel) similar to the ones in P07. The three best results are shown (right panel) along with the confidence of the detector. +

+ +

The following applet requires Adobe Flash Player 10.

+ + + + + + + + + + +

+Free hosting provided by 000webhost.com +

+ + + + + + + + diff -r 84f42fe05594 -r 269c39f55134 demo/mlp_conv.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/mlp_conv.c Wed Jun 02 01:34:49 2010 -0400 @@ -0,0 +1,148 @@ + +#include "AS3.h" +#include + +typedef struct { + int n,x,y; + float *w, *b; + int nonlin; // 0aucune,1sigm,2tanh,3softmax + int maxpool; // 01 +} LAYER; + +LAYER models[] = { {500,32,32,0,0,2,0},{62,1,1,0,0,3,0}, {1000,32,32,0,0,1,0},{1000,1,1,0,0,1,0},{1000,1,1,0,0,1,0},{62,1,1,0,0,1,0} }; +int mod_i[] = {0,2,6}; + +LAYER *L; +int nl; + +float *data, *o; +#define BUF_SIZE 20000 + +static AS3_Val initparam(void* self, AS3_Val args) { + AS3_Val tmp = AS3_Undefined(); + int il, len; + + for (il=0; il < sizeof(models)/sizeof(LAYER); ++il) { + tmp = AS3_Get(args, AS3_Int(2*il)); + len = AS3_IntValue(AS3_GetS(tmp, "length")); + models[il].w = (float*) malloc(len); + AS3_ByteArray_readBytes(models[il].w, tmp, len); + + tmp = AS3_Get(args, AS3_Int(2*il+1)); + len = AS3_IntValue(AS3_GetS(tmp, "length")); + models[il].b = (float*) malloc(len); + AS3_ByteArray_readBytes(models[il].b, tmp, len); + } + + data = (float*) malloc(BUF_SIZE); + o = (float*) malloc(BUF_SIZE); + + return AS3_Int(0); +} + +static AS3_Val choosemodel(void* self, AS3_Val args) { + int il; + + AS3_ArrayValue( args, "IntType", &il ); + + L = models + mod_i[il]; + nl = mod_i[il+1] - mod_i[il]; + + return AS3_Int(0); +} + +static AS3_Val prediction(void* self, AS3_Val args) { + AS3_Val in_arr = AS3_Undefined(), out_arr = AS3_Array(0); + float *tmp, d, e; + int i,j,k,l, n,x,y, newx,newy, il, dx,dy; + LAYER *pL; + + AS3_ArrayValue( args, "AS3ValType", &in_arr ); + + for(i=0; i < 1024; ++i) + data[i] = AS3_IntValue(AS3_Get(in_arr, AS3_Int(4*i+1))) /255.0; + + n = 1; + x = 32; + y = 32; + + #define DATA(l,j,i) data[((l)*y + (j))*x + (i)] + #define O(k,dy,dx) o[((k)*newy + (dy))*newx + (dx)] + #define W(k,l,j,i) pL->w[(((k)*n + (l))*pL->y + (j))*pL->x + (i)] + + for (il=0; il < nl; ++il) { + flyield(); + pL = L+il; + newx = x+1-pL->x; + newy = y+1-pL->y; + + for (dx=0; dx < newx; ++dx) + for (dy=0; dy < newy; ++dy) + for (k=0; k < pL->n; ++k) { + d = pL->b[k]; + for (l=0; l < n; ++l) + for(j=0; j < pL->y; ++j) + for(i=0; i < pL->x; ++i) + d += DATA(l,j+dy,i+dx)*W(k,l,j,i); + O(k,dy,dx) = d; + } + + if(pL->maxpool) { + for (k=0; k < pL->n; ++k) + for (dx=0; dx < newx; dx+=2) + for (dy=0; dy < newy; dy+=2) { + d=O(k,dy,dx); + e=O(k,dy,dx+1); if(e>d) d=e; + e=O(k,dy+1,dx); if(e>d) d=e; + e=O(k,dy+1,dx+1); if(e>d) d=e; + O(k,dy/2,dx/2)=d; + } + newx /= 2; + newy /= 2; + } + + for (dx=0; dx < newx; ++dx) + for (dy=0; dy < newy; ++dy) { + e = 0; + for (k=0; k < pL->n; ++k) { + d = O(k,dy,dx); + if(pL->nonlin==1) d=1.0/(1.0 + exp(-d)); + else if(pL->nonlin==2) d=tanh(d); + else if(pL->nonlin==3) { d=exp(d); e += d; } + O(k,dy,dx) = d; + } + if(pL->nonlin==3 && e) + for (k=0; k < pL->n; ++k) + O(k,dy,dx) /= e; + } + + tmp = data; + data = o; + o = tmp; + + x = newx; + y = newy; + n = pL->n; + } + + for(i=0; i < n*x*y; ++i) + AS3_Set(out_arr, AS3_Int(i), AS3_Number(data[i])); + + return out_arr; +} + +int main() { + AS3_Val initparamMethod = AS3_Function( NULL, initparam ); + AS3_Val choosemodelMethod = AS3_Function( NULL, choosemodel ); + AS3_Val predictionMethod = AS3_FunctionAsync( NULL, prediction ); + + AS3_Val result = AS3_Object( "initparam: AS3ValType, choosemodel: AS3ValType, prediction: AS3ValType", initparamMethod, choosemodelMethod, predictionMethod ); + + AS3_Release( initparamMethod ); + AS3_Release( choosemodelMethod ); + AS3_Release( predictionMethod ); + + AS3_LibInit( result ); + + return 0; +}