2020-12-19 17:46:41 +01:00
|
|
|
import { extractWeightsFactory, ParamMapping } from '../common/index';
|
2020-08-18 13:54:53 +02:00
|
|
|
import { extractorsFactory } from './extractorsFactory';
|
|
|
|
import { FaceFeatureExtractorParams } from './types';
|
|
|
|
|
|
|
|
export function extractParams(weights: Float32Array): { params: FaceFeatureExtractorParams, paramMappings: ParamMapping[] } {
|
2020-12-23 17:26:55 +01:00
|
|
|
const paramMappings: ParamMapping[] = [];
|
2020-08-18 13:54:53 +02:00
|
|
|
|
|
|
|
const {
|
|
|
|
extractWeights,
|
2020-12-23 17:26:55 +01:00
|
|
|
getRemainingWeights,
|
|
|
|
} = extractWeightsFactory(weights);
|
2020-08-18 13:54:53 +02:00
|
|
|
|
|
|
|
const {
|
2020-12-23 17:26:55 +01:00
|
|
|
extractDenseBlock4Params,
|
|
|
|
} = extractorsFactory(extractWeights, paramMappings);
|
2020-08-18 13:54:53 +02:00
|
|
|
|
2020-12-23 17:26:55 +01:00
|
|
|
const dense0 = extractDenseBlock4Params(3, 32, 'dense0', true);
|
|
|
|
const dense1 = extractDenseBlock4Params(32, 64, 'dense1');
|
|
|
|
const dense2 = extractDenseBlock4Params(64, 128, 'dense2');
|
|
|
|
const dense3 = extractDenseBlock4Params(128, 256, 'dense3');
|
2020-08-18 13:54:53 +02:00
|
|
|
|
|
|
|
if (getRemainingWeights().length !== 0) {
|
2020-12-23 17:26:55 +01:00
|
|
|
throw new Error(`weights remaing after extract: ${getRemainingWeights().length}`);
|
2020-08-18 13:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
paramMappings,
|
2020-12-23 17:26:55 +01:00
|
|
|
params: {
|
|
|
|
dense0, dense1, dense2, dense3,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|