|
|
|
@@ -103,7 +103,12 @@ int Net::register_custom_layer(int index, layer_creator_func creator) |
|
|
|
int Net::load_param(FILE* fp) |
|
|
|
{ |
|
|
|
int magic = 0; |
|
|
|
fscanf(fp, "%d", &magic); |
|
|
|
int nbr = fscanf(fp, "%d", &magic); |
|
|
|
if (nbr != 1) |
|
|
|
{ |
|
|
|
fprintf(stderr, "issue with param file\n"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
if (magic != 7767517) |
|
|
|
{ |
|
|
|
fprintf(stderr, "param is too old, please regenerate\n"); |
|
|
|
@@ -113,10 +118,15 @@ int Net::load_param(FILE* fp) |
|
|
|
// parse |
|
|
|
int layer_count = 0; |
|
|
|
int blob_count = 0; |
|
|
|
fscanf(fp, "%d %d", &layer_count, &blob_count); |
|
|
|
nbr = fscanf(fp, "%d %d", &layer_count, &blob_count); |
|
|
|
if (nbr != 2 || layer_count <= 0 || blob_count <= 0) |
|
|
|
{ |
|
|
|
fprintf(stderr, "issue with param file\n"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
layers.resize(layer_count); |
|
|
|
blobs.resize(blob_count); |
|
|
|
layers.resize((size_t)layer_count); |
|
|
|
blobs.resize((size_t)blob_count); |
|
|
|
|
|
|
|
ParamDict pd; |
|
|
|
pd.use_winograd_convolution = use_winograd_convolution; |
|
|
|
@@ -397,21 +407,34 @@ int Net::load_param(const char* protopath) |
|
|
|
} |
|
|
|
#endif // NCNN_STRING |
|
|
|
|
|
|
|
template<typename T> bool readValue(T & val, FILE * fp) |
|
|
|
{ |
|
|
|
size_t res = fread(&val, sizeof(T), 1, fp); |
|
|
|
if (res != sizeof(T)) { |
|
|
|
fprintf(stderr, "issue with param file reading\n"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
int Net::load_param_bin(FILE* fp) |
|
|
|
{ |
|
|
|
int magic = 0; |
|
|
|
fread(&magic, sizeof(int), 1, fp); |
|
|
|
if (!readValue(magic, fp)) |
|
|
|
return -1; |
|
|
|
if (magic != 7767517) |
|
|
|
{ |
|
|
|
fprintf(stderr, "param is too old, please regenerate\n"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
int layer_count = 0; |
|
|
|
fread(&layer_count, sizeof(int), 1, fp); |
|
|
|
size_t layer_count = 0; |
|
|
|
if (!readValue(layer_count, fp)) |
|
|
|
return -1; |
|
|
|
|
|
|
|
int blob_count = 0; |
|
|
|
fread(&blob_count, sizeof(int), 1, fp); |
|
|
|
size_t blob_count = 0; |
|
|
|
if (!readValue(blob_count, fp)) |
|
|
|
return -1; |
|
|
|
|
|
|
|
layers.resize(layer_count); |
|
|
|
blobs.resize(blob_count); |
|
|
|
@@ -421,16 +444,19 @@ int Net::load_param_bin(FILE* fp) |
|
|
|
pd.use_sgemm_convolution = use_sgemm_convolution; |
|
|
|
pd.use_int8_inference = use_int8_inference; |
|
|
|
|
|
|
|
for (int i=0; i<layer_count; i++) |
|
|
|
for (size_t i=0; i<layer_count; i++) |
|
|
|
{ |
|
|
|
int typeindex; |
|
|
|
fread(&typeindex, sizeof(int), 1, fp); |
|
|
|
if (!readValue(typeindex, fp)) |
|
|
|
return -1; |
|
|
|
|
|
|
|
int bottom_count; |
|
|
|
fread(&bottom_count, sizeof(int), 1, fp); |
|
|
|
size_t bottom_count; |
|
|
|
if (!readValue(bottom_count, fp)) |
|
|
|
return -1; |
|
|
|
|
|
|
|
int top_count; |
|
|
|
fread(&top_count, sizeof(int), 1, fp); |
|
|
|
size_t top_count; |
|
|
|
if (!readValue(top_count, fp)) |
|
|
|
return -1; |
|
|
|
|
|
|
|
Layer* layer = create_layer(typeindex); |
|
|
|
if (!layer) |
|
|
|
@@ -450,10 +476,11 @@ int Net::load_param_bin(FILE* fp) |
|
|
|
// fprintf(stderr, "new layer %d\n", typeindex); |
|
|
|
|
|
|
|
layer->bottoms.resize(bottom_count); |
|
|
|
for (int j=0; j<bottom_count; j++) |
|
|
|
for (size_t j=0; j<bottom_count; j++) |
|
|
|
{ |
|
|
|
int bottom_blob_index; |
|
|
|
fread(&bottom_blob_index, sizeof(int), 1, fp); |
|
|
|
size_t bottom_blob_index; |
|
|
|
if (!readValue(bottom_blob_index, fp)) |
|
|
|
return -1; |
|
|
|
|
|
|
|
Blob& blob = blobs[bottom_blob_index]; |
|
|
|
|
|
|
|
@@ -463,10 +490,11 @@ int Net::load_param_bin(FILE* fp) |
|
|
|
} |
|
|
|
|
|
|
|
layer->tops.resize(top_count); |
|
|
|
for (int j=0; j<top_count; j++) |
|
|
|
for (size_t j=0; j<top_count; j++) |
|
|
|
{ |
|
|
|
int top_blob_index; |
|
|
|
fread(&top_blob_index, sizeof(int), 1, fp); |
|
|
|
size_t top_blob_index; |
|
|
|
if (!readValue(top_blob_index, fp)) |
|
|
|
return -1; |
|
|
|
|
|
|
|
Blob& blob = blobs[top_blob_index]; |
|
|
|
|
|
|
|
|