Skip to content

Instantly share code, notes, and snippets.

@liuliu
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save liuliu/10b7b067ace070ee7e33 to your computer and use it in GitHub Desktop.
Save liuliu/10b7b067ace070ee7e33 to your computer and use it in GitHub Desktop.
static void ccv_convnet_read_extra(ccv_convnet_t* convnet, const char* filename)
{
sqlite3* db = 0;
if (SQLITE_OK == sqlite3_open(filename, &db))
{
sqlite3_stmt* layer_quant_stmt = 0;
const char layer_quant_qs[] =
"SELECT layer, quant FROM layer_quant;";
if (SQLITE_OK == sqlite3_prepare_v2(db, layer_quant_qs, sizeof(layer_quant_qs), &layer_quant_stmt, 0))
{
while (sqlite3_step(layer_quant_stmt) == SQLITE_ROW)
{
ccv_convnet_layer_t* layer = convnet->layers + sqlite3_column_int(layer_quant_stmt, 0);
int qnum = sqlite3_column_bytes(layer_quant_stmt, 1) / sizeof(uint16_t);
// if weights available, load weights
ccv_dense_matrix_t* w = 0;
char wname[256];
switch (qnum)
{
case 0x10:
sprintf(wname, "layer-%d-4bit-crush.png", sqlite3_column_int(layer_quant_stmt, 0));
break;
case 0x100:
sprintf(wname, "layer-%d-crush.png", sqlite3_column_int(layer_quant_stmt, 0));
break;
}
ccv_read(wname, &w, CCV_IO_ANY_FILE | CCV_IO_GRAY);
const void* q = sqlite3_column_blob(layer_quant_stmt, 1);
float f[256];
ccv_half_precision_to_float((uint16_t*)q, f, qnum);
int j, k;
for (j = 0; j < w->rows; j++)
for (k = 0; k < w->cols; k++)
layer->w[j * w->cols + k] = f[w->data.u8[j * w->cols + k]];
ccv_matrix_free(w);
}
sqlite3_finalize(layer_quant_stmt);
}
}
sqlite3_close(db);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment