-
Notifications
You must be signed in to change notification settings - Fork 758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose builtin models #1129
base: master
Are you sure you want to change the base?
Expose builtin models #1129
Conversation
Thanks for your work on this! Would you please add a new test in test/test_model.c ? |
Sure can, EDIT |
…now/vmaf into expose_builtin_models
Vscode automatically generated this file, It's not needed
Forgot to assert that *next is not null
change test function's name to better reflect which function it's actually testing
Could you please fix your diff for |
Sorry about that, my autoformatter must have done its thing without me noticing |
Aside from reverting to that commit and re-doing my changes is there a way to do this? |
I would just revert your changes to |
This reverts commit 2243109.
It has come to my attention that assignments are also expressions in c
From an API perspective, I think this is basically ready to go. A few more items on my side.
|
I'm not sure if testing the model loading is entirely appropriate here. While it is definitely relevant it would likely more fall under the testing of I could attempt to load a model, but it seems redundant assuming that vmaf_model_load is already well tested. However I do see the value in asserting my assumption one step further by saying "Yes, the version field matches, but I should still be able to load a model with this" |
Yes, but I don't think that's what is happening here. VmafBuiltInModel *builtin = next;
mu_assert("Version field should match on both builtin and next", next->version == builtin->version); |
I think I may have explained myself poorly. |
does this look right? /**
* This test may fail if VmafBuiltInModel's memory layout has changed
* (version MUST be the first defined property in the struct)
*/
char *test_model_descriptor_next()
{
VmafModelDescriptor *next = NULL;
VmafModelConfig config = {.name = NULL, .flags = VMAF_MODEL_FLAGS_DEFAULT};
while (vmaf_model_descriptor_next(next))
{
next = vmaf_model_descriptor_next(next);
VmafBuiltInModel *builtin = next;
mu_assert("Version field should match on both builtin and next", next->version == builtin->version);
VmafModel *model = NULL;
int err = vmaf_model_load(&model, &config, next->version);
mu_assert("Model load should not return an error",err==0);
vmaf_model_destroy(model);
}
return NULL;
} This test fails with the message |
I modified the unit test to write the current version that it's trying to load to stdout. Here's what I get
Looks like it's reading the version string just fine, but for some reason attempting to load |
@kylophone I believe that this test failing is more a problem with |
Let me find some time to look at it. Are you OK if I make some changes? |
By all means! |
I ran a debugger session when attempting to load "vmaf_b_v0.6.3" and noticed something interesting. I found that the model is getting caught up in parsing. In this function from (I've added comments in places of note) static int model_parse(json_stream *s, VmafModel *model,
enum VmafModelFlags flags)
{
int err = -EINVAL;
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); // Read the current "key" value of the json stream
if (!strcmp(key, "model_dict")) { // If current "key" is "model_dict", continue. This never evaluates to true!
err = parse_model_dict(s, model, flags);
if (err) return err;
continue;
}
json_skip(s);
}
json_skip_until(s, JSON_OBJECT_END);
return err;
} If you take a look at |
I did some more looking and it looks like built_in_models stores both if we were to split those into seperate arrays we could do the following: // When next is null, return a pointer to the first item in the new array, built_in_model_collections
VmafModelDescriptor *vmaf_model_collection_next(VmafModelDescriptor *next);
// When next is null, return a pointer to the current array, built_in_models.
VmafModelDescriptor *vmaf_model_next(VmafModelDescriptor *next);
// Not exposed in the headers
// Called into by both vmaf_model_next and vmaf_model_collection_next
// Basically the same logic as now, but doesn't make decisions on what to do when next is null
VmafModelDescriptor *vmaf_model_descriptor_next(VmafModelDescriptor *next); This might require changing the function signature of these functions slightly though, since giving a null pointer to |
Related to issue #1128
the function
vmaf_model_load
allows you to load a builtin vmaf model, given aVmafModelConfiguration
and a "version" string which corresponds to the version property on theVmafBuildInModel
struct defined inmodel.c
This struct and array are not exposed to the public api, meaning that users of libvmaf would have to know the magic strings to pass to the version param of vmaf_model_load to get a VmafModel struct
This PR adds a function
vmaf_built_in_model_next
which iterates through each item in built_in_models, allowing users of libvmaf to get a list of available built in models