Skip to content

Instantly share code, notes, and snippets.

@liuliu
Last active August 29, 2015 14:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save liuliu/9c737fa53a62d7165f2c to your computer and use it in GitHub Desktop.
Save liuliu/9c737fa53a62d7165f2c to your computer and use it in GitHub Desktop.
int f;
for (f = 10; f < 13; f++)
{
int i, j, k;
ccv_convnet_layer_t *layer = convnet->layers + f;
char filename[256];
float kmean[256];
sprintf(filename, "lut-layer-%d.txt", f);
FILE *r = fopen(filename, "r");
for (i = 0; i < 0x100; i++)
{
union {
int i;
float f;
} v;
fscanf(r, "%d %d", &j, &v.i);
kmean[i] = v.f;
}
fclose(r);
for (i = 0; i < 0x100; i++)
{
k = i;
for (j = i + 1; j < 0x100; j++)
if (kmean[j] < kmean[k])
k = j;
float t = kmean[k];
kmean[k] = kmean[i];
kmean[i] = t;
}
ccv_dense_matrix_t* pngw = 0;
sprintf(filename, "layer-%d-crush.png", f);
ccv_read(filename, &pngw, CCV_IO_ANY_FILE | CCV_IO_GRAY);
for (i = 0; i < pngw->rows; i++)
for (j = 0; j < pngw->cols; j++)
layer->w[i * pngw->cols + j] = kmean[pngw->data.u8[i * pngw->cols + j]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment