in libvmaf/src/read_json_model.c [286:404]
static int parse_model_dict(json_stream *s, VmafModel *model,
enum VmafModelFlags flags)
{
if (json_next(s) != JSON_OBJECT)
return -EINVAL;
while (json_peek(s) != JSON_OBJECT_END && !json_get_error(s)) {
if (json_next(s) != JSON_STRING)
return -EINVAL;
const char *key = json_get_string(s, NULL);
if (!strcmp(key, "score_transform")) {
if (json_next(s) != JSON_OBJECT)
return -EINVAL;
int err = parse_score_transform(s, model);
if (err) return err;
if (!model->score_transform.enabled &&
(flags & VMAF_MODEL_FLAG_ENABLE_TRANSFORM)) {
model->score_transform.enabled = true;
}
json_skip_until(s, JSON_OBJECT_END);
continue;
}
if (!strcmp(key, "model_type")) {
if (json_next(s) != JSON_STRING)
return -EINVAL;
const char *model_type = json_get_string(s, NULL);
if (!strcmp(model_type, "RESIDUEBOOTSTRAP_LIBSVMNUSVR"))
model->type = VMAF_MODEL_RESIDUE_BOOTSTRAP_SVM_NUSVR;
else if (!strcmp(model_type, "BOOTSTRAP_LIBSVMNUSVR"))
model->type = VMAF_MODEL_BOOTSTRAP_SVM_NUSVR;
else if (!strcmp(model_type, "LIBSVMNUSVR"))
model->type = VMAF_MODEL_TYPE_SVM_NUSVR;
else
return -EINVAL;
continue;
}
if (!strcmp(key, "norm_type")) {
if (json_next(s) != JSON_STRING)
return -EINVAL;
const char *norm_type = json_get_string(s, NULL);
if (!strcmp(norm_type, "linear_rescale"))
model->norm_type = VMAF_MODEL_NORMALIZATION_TYPE_LINEAR_RESCALE;
else if (!strcmp(norm_type, "none"))
model->norm_type = VMAF_MODEL_NORMALIZATION_TYPE_NONE;
else
return -EINVAL;
continue;
}
if (!strcmp(key, "score_clip")) {
if (json_next(s) != JSON_ARRAY)
return -EINVAL;
if (!(flags & VMAF_MODEL_FLAG_DISABLE_CLIP)) {
model->score_clip.enabled = true;
if (json_next(s) != JSON_NUMBER)
return -EINVAL;
model->score_clip.min = json_get_number(s);
if (json_next(s) != JSON_NUMBER)
return -EINVAL;
model->score_clip.max = json_get_number(s);
}
json_skip_until(s, JSON_ARRAY_END);
continue;
}
if (!strcmp(key, "slopes")) {
if (json_next(s) != JSON_ARRAY)
return -EINVAL;
int err = parse_slopes(s, model);
if (err) return err;
json_skip_until(s, JSON_ARRAY_END);
continue;
}
if (!strcmp(key, "intercepts")) {
if (json_next(s) != JSON_ARRAY)
return -EINVAL;
int err = parse_intercepts(s, model);
if (err) return err;
json_skip_until(s, JSON_ARRAY_END);
continue;
}
if (!strcmp(key, "feature_names")) {
if (json_next(s) != JSON_ARRAY)
return -EINVAL;
int err = parse_feature_names(s, model);
if (err) return err;
continue;
}
if (!strcmp(key, "feature_opts_dicts")) {
if (json_next(s) != JSON_ARRAY)
return -EINVAL;
int err = parse_feature_opts_dicts(s, model);
if (err) return err;
continue;
}
if (!strcmp(key, "model")) {
if (json_next(s) != JSON_STRING)
return -EINVAL;
int err = parse_libsvm_model(s, model);
if (err) return err;
continue;
}
json_skip(s);
}
json_skip_until(s, JSON_OBJECT_END);
return 0;
}