Skip to content

Commit

Permalink
bug fix^2
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuichiro Nakada committed Aug 17, 2018
1 parent a7f757f commit 911d69e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ for more information, see example/
$ ./sin

## Demo
- Recognizing handwritten digits by MNIST training (example/mnist_train.c)
- Recognizing handwritten digits by MNIST training ([example/mnist_train.c](example/mnist_train.c))
- http://yui0.github.io/catseye/example/html/mnist.html

- Recognizing pictures (example/cifar10_train.c)
- Recognizing pictures ([example/cifar10_train.c](example/cifar10_train.c))
- http://yui0.github.io/catseye/example/html/cifar10.html

- Neural Network 'paints' an image (example/paint.c)
- Neural Network 'paints' an image ([example/paint.c](example/paint.c))

![Sakura](example/paint_sakura.png)
[![Sakura](example/paint_sakura0499.png)](http://www.youtube.com/watch?v=445ilzeKtto)
Expand All @@ -64,12 +64,12 @@ for more information, see example/
![Nyanko](example/paint_cat.png)
[![Nyanko](example/paint_cat0499.png)](http://www.youtube.com/watch?v=qy_R2gp5rx0)

- Function approximation (example/sin.c)
- Function approximation ([example/sin.c](example/sin.c))

![sin](example/sin.png)
![quadratic function](example/quadratic.png)

- Autoencoder (example/mnist_autoencoder.c)
- Autoencoder ([example/mnist_autoencoder.c](example/mnist_autoencoder.c))
- Unit 64 [tied weight]

![epoch=100](example/mnist_autoencoder_u64ae_s100.png "epoch=100")
Expand Down
42 changes: 29 additions & 13 deletions catseye.h
Original file line number Diff line number Diff line change
Expand Up @@ -1161,19 +1161,20 @@ void __CatsEye__construct(CatsEye *this, CatsEye_layer *layer, int layers)
this->dsize = 0;
this->w = malloc(sizeof(real*)*(this->layers-1)); // weights
this->ws = malloc(sizeof(int)*(this->layers-1));
int n[this->layers], m[this->layers];
this->wsize = 0;

int n[this->layers], m[this->layers];
for (int i=0; i<this->layers; i++) {
CatsEye_layer *l = &this->layer[i];

if (i<this->layers-1) {
l->outputs = layer[i+1].inputs;
// l->outputs = layer[i+1].inputs;
l->forward = _CatsEye_layer_forward[layer[i].type];
l->backward = _CatsEye_layer_backward[layer[i].type];
if (!i && layer[i].type!=CATS_RECURRENT) l->backward = CatsEye_none;
l->update = _CatsEye_layer_update[layer[i].type];
} else { // last layer
l->outputs = 1;
if (!l->outputs) l->outputs = 1;
l->forward = CatsEye_none;
l->backward = CatsEye_none;
l->update = CatsEye_none;
Expand All @@ -1184,29 +1185,39 @@ void __CatsEye__construct(CatsEye *this, CatsEye_layer *layer, int layers)
if (i>0) l->dact = CatsEye_dact[layer[i-1].activation];
else l->dact = CatsEye_dact[layer[i].activation];

/* if (i>0 && layer[i].type!=CATS_LINEAR) {
this->layer[i-1].outputs = l->inputs;
if (i>0) {
// this->layer[i-1].outputs = l->inputs;
l->ich = this->layer[i-1].ch;
if (!l->sx) {
/* if (!l->sx && l->ich) {
// printf("%d/%d\n", this->layer[i-1].inputs, l->ich);
l->sx = l->sy = sqrt(this->layer[i-1].inputs/l->ich);
}
}*/
}*/
if (!l->inputs) l->inputs = this->layer[i-1].outputs;
} else {
if (!l->ch) l->ch = 1;
if (!l->ich) l->ich = 1;
}
if (!l->sx && l->ich) l->sx = l->sy = sqrt(l->inputs/l->ich);

switch (layer[i].type) {
case CATS_CONV:
l->inputs = l->ch * (l->sx - l->ksize/2*2) * (l->sy - l->ksize/2*2);
// l->inputs = l->ch * (l->sx - l->ksize/2*2) * (l->sy - l->ksize/2*2);
l->outputs = l->ch * (l->sx - l->ksize/2*2) * (l->sy - l->ksize/2*2);
// printf("L%02d in:[%dx%dx%d] out:[%d]\n", i, u[CHANNEL-LPLEN], u[XSIZE], u[YSIZE], u[SIZE]);
n[i] = l->ksize * l->ksize; // kernel size
m[i] = l->ch * l->ich; // channel
printf("L%02d: CONV%d-%d (%d[ksize]x%d[ch])\n", i+1, l->ksize, l->ch, n[i], m[i]);
printf("L%02d: CONV%d-%d i/o:%d/%d (%d[ksize^2]x%d[ch])\n", i+1, l->ksize, l->ch, l->inputs, l->outputs, n[i], m[i]);
// this->layer[i-1].outputs = l->inputs;
break;
case CATS_MAXPOOL:
l->ch = l->ich;
l->inputs = l->ch * (l->sx - l->ksize) * (l->sy - l->ksize);
// l->inputs = l->ch * (l->sx - l->ksize) * (l->sy - l->ksize);
l->outputs = l->ch * (l->sx/l->ksize) * (l->sy/l->ksize);
// printf("L%02d in:[%dx%dx%d] out:[%d]\n", i, u[CHANNEL-LPLEN], u[XSIZE], u[YSIZE], u[SIZE]);
n[i] = l->ch * l->sx * l->sy;//SIZE(i);
m[i] = 1;
printf("L%02d: POOL%d [%d]\n", i+1, l->ksize, n[i]);
printf("L%02d: POOL%d-%d (sx:%d sy:%d [%d])\n", i+1, l->ksize, l->ch, l->sx, l->sy, n[i]);
// this->layer[i-1].outputs = l->inputs;
break;
case CATS_RECURRENT:
l->Wi = calloc(l->inputs * l->hiddens, sizeof(real));
Expand All @@ -1231,14 +1242,19 @@ void __CatsEye__construct(CatsEye *this, CatsEye_layer *layer, int layers)
m[i] = l->hiddens;
printf("L%02d: RECURRENT %d %d\n", i+1, n[i], m[i]);
break;
default:
default: // LINEAR
// if (i>0 && !l->inputs) l->inputs = this->layer[i-1].outputs;
if (i<this->layers-1) l->outputs = layer[i+1].inputs;
n[i] = l->inputs;
m[i] = l->outputs;
printf("L%02d: LINEAR %d %d\n", i+1, n[i], m[i]);
}
wsize[i] = this->wsize;
this->ws[i] = (n[i]+1)*m[i];
this->wsize += this->ws[i];
// }
// for (int i=0; i<this->layers; i++) {
// CatsEye_layer *l = &this->layer[i];

osize[i] = this->osize;
this->osize += l->inputs+1; // bias
Expand Down
8 changes: 0 additions & 8 deletions example/sin.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,9 @@ int main()
CatsEye cat;
CatsEye__construct(&cat, 0, 0, layers, u);

/*int _u[] = {
size, CATS_LINEAR, CATS_ACT_SIGMOID, 0,
100, CATS_LINEAR, CATS_ACT_IDENTITY, 0,
1, CATS_LOSS, CATS_LOSS_MSE, 0,
};
CatsEye_construct(&cat, _u);*/

// 訓練データ
double x[sample];
for (int i=0; i<sample; i++) x[i] = 2.0*M_PI / sample * i;
// ラベルデータ
double t[sample];
for (int i=0; i<sample; i++) t[i] = sin(x[i]);

Expand Down

0 comments on commit 911d69e

Please sign in to comment.